From ff0b83fa89357f03c41c2d6c3f537d13170f80f1 Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Sat, 17 Sep 2011 23:25:22 +0000 Subject: [PATCH] fix bugs with deeply nested menus --- source/Ox.UI/js/Menu/Ox.MainMenu.js | 6 ++--- source/Ox.UI/js/Menu/Ox.Menu.js | 41 +++++++++++++++++------------ 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/source/Ox.UI/js/Menu/Ox.MainMenu.js b/source/Ox.UI/js/Menu/Ox.MainMenu.js index 73f31ff8..7cc02d0e 100644 --- a/source/Ox.UI/js/Menu/Ox.MainMenu.js +++ b/source/Ox.UI/js/Menu/Ox.MainMenu.js @@ -138,10 +138,8 @@ Ox.MainMenu = function(options, self) { checkItem checkItem @*/ that.checkItem = function(id) { - var ids = id.split('_'), - itemId = ids.pop(), - menuId = ids.join('_'); - that.getMenu(menuId).checkItem(itemId); + var ids = id.split('_'); + that.getMenu(ids.shift()).checkItem(ids.join('_')); return that; }; diff --git a/source/Ox.UI/js/Menu/Ox.Menu.js b/source/Ox.UI/js/Menu/Ox.Menu.js index f2665d9d..9731022f 100644 --- a/source/Ox.UI/js/Menu/Ox.Menu.js +++ b/source/Ox.UI/js/Menu/Ox.Menu.js @@ -121,8 +121,8 @@ Ox.Menu = function(options, self) { toggled; that.hideMenu(); if (!item.options('items').length) { - if (that.options('parent')) { - that.options('parent').hideMenu().triggerEvent('click'); + if (self.options.parent) { + self.options.parent.hideMenu(true).triggerEvent('click'); } if (item.options('checked') !== null) { if (item.options('group')) { @@ -551,19 +551,27 @@ Ox.Menu = function(options, self) { checkItem @*/ that.checkItem = function(id) { - var item = that.getItem(id); - 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(); + //Ox.print('checkItem id', id) + var ids = id.split('_'), + item; + if (ids.length == 1) { + item = that.getItem(id); + Ox.print('checkItem', id, item, that.submenus) + 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 { - item.options({ - checked: true - }); + that.submenus[ids.shift()].checkItem(ids.join('_')); } }; @@ -571,7 +579,7 @@ Ox.Menu = function(options, self) { getItem @*/ that.getItem = function(id) { - //Ox.print('id', id) + //Ox.print('getItem id', id) var ids = id.split('_'), item; if (ids.length == 1) { @@ -625,7 +633,7 @@ Ox.Menu = function(options, self) { hideMenu () -> Menu Object @*/ - that.hideMenu = function() { + that.hideMenu = function(hideParent) { if (that.is(':hidden')) { return; } @@ -644,10 +652,9 @@ Ox.Menu = function(options, self) { self.options.parent.options({ selected: -1 }); + hideParent && self.options.parent.hideMenu(true); } - that.hide() - .loseFocus() - .triggerEvent('hide'); + that.hide().loseFocus().triggerEvent('hide'); that.$layer.hide(); return that; };