Commit | Line | Data |
---|---|---|
50ac472f D |
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.setCurrentTopic(active_panel.get('topic') || ''); | |
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) { | |
425efe7a | 32 | _kiwi.app.connections.active_connection.gateway.topic(_kiwi.app.panels().active.get('name'), inp_val); |
50ac472f D |
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 | }); |