1 _kiwi
.view
.MenuBox
= Backbone
.View
.extend({
3 'click .ui_menu_foot .close, a.close_menu': 'dispose'
6 initialize: function(title
) {
9 this.$el
= $('<div class="ui_menu"></div>');
11 this._title
= title
|| '';
13 this._display_footer
= true;
14 this._close_on_blur
= true;
21 this.$el
.find('*').remove();
23 $('<div class="ui_menu_title"></div>').appendTo(this.$el
);
25 this.$el
.find('.ui_menu_title')
30 _
.each(this._items
, function(item
) {
31 var $item
= $('<div class="ui_menu_content hover"></div>')
34 that
.$el
.append($item
);
37 if (this._display_footer
)
38 this.$el
.append('<div class="ui_menu_foot"><a class="close" onclick="">Close <i class="icon-remove"></i></a></div>');
42 setTitle: function(new_title
) {
43 this._title
= new_title
;
48 this.$el
.find('.ui_menu_title').text(this._title
);
52 onDocumentClick: function(event
) {
53 var $target
= $(event
.target
);
55 if (!this._close_on_blur
)
58 // If this is not itself AND we don't contain this element, dispose $el
59 if ($target
[0] != this.$el
[0] && this.$el
.has($target
).length
=== 0)
65 _
.each(this._items
, function(item
) {
66 item
.dispose
&& item
.dispose();
67 item
.remove
&& item
.remove();
73 if (this._close_proxy
)
74 $(document
).off('click', this._close_proxy
);
78 addItem: function(item_name
, $item
) {
79 if ($item
.is('a')) $item
.addClass('icon-chevron-right');
80 this._items
[item_name
] = $item
;
84 removeItem: function(item_name
) {
85 delete this._items
[item_name
];
89 showFooter: function(show
) {
90 this._display_footer
= show
;
94 closeOnBlur: function(close_it
) {
95 this._close_on_blur
= close_it
;
103 this.$el
.appendTo(_kiwi
.app
.view
.$el
);
105 // We add this document click listener on the next javascript tick.
106 // If the current tick is handling an existing click event (such as the nicklist click handler),
107 // the click event bubbles up and hits the document therefore calling this callback to
108 // remove this menubox before it's even shown.
109 setTimeout(function() {
110 that
._close_proxy = function(event
) {
111 that
.onDocumentClick(event
);
113 $(document
).on('click', that
._close_proxy
);