Commit | Line | Data |
---|---|---|
50ac472f D |
1 | _kiwi.view.MemberList = Backbone.View.extend({ |
2 | tagName: "ul", | |
3 | events: { | |
4 | "click .nick": "nickClick" | |
5 | }, | |
6 | initialize: function (options) { | |
7 | this.model.bind('all', this.render, this); | |
8 | $(this.el).appendTo('#kiwi .memberlists'); | |
9 | }, | |
10 | render: function () { | |
11 | var $this = this.$el; | |
12 | $this.empty(); | |
13 | this.model.forEach(function (member) { | |
ceca5991 D |
14 | member.view.$el.data('member', member); |
15 | $this.append(member.view.$el); | |
50ac472f D |
16 | }); |
17 | return this; | |
18 | }, | |
19 | nickClick: function (event) { | |
20 | var $target = $(event.currentTarget).parent('li'), | |
21 | member = $target.data('member'), | |
22 | userbox; | |
23 | ||
50ac472f D |
24 | userbox = new _kiwi.view.UserBox(); |
25 | userbox.member = member; | |
26 | userbox.channel = this.model.channel; | |
27 | ||
28 | if (!this.model.getByNick(_kiwi.app.connections.active_connection.get('nick')).get('is_op')) { | |
29 | userbox.$el.children('.if_op').remove(); | |
30 | } | |
31 | ||
32 | var menu = new _kiwi.view.MenuBox(member.get('nick') || 'User'); | |
33 | menu.addItem('userbox', userbox.$el); | |
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 | ||
42 | // If the bottom of the userbox is going to be too low.. raise it | |
43 | if (m_bottom > memberlist_bottom){ | |
44 | t = memberlist_bottom - menu.$el.outerHeight(); | |
45 | } | |
46 | ||
47 | // Set the new positon | |
48 | menu.$el.offset({ | |
49 | left: _kiwi.app.view.$el.width() - menu.$el.outerWidth() - 20, | |
50 | top: t | |
51 | }); | |
52 | }).call(this); | |
53 | }, | |
54 | show: function () { | |
55 | $('#kiwi .memberlists').children().removeClass('active'); | |
56 | $(this.el).addClass('active'); | |
57 | } | |
58 | }); |