Merge branch 'chanlist' of https://github.com/CoryChaplin/KiwiIRC into development
[KiwiIRC.git] / client / src / views / memberlist.js
1 _kiwi.view.MemberList = Backbone.View.extend({
2 tagName: "ul",
3 events: {
4 "click .nick": "nickClick",
5 "click .channel_info": "channelInfoClick"
6 },
7
8 initialize: function (options) {
9 this.model.bind('all', this.render, this);
10 $(this.el).appendTo('#kiwi .memberlists');
11 },
12 render: function () {
13 var $this = this.$el;
14 $this.empty();
15 this.model.forEach(function (member) {
16 member.view.$el.data('member', member);
17 $this.append(member.view.$el);
18 });
19 return this;
20 },
21 nickClick: function (event) {
22 var $target = $(event.currentTarget).parent('li'),
23 member = $target.data('member'),
24 userbox,
25 are_we_an_op = !!this.model.getByNick(_kiwi.app.connections.active_connection.get('nick')).get('is_op');
26
27 userbox = new _kiwi.view.UserBox();
28 userbox.setTargets(member, this.model.channel);
29 userbox.displayOpItems(are_we_an_op);
30
31 var menu = new _kiwi.view.MenuBox(member.get('nick') || 'User');
32 menu.addItem('userbox', userbox.$el);
33 menu.showFooter(false);
34 menu.show();
35
36 // Position the userbox + menubox
37 (function() {
38 var t = event.pageY,
39 m_bottom = t + menu.$el.outerHeight(), // Where the bottom of menu will be
40 memberlist_bottom = this.$el.parent().offset().top + this.$el.parent().outerHeight(),
41 l = event.pageX,
42 m_right = l + menu.$el.outerWidth(), // Where the left of menu will be
43 memberlist_right = this.$el.parent().offset().left + this.$el.parent().outerWidth();
44
45 // If the bottom of the userbox is going to be too low.. raise it
46 if (m_bottom > memberlist_bottom){
47 t = memberlist_bottom - menu.$el.outerHeight();
48 }
49
50 // If the top of the userbox is going to be too high.. lower it
51 if (t < 0){
52 t = 0;
53 }
54
55 // If the right of the userbox is going off screen.. bring it in
56 if (m_right > memberlist_right){
57 l = memberlist_right - menu.$el.outerWidth();
58 }
59
60 // Set the new positon
61 menu.$el.offset({
62 left: l,
63 top: t
64 });
65 }).call(this);
66 },
67
68
69 channelInfoClick: function(event) {
70 new _kiwi.model.ChannelInfo({channel: this.model.channel});
71 },
72
73
74 show: function () {
75 $('#kiwi .memberlists').children().removeClass('active');
76 $(this.el).addClass('active');
77 }
78 });