Commit | Line | Data |
---|---|---|
50ac472f D |
1 | _kiwi.view.MemberList = Backbone.View.extend({ |
2 | tagName: "ul", | |
3 | events: { | |
9936359c D |
4 | "click .nick": "nickClick", |
5 | "click .channel_info": "channelInfoClick" | |
50ac472f | 6 | }, |
9936359c | 7 | |
50ac472f D |
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) { | |
ceca5991 D |
16 | member.view.$el.data('member', member); |
17 | $this.append(member.view.$el); | |
50ac472f D |
18 | }); |
19 | return this; | |
20 | }, | |
21 | nickClick: function (event) { | |
22 | var $target = $(event.currentTarget).parent('li'), | |
23 | member = $target.data('member'), | |
d62fa271 D |
24 | userbox, |
25 | are_we_an_op = !!this.model.getByNick(_kiwi.app.connections.active_connection.get('nick')).get('is_op'); | |
50ac472f | 26 | |
50ac472f | 27 | userbox = new _kiwi.view.UserBox(); |
d62fa271 D |
28 | userbox.setTargets(member, this.model.channel); |
29 | userbox.displayOpItems(are_we_an_op); | |
50ac472f D |
30 | |
31 | var menu = new _kiwi.view.MenuBox(member.get('nick') || 'User'); | |
32 | menu.addItem('userbox', userbox.$el); | |
96910370 | 33 | menu.showFooter(false); |
50ac472f D |
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 | |
9421e70a D |
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(); | |
50ac472f D |
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 | ||
96910370 D |
50 | // If the top of the userbox is going to be too high.. lower it |
51 | if (t < 0){ | |
52 | t = 0; | |
53 | } | |
54 | ||
9421e70a D |
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 | ||
50ac472f D |
60 | // Set the new positon |
61 | menu.$el.offset({ | |
9421e70a | 62 | left: l, |
50ac472f D |
63 | top: t |
64 | }); | |
65 | }).call(this); | |
66 | }, | |
9936359c D |
67 | |
68 | ||
69 | channelInfoClick: function(event) { | |
70 | new _kiwi.model.ChannelInfo({channel: this.model.channel}); | |
71 | }, | |
72 | ||
73 | ||
50ac472f D |
74 | show: function () { |
75 | $('#kiwi .memberlists').children().removeClass('active'); | |
76 | $(this.el).addClass('active'); | |
77 | } | |
78 | }); |