631ea5b4c891b8cf32202e1db6313f7631e78090
[ccsdk/features.git] /
1 (function( app ) {
2
3         var ui = app.ns("ui");
4
5         ui.MenuPanel = ui.AbstractPanel.extend({
6                 defaults: {
7                         items: [],              // (required) an array of menu items
8                         modal: false
9                 },
10                 _baseCls: "uiMenuPanel",
11                 init: function() {
12                         this._super();
13                         this.el = $(this._main_template());
14                 },
15                 open: function(jEv) {
16                         this._super(jEv);
17                         var cx = this; setTimeout(function() { $(document).bind("click", cx._close_handler); }, 50);
18                 },
19                 _getItems: function() {
20                         return this.config.items;
21                 },
22                 _close_handler: function(jEv) {
23                         this._super(jEv);
24                         $(document).unbind("click", this._close_handler);
25                 },
26                 _main_template: function() {
27                         return { tag: "DIV", cls: this._baseCls, children: this._getItems().map(this._menuItem_template, this) };
28                 },
29                 _menuItem_template: function(item) {
30                         var dx = item.disabled ? { onclick: function() {} } : {};
31                         return { tag: "LI", cls: "uiMenuPanel-item" + (item.disabled ? " disabled" : "") + (item.selected ? " selected" : ""), children: [ $.extend({ tag: "DIV", cls: "uiMenuPanel-label" }, item, dx ) ] };
32                 },
33                 _getPosition: function(jEv) {
34                         var right = !! $(jEv.target).parents(".pull-right").length;
35                         var parent = $(jEv.target).closest("BUTTON");
36                         return parent.vOffset()
37                                 .addY(parent.vSize().y)
38                                 .addX( right ? parent.vSize().x - this.el.vOuterSize().x : 0 )
39                                 .asOffset();
40                 }
41         });
42
43 })( this.app );