5 ui.MenuPanel = ui.AbstractPanel.extend({
7 items: [], // (required) an array of menu items
10 _baseCls: "uiMenuPanel",
13 this.el = $(this._main_template());
17 var cx = this; setTimeout(function() { $(document).bind("click", cx._close_handler); }, 50);
19 _getItems: function() {
20 return this.config.items;
22 _close_handler: function(jEv) {
24 $(document).unbind("click", this._close_handler);
26 _main_template: function() {
27 return { tag: "DIV", cls: this._baseCls, children: this._getItems().map(this._menuItem_template, this) };
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 ) ] };
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 )