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