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();
24 $('<div class="ui_menu_title"></div>')
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 onDocumentClick: function(event
) {
43 var $target
= $(event
.target
);
45 if (!this._close_on_blur
)
48 // If this is not itself AND we don't contain this element, dispose $el
49 if ($target
[0] != this.$el
[0] && this.$el
.has($target
).length
=== 0)
55 _
.each(this._items
, function(item
) {
56 item
.dispose
&& item
.dispose();
57 item
.remove
&& item
.remove();
63 if (this._close_proxy
)
64 $(document
).off('click', this._close_proxy
);
68 addItem: function(item_name
, $item
) {
70 if ($item
.is('a')) $item
.addClass('icon-chevron-right');
71 this._items
[item_name
] = $item
;
75 removeItem: function(item_name
) {
76 delete this._items
[item_name
];
80 showFooter: function(show
) {
81 this._display_footer
= show
;
85 closeOnBlur: function(close_it
) {
86 this._close_on_blur
= close_it
;
94 this.$el
.appendTo(_kiwi
.app
.view
.$el
);
96 // We add this document click listener on the next javascript tick.
97 // If the current tick is handling an existing click event (such as the nicklist click handler),
98 // the click event bubbles up and hits the document therefore calling this callback to
99 // remove this menubox before it's even shown.
100 setTimeout(function() {
101 that
._close_proxy = function(event
) {
102 that
.onDocumentClick(event
);
104 $(document
).on('click', that
._close_proxy
);