making it librejs compliant
[KiwiIRC.git] / client / src / views / topicbar.js
1 _kiwi.view.TopicBar = Backbone.View.extend({
2 events: {
3 'keydown div': 'process'
4 },
5
6 initialize: function () {
7 _kiwi.app.panels.bind('active', function (active_panel) {
8 // If it's a channel topic, update and make editable
9 if (active_panel.isChannel()) {
10 this.setCurrentTopicFromChannel(active_panel);
11 this.$el.find('div').attr('contentEditable', true);
12
13 } else {
14 // Not a channel topic.. clear and make uneditable
15 this.$el.find('div').attr('contentEditable', false)
16 .text('');
17 }
18 }, this);
19 },
20
21 process: function (ev) {
22 var inp = $(ev.currentTarget),
23 inp_val = inp.text();
24
25 // Only allow topic editing if this is a channel panel
26 if (!_kiwi.app.panels().active.isChannel()) {
27 return false;
28 }
29
30 // If hit return key, update the current topic
31 if (ev.keyCode === 13) {
32 _kiwi.app.connections.active_connection.gateway.topic(_kiwi.app.panels().active.get('name'), inp_val);
33 return false;
34 }
35 },
36
37 setCurrentTopic: function (new_topic) {
38 new_topic = new_topic || '';
39
40 // We only want a plain text version
41 $('div', this.$el).html(formatIRCMsg(_.escape(new_topic)));
42 },
43
44 setCurrentTopicFromChannel: function(channel) {
45 var set_by = channel.get('topic_set_by'),
46 set_by_text = '';
47
48 this.setCurrentTopic(channel.get("topic"));
49
50 if (set_by) {
51 set_by_text += translateText('client_models_network_topic', [set_by.nick, _kiwi.utils.formatDate(set_by.when)]);
52 this.$el.attr('title', set_by_text);
53 } else {
54 this.$el.attr('title', '');
55 }
56 }
57 });