aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgcko <jscott@coverity.com>2011-05-24 10:28:24 -0700
committergcko <jscott@coverity.com>2011-05-24 10:28:24 -0700
commit9e57e43d9c68596e21f27be81d2535ad5e749dca (patch)
tree7862e18fa62552fedd642e910194ce6e98851c74
parente2c4a3cc654555df75e8241ed40be562b73ab6f1 (diff)
downloadjquery-ui-9e57e43d9c68596e21f27be81d2535ad5e749dca.tar.gz
jquery-ui-9e57e43d9c68596e21f27be81d2535ad5e749dca.zip
Adding in recursion for moveSelection and moveFocus
-rw-r--r--ui/jquery.ui.selectmenu.js29
1 files 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();