summaryrefslogtreecommitdiffstats
path: root/ui/jquery.ui.selectmenu.js
diff options
context:
space:
mode:
authorFelix Nagel <info@felixnagel.com>2011-05-24 13:17:55 -0700
committerFelix Nagel <info@felixnagel.com>2011-05-24 13:17:55 -0700
commit2edde9ca30692a7eeb8c9341da1d1d33e367386b (patch)
tree7862e18fa62552fedd642e910194ce6e98851c74 /ui/jquery.ui.selectmenu.js
parent07d40b887d96a01f09fe0151d0a782f0fe3e5bb1 (diff)
parent9e57e43d9c68596e21f27be81d2535ad5e749dca (diff)
downloadjquery-ui-2edde9ca30692a7eeb8c9341da1d1d33e367386b.tar.gz
jquery-ui-2edde9ca30692a7eeb8c9341da1d1d33e367386b.zip
Merge pull request #119 from gcko/selectmenu
Adding recursion for moveSelection and moveFocus
Diffstat (limited to 'ui/jquery.ui.selectmenu.js')
-rw-r--r--ui/jquery.ui.selectmenu.js30
1 files changed, 25 insertions, 5 deletions
diff --git a/ui/jquery.ui.selectmenu.js b/ui/jquery.ui.selectmenu.js
index deb7b419b..49f3d0e77 100644
--- a/ui/jquery.ui.selectmenu.js
+++ b/ui/jquery.ui.selectmenu.js
@@ -535,6 +535,7 @@ $.widget("ui.selectmenu", {
},
select: function(event) {
+ if (this._disabled(event.currentTarget)) { return false; }
this._trigger("select", event, this._uiHash());
},
@@ -569,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;
@@ -591,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);
@@ -598,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();