1 _kiwi
.view
.MenuBox
= Backbone
.View
.extend({
3 'click .ui_menu_foot .close': '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;
16 this._close_proxy = function(event
) {
17 that
.onDocumentClick(event
);
19 $(document
).on('click', this._close_proxy
);
26 this.$el
.find('*').remove();
29 $('<div class="ui_menu_title"></div>')
35 _
.each(this._items
, function(item
) {
36 var $item
= $('<div class="ui_menu_content hover"></div>')
39 that
.$el
.append($item
);
42 if (this._display_footer
)
43 this.$el
.append('<div class="ui_menu_foot"><a class="close" onclick="">Close <i class="icon-remove"></i></a></div>');
47 onDocumentClick: function(event
) {
48 var $target
= $(event
.target
);
50 if (!this._close_on_blur
)
53 // If this is not itself AND we don't contain this element, dispose $el
54 if ($target
[0] != this.$el
[0] && this.$el
.has($target
).length
=== 0)
60 _
.each(this._items
, function(item
) {
61 item
.dispose
&& item
.dispose();
62 item
.remove
&& item
.remove();
68 $(document
).off('click', this._close_proxy
);
72 addItem: function(item_name
, $item
) {
74 if ($item
.is('a')) $item
.addClass('icon-chevron-right');
75 this._items
[item_name
] = $item
;
79 removeItem: function(item_name
) {
80 delete this._items
[item_name
];
84 showFooter: function(show
) {
85 this._display_footer
= show
;
89 closeOnBlur: function(close_it
) {
90 this._close_on_blur
= close_it
;
96 this.$el
.appendTo(_kiwi
.app
.view
.$el
);