diff options
author | Felix Nagel <info@felixnagel.com> | 2013-10-29 19:52:54 +0100 |
---|---|---|
committer | Felix Nagel <info@felixnagel.com> | 2013-10-29 19:52:54 +0100 |
commit | f3e4b24485a34c89ee4032605d853c1b3e0a4e7e (patch) | |
tree | 6ca3a9c26592956faa795e81d016306cd273d73d /ui/jquery.ui.selectmenu.js | |
parent | 480e89b1aaa2ab9eeb15e7b588d59bc27cbaacaa (diff) | |
download | jquery-ui-f3e4b24485a34c89ee4032605d853c1b3e0a4e7e.tar.gz jquery-ui-f3e4b24485a34c89ee4032605d853c1b3e0a4e7e.zip |
Selectmenu: improve disabled item handling
Diffstat (limited to 'ui/jquery.ui.selectmenu.js')
-rw-r--r-- | ui/jquery.ui.selectmenu.js | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/ui/jquery.ui.selectmenu.js b/ui/jquery.ui.selectmenu.js index 800503c08..69f863108 100644 --- a/ui/jquery.ui.selectmenu.js +++ b/ui/jquery.ui.selectmenu.js @@ -287,17 +287,24 @@ $.widget( "ui.selectmenu", { }, _move: function( direction, event ) { + var filter = ".ui-menu-item", + item, next; + + if ( this.isOpen ) { + item = this.menuItems.eq( this.focusIndex ); + } else { + item = this.menuItems.eq( this.element[ 0 ].selectedIndex ); + filter += ":not(.ui-state-disabled)"; + } + if ( direction === "first" || direction === "last" ) { - // Set focus manually for first or last item - this.menu.menu( "focus", event, this.menuItems[ direction ]() ); + next = item[ direction === "first" ? "prevAll" : "nextAll" ]( filter ).eq( -1 ); } else { - if ( direction === "previous" && this.menu.menu( "isFirstItem" ) || - direction === "next" && this.menu.menu( "isLastItem" ) ) { - return; - } + next = item[ direction + "All" ]( filter ).eq( 0 ); + } - // Move to and focus next or prev item - this.menu.menu( direction, event ); + if ( next.length ) { + this.menu.menu( "focus", event, next ); } }, @@ -340,14 +347,14 @@ $.widget( "ui.selectmenu", { break; case $.ui.keyCode.ENTER: if ( this.isOpen ) { - this.menuInstance.select( event ); + this._selectMenu( event ); } break; case $.ui.keyCode.UP: if ( event.altKey ) { this._toggle( event ); } else { - this._move( "previous", event ); + this._move( "prev", event ); } break; case $.ui.keyCode.DOWN: @@ -359,13 +366,13 @@ $.widget( "ui.selectmenu", { break; case $.ui.keyCode.SPACE: if ( this.isOpen ) { - this.menuInstance.select( event ); + this._selectMenu( event ); } else { this._toggle( event ); } break; case $.ui.keyCode.LEFT: - this._move( "previous", event ); + this._move( "prev", event ); break; case $.ui.keyCode.RIGHT: this._move( "next", event ); @@ -389,6 +396,12 @@ $.widget( "ui.selectmenu", { } }, + _selectMenu: function( event ) { + if ( !this.menuItems.eq( this.focusIndex ).hasClass( "ui-state-disabled" ) ) { + this.menuInstance.select( event ); + } + }, + _select: function( item, event ) { var oldIndex = this.element[ 0 ].selectedIndex; |