From 314788dd244a0b7555da2132f6f971d9c37fc502 Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Mon, 7 Nov 2011 18:17:16 +0000 Subject: [PATCH] don't throw errors in menu when accessing non-existing items --- source/Ox.UI/js/Core/Ox.Focus.js | 6 ++++-- source/Ox.UI/js/Menu/Ox.MainMenu.js | 15 ++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/source/Ox.UI/js/Core/Ox.Focus.js b/source/Ox.UI/js/Core/Ox.Focus.js index 2c021a4c..65910ec8 100644 --- a/source/Ox.UI/js/Core/Ox.Focus.js +++ b/source/Ox.UI/js/Core/Ox.Focus.js @@ -26,7 +26,8 @@ Ox.Focus = (function() { : stack.splice(stack.length - 2, 0, stack.pop()); //$elements[id].removeClass('OxFocus'); $('.OxFocus').removeClass('OxFocus'); // fixme: the above is better, and should work - stack.length && Ox.UI.elements[stack[stack.length - 1]].addClass('OxFocus'); + stack.length && Ox.UI.elements[stack[stack.length - 1]] + .addClass('OxFocus').triggerEvent('focus'); Ox.Log('Core', 'blur', id, stack); } }, @@ -41,7 +42,8 @@ Ox.Focus = (function() { stack.push(id); $('.OxFocus').removeClass('OxFocus'); // fixme: see above Ox.Log('Core', 'focus', id, stack); - Ox.UI.elements[id].addClass('OxFocus'); + Ox.UI.elements[id] + .addClass('OxFocus').triggerEvent('focus'); } }, /*@ diff --git a/source/Ox.UI/js/Menu/Ox.MainMenu.js b/source/Ox.UI/js/Menu/Ox.MainMenu.js index 4abed19f..c8ab22ce 100644 --- a/source/Ox.UI/js/Menu/Ox.MainMenu.js +++ b/source/Ox.UI/js/Menu/Ox.MainMenu.js @@ -140,7 +140,8 @@ Ox.MainMenu = function(options, self) { checkItem checkItem @*/ that.checkItem = function(id) { - that.getItem(id).options({checked: true}); + var item = that.getItem(id); + item && item.options({checked: true}); return that; }; @@ -148,7 +149,8 @@ Ox.MainMenu = function(options, self) { disableItem disableItem @*/ that.disableItem = function(id) { - that.getItem(id).options({disabled: true}); + var item = that.getItem(id); + item && item.options({disabled: true}); return that; }; @@ -156,7 +158,8 @@ Ox.MainMenu = function(options, self) { enableItem enableItem @*/ that.enableItem = function(id) { - that.getItem(id).options({disabled: false}); + var item = that.getItem(id); + item && item.options({disabled: false}); return that; }; @@ -229,7 +232,8 @@ Ox.MainMenu = function(options, self) { }; that.setItemTitle = function(id, title) { - that.getItem(id).options({title: title}); + var item = that.getItem(id); + item && item.options({title: title}); return that; }; @@ -237,7 +241,8 @@ Ox.MainMenu = function(options, self) { uncheckItem uncheckItem @*/ that.uncheckItem = function(id) { - that.getItem(id).options({checked: false}); + var item = that.getItem(id); + item && item.options({checked: false}); return that; };