Commit | Line | Data |
---|---|---|
50ac472f | 1 | _kiwi.view.Channel = _kiwi.view.Panel.extend({ |
9b807765 D |
2 | events: function(){ |
3 | var parent_events = _kiwi.view.Panel.prototype.events; | |
4 | ||
5 | if(_.isFunction(parent_events)){ | |
6 | parent_events = parent_events(); | |
7 | } | |
8 | return _.extend({}, parent_events, { | |
9 | 'click .msg .nick' : 'nickClick' | |
10 | }); | |
dfb5209c JA |
11 | }, |
12 | ||
50ac472f D |
13 | initialize: function (options) { |
14 | this.initializePanel(options); | |
15 | this.model.bind('change:topic', this.topic, this); | |
16 | ||
7d2a2771 D |
17 | if (this.model.get('members')) { |
18 | this.model.get('members').bind('add', function (member) { | |
19 | if (member.get('nick') === this.model.collection.network.get('nick')) { | |
20 | this.$el.find('.initial_loader').slideUp(function () { | |
21 | $(this).remove(); | |
22 | }); | |
23 | } | |
24 | }, this); | |
25 | } | |
660e1427 | 26 | |
50ac472f D |
27 | // Only show the loader if this is a channel (ie. not a query) |
28 | if (this.model.isChannel()) { | |
247dd7ac | 29 | this.$el.append('<div class="initial_loader" style="margin:1em;text-align:center;"> ' + _kiwi.global.i18n.translate('client_views_channel_joining').fetch() + ' <span class="loader"></span></div>'); |
50ac472f D |
30 | } |
31 | }, | |
32 | ||
33 | // Override the existing newMsg() method to remove the joining channel loader | |
34 | newMsg: function () { | |
50ac472f D |
35 | return this.constructor.__super__.newMsg.apply(this, arguments); |
36 | }, | |
37 | ||
38 | topic: function (topic) { | |
39 | if (typeof topic !== 'string' || !topic) { | |
40 | topic = this.model.get("topic"); | |
41 | } | |
42 | ||
247dd7ac | 43 | this.model.addMsg('', '== ' + _kiwi.global.i18n.translate('client_views_channel_topic').fetch(this.model.get('name'), topic), 'topic'); |
50ac472f D |
44 | |
45 | // If this is the active channel then update the topic bar | |
46 | if (_kiwi.app.panels().active === this) { | |
47 | _kiwi.app.topicbar.setCurrentTopic(this.model.get("topic")); | |
48 | } | |
dfb5209c JA |
49 | }, |
50 | ||
51 | // Click on a nickname | |
52 | nickClick: function (event) { | |
53 | var nick = $(event.currentTarget).text(), | |
54 | members = this.model.get('members'), | |
55 | member, query, userbox, menubox; | |
56 | ||
57 | if (members) { | |
58 | member = members.getByNick(nick); | |
59 | if (member) { | |
dfb5209c JA |
60 | userbox = new _kiwi.view.UserBox(); |
61 | userbox.member = member; | |
62 | userbox.channel = this.model; | |
63 | ||
0826460d D |
64 | // Hide the op related items if we're not an op |
65 | if (!members.getByNick(_kiwi.app.connections.active_connection.get('nick')).get('is_op')) { | |
dfb5209c JA |
66 | userbox.$el.children('.if_op').remove(); |
67 | } | |
0826460d | 68 | |
dfb5209c JA |
69 | menubox = new _kiwi.view.MenuBox(member.get('nick') || 'User'); |
70 | menubox.addItem('userbox', userbox.$el); | |
dfb5209c | 71 | menubox.show(); |
0826460d | 72 | |
dfb5209c JA |
73 | // Position the userbox + menubox |
74 | (function() { | |
75 | var t = event.pageY, | |
76 | m_bottom = t + menubox.$el.outerHeight(), // Where the bottom of menu will be | |
77 | memberlist_bottom = this.$el.parent().offset().top + this.$el.parent().outerHeight(); | |
78 | ||
79 | // If the bottom of the userbox is going to be too low.. raise it | |
80 | if (m_bottom > memberlist_bottom){ | |
81 | t = memberlist_bottom - menubox.$el.outerHeight(); | |
82 | } | |
83 | ||
84 | // Set the new positon | |
85 | menubox.$el.offset({ | |
86 | left: event.clientX, | |
87 | top: t | |
88 | }); | |
89 | }).call(this); | |
90 | } | |
91 | } | |
50ac472f | 92 | } |
dfb5209c | 93 | }); |