Skip to content

Commit 9e57e43

Browse files
author
gcko
committed
Adding in recursion for moveSelection and moveFocus
1 parent e2c4a3c commit 9e57e43

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

ui/jquery.ui.selectmenu.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -570,14 +570,30 @@ $.widget("ui.selectmenu", {
570570
return this.list.find('.' + this.widgetBaseClass + '-item-focus');
571571
},
572572

573-
_moveSelection: function(amt) {
574-
var currIndex = parseInt(this._selectedOptionLi().data('index'), 10);
573+
_moveSelection: function(amt, recIndex) {
574+
var currIndex = parseInt(this._selectedOptionLi().data('index') || 0, 10);
575575
var newIndex = currIndex + amt;
576576
// do not loop when using up key
577-
if (newIndex >= 0 ) return this._optionLis.eq(newIndex).trigger('mouseup');
577+
578+
if (newIndex < 0) {
579+
newIndex = 0;
580+
}
581+
if (newIndex > this._optionLis.size() - 1) {
582+
newIndex = this._optionLis.size() - 1;
583+
}
584+
//Occurs when a full loop has been made
585+
if (newIndex === recIndex) { return false; }
586+
587+
if (this._optionLis.eq(newIndex).hasClass( this.namespace + '-state-disabled' )) {
588+
// if option at newIndex is disabled, call _moveFocus, incrementing amt by one
589+
(amt > 0) ? ++amt : --amt;
590+
this._moveSelection(amt, newIndex);
591+
} else {
592+
return this._optionLis.eq(newIndex).trigger('mouseup');
593+
}
578594
},
579595

580-
_moveFocus: function(amt) {
596+
_moveFocus: function(amt, recIndex) {
581597
if (!isNaN(amt)) {
582598
var currIndex = parseInt(this._focusedOptionLi().data('index') || 0, 10);
583599
var newIndex = currIndex + amt;
@@ -592,14 +608,17 @@ $.widget("ui.selectmenu", {
592608
if (newIndex > this._optionLis.size() - 1) {
593609
newIndex = this._optionLis.size() - 1;
594610
}
611+
612+
//Occurs when a full loop has been made
613+
if (newIndex === recIndex) { return false; }
595614

596615
var activeID = this.widgetBaseClass + '-item-' + Math.round(Math.random() * 1000);
597616

598617
this._focusedOptionLi().find('a:eq(0)').attr('id', '');
599618

600619
if (this._optionLis.eq(newIndex).hasClass( this.namespace + '-state-disabled' )) {
601620
// if option at newIndex is disabled, call _moveFocus, incrementing amt by one
602-
(amt > 0) ? amt++ : amt--;
621+
(amt > 0) ? ++amt : --amt;
603622
this._moveFocus(amt, newIndex);
604623
} else {
605624
this._optionLis.eq(newIndex).find('a:eq(0)').attr('id',activeID).focus();

0 commit comments

Comments
 (0)