fix bugs with deeply nested menus

This commit is contained in:
rlx 2011-09-17 23:25:22 +00:00
parent e11a8e3a78
commit ff0b83fa89
2 changed files with 26 additions and 21 deletions

View file

@ -138,10 +138,8 @@ Ox.MainMenu = function(options, self) {
checkItem <f> checkItem checkItem <f> checkItem
@*/ @*/
that.checkItem = function(id) { that.checkItem = function(id) {
var ids = id.split('_'), var ids = id.split('_');
itemId = ids.pop(), that.getMenu(ids.shift()).checkItem(ids.join('_'));
menuId = ids.join('_');
that.getMenu(menuId).checkItem(itemId);
return that; return that;
}; };

View file

@ -121,8 +121,8 @@ Ox.Menu = function(options, self) {
toggled; toggled;
that.hideMenu(); that.hideMenu();
if (!item.options('items').length) { if (!item.options('items').length) {
if (that.options('parent')) { if (self.options.parent) {
that.options('parent').hideMenu().triggerEvent('click'); self.options.parent.hideMenu(true).triggerEvent('click');
} }
if (item.options('checked') !== null) { if (item.options('checked') !== null) {
if (item.options('group')) { if (item.options('group')) {
@ -551,19 +551,27 @@ Ox.Menu = function(options, self) {
checkItem <f> checkItem <f>
@*/ @*/
that.checkItem = function(id) { that.checkItem = function(id) {
var item = that.getItem(id); //Ox.print('checkItem id', id)
if (item.options('group')) { var ids = id.split('_'),
var position = getItemPositionById(id), item;
toggled = self.optionGroups[item.options('group')].toggle(position); if (ids.length == 1) {
if (toggled.length) { item = that.getItem(id);
toggled.forEach(function(pos) { Ox.print('checkItem', id, item, that.submenus)
that.items[pos].toggleChecked(); if (item.options('group')) {
var position = getItemPositionById(id),
toggled = self.optionGroups[item.options('group')].toggle(position);
if (toggled.length) {
toggled.forEach(function(pos) {
that.items[pos].toggleChecked();
});
}
} else {
item.options({
checked: true
}); });
} }
} else { } else {
item.options({ that.submenus[ids.shift()].checkItem(ids.join('_'));
checked: true
});
} }
}; };
@ -571,7 +579,7 @@ Ox.Menu = function(options, self) {
getItem <f> getItem <f>
@*/ @*/
that.getItem = function(id) { that.getItem = function(id) {
//Ox.print('id', id) //Ox.print('getItem id', id)
var ids = id.split('_'), var ids = id.split('_'),
item; item;
if (ids.length == 1) { if (ids.length == 1) {
@ -625,7 +633,7 @@ Ox.Menu = function(options, self) {
hideMenu <f> hideMenu <f>
() -> <f> Menu Object () -> <f> Menu Object
@*/ @*/
that.hideMenu = function() { that.hideMenu = function(hideParent) {
if (that.is(':hidden')) { if (that.is(':hidden')) {
return; return;
} }
@ -644,10 +652,9 @@ Ox.Menu = function(options, self) {
self.options.parent.options({ self.options.parent.options({
selected: -1 selected: -1
}); });
hideParent && self.options.parent.hideMenu(true);
} }
that.hide() that.hide().loseFocus().triggerEvent('hide');
.loseFocus()
.triggerEvent('hide');
that.$layer.hide(); that.$layer.hide();
return that; return that;
}; };