MenuBox disposing improvements
[KiwiIRC.git] / client / assets / src / views / channel.js
CommitLineData
50ac472f 1_kiwi.view.Channel = _kiwi.view.Panel.extend({
dfb5209c
JA
2 events: {
3 'click .msg .nick': 'nickClick'
4 },
5
50ac472f
D
6 initialize: function (options) {
7 this.initializePanel(options);
8 this.model.bind('change:topic', this.topic, this);
9
10 // Only show the loader if this is a channel (ie. not a query)
11 if (this.model.isChannel()) {
12 this.$el.append('<div class="initial_loader" style="margin:1em;text-align:center;">Joining channel.. <span class="loader"></span></div>');
13 }
14 },
15
16 // Override the existing newMsg() method to remove the joining channel loader
17 newMsg: function () {
18 this.$el.find('.initial_loader').slideUp(function () {
19 $(this).remove();
20 });
21
22 return this.constructor.__super__.newMsg.apply(this, arguments);
23 },
24
25 topic: function (topic) {
26 if (typeof topic !== 'string' || !topic) {
27 topic = this.model.get("topic");
28 }
29
30 this.model.addMsg('', '== Topic for ' + this.model.get('name') + ' is: ' + topic, 'topic');
31
32 // If this is the active channel then update the topic bar
33 if (_kiwi.app.panels().active === this) {
34 _kiwi.app.topicbar.setCurrentTopic(this.model.get("topic"));
35 }
dfb5209c
JA
36 },
37
38 // Click on a nickname
39 nickClick: function (event) {
40 var nick = $(event.currentTarget).text(),
41 members = this.model.get('members'),
42 member, query, userbox, menubox;
43
44 if (members) {
45 member = members.getByNick(nick);
46 if (member) {
dfb5209c
JA
47 userbox = new _kiwi.view.UserBox();
48 userbox.member = member;
49 userbox.channel = this.model;
50
51 if (!member.get('is_op')) {
52 userbox.$el.children('.if_op').remove();
53 }
54 menubox = new _kiwi.view.MenuBox(member.get('nick') || 'User');
55 menubox.addItem('userbox', userbox.$el);
dfb5209c 56 menubox.show();
c3c793e0 57
dfb5209c
JA
58 // Position the userbox + menubox
59 (function() {
60 var t = event.pageY,
61 m_bottom = t + menubox.$el.outerHeight(), // Where the bottom of menu will be
62 memberlist_bottom = this.$el.parent().offset().top + this.$el.parent().outerHeight();
63
64 // If the bottom of the userbox is going to be too low.. raise it
65 if (m_bottom > memberlist_bottom){
66 t = memberlist_bottom - menubox.$el.outerHeight();
67 }
68
69 // Set the new positon
70 menubox.$el.offset({
71 left: event.clientX,
72 top: t
73 });
74 }).call(this);
75 }
76 }
50ac472f 77 }
dfb5209c 78});