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