From 9e57e43d9c68596e21f27be81d2535ad5e749dca Mon Sep 17 00:00:00 2001 From: gcko Date: Tue, 24 May 2011 10:28:24 -0700 Subject: [PATCH] Adding in recursion for moveSelection and moveFocus --- ui/jquery.ui.selectmenu.js | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/ui/jquery.ui.selectmenu.js b/ui/jquery.ui.selectmenu.js index 59de135bd..49f3d0e77 100644 --- a/ui/jquery.ui.selectmenu.js +++ b/ui/jquery.ui.selectmenu.js @@ -570,14 +570,30 @@ $.widget("ui.selectmenu", { return this.list.find('.' + this.widgetBaseClass + '-item-focus'); }, - _moveSelection: function(amt) { - var currIndex = parseInt(this._selectedOptionLi().data('index'), 10); + _moveSelection: function(amt, recIndex) { + var currIndex = parseInt(this._selectedOptionLi().data('index') || 0, 10); var newIndex = currIndex + amt; // do not loop when using up key - if (newIndex >= 0 ) return this._optionLis.eq(newIndex).trigger('mouseup'); + + if (newIndex < 0) { + newIndex = 0; + } + if (newIndex > this._optionLis.size() - 1) { + newIndex = this._optionLis.size() - 1; + } + //Occurs when a full loop has been made + if (newIndex === recIndex) { return false; } + + if (this._optionLis.eq(newIndex).hasClass( this.namespace + '-state-disabled' )) { + // if option at newIndex is disabled, call _moveFocus, incrementing amt by one + (amt > 0) ? ++amt : --amt; + this._moveSelection(amt, newIndex); + } else { + return this._optionLis.eq(newIndex).trigger('mouseup'); + } }, - _moveFocus: function(amt) { + _moveFocus: function(amt, recIndex) { if (!isNaN(amt)) { var currIndex = parseInt(this._focusedOptionLi().data('index') || 0, 10); var newIndex = currIndex + amt; @@ -592,6 +608,9 @@ $.widget("ui.selectmenu", { if (newIndex > this._optionLis.size() - 1) { newIndex = this._optionLis.size() - 1; } + + //Occurs when a full loop has been made + if (newIndex === recIndex) { return false; } var activeID = this.widgetBaseClass + '-item-' + Math.round(Math.random() * 1000); @@ -599,7 +618,7 @@ $.widget("ui.selectmenu", { if (this._optionLis.eq(newIndex).hasClass( this.namespace + '-state-disabled' )) { // if option at newIndex is disabled, call _moveFocus, incrementing amt by one - (amt > 0) ? amt++ : amt--; + (amt > 0) ? ++amt : --amt; this._moveFocus(amt, newIndex); } else { this._optionLis.eq(newIndex).find('a:eq(0)').attr('id',activeID).focus(); -- 2.39.5