aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkborchers <kris.borchers@gmail.com>2012-02-06 14:12:56 -0600
committerkborchers <kris.borchers@gmail.com>2012-02-06 14:12:56 -0600
commit87dc9ce24a6355ea551b9dfc266b84712fd5d00c (patch)
treef06b622879ba48eb877485598e2d3def81b930d2
parent30713ade36e2265dc6f10da23a104219bcf456a0 (diff)
downloadjquery-ui-87dc9ce24a6355ea551b9dfc266b84712fd5d00c.tar.gz
jquery-ui-87dc9ce24a6355ea551b9dfc266b84712fd5d00c.zip
Menu: Prevent navigating to disabled menu items with the keyboard.
-rw-r--r--tests/visual/menu/menu.html5
-rw-r--r--ui/jquery.ui.menu.js41
2 files changed, 23 insertions, 23 deletions
diff --git a/tests/visual/menu/menu.html b/tests/visual/menu/menu.html
index 7fffdf2a7..16ba6ae45 100644
--- a/tests/visual/menu/menu.html
+++ b/tests/visual/menu/menu.html
@@ -74,9 +74,9 @@
</ul>
<ul id="menu2">
- <li><a href="#">Aberdeen</a></li>
+ <li class="ui-state-disabled"><a href="#">Aberdeen</a></li>
<li><a href="#">Ada</a></li>
- <li class="ui-state-disabled"><a href="#">Adamsville</a></li>
+ <li><a href="#">Adamsville</a></li>
<li><a href="#">Addyston</a></li>
<li>
<a href="#">Delphi</a>
@@ -109,6 +109,7 @@
<li><a href="#">Perch</a></li>
</ul>
</li>
+ <li class="ui-state-disabled"><a href="#">Amesville</a></li>
</ul>
<ul id="menu3">
diff --git a/ui/jquery.ui.menu.js b/ui/jquery.ui.menu.js
index ce6e977e6..4575e4a8d 100644
--- a/ui/jquery.ui.menu.js
+++ b/ui/jquery.ui.menu.js
@@ -77,7 +77,7 @@ $.widget( "ui.menu", {
"mouseleave": "collapseAll",
"mouseleave .ui-menu": "collapseAll",
"focus": function( event ) {
- var firstItem = this.element.children( ".ui-menu-item" ).eq( 0 );
+ var firstItem = this.element.children( ".ui-menu-item" ).not( ".ui-state-disabled" ).eq( 0 );
if ( this._hasScroll() && !this.active ) {
var menu = this.element;
menu.children().each( function() {
@@ -417,7 +417,7 @@ $.widget( "ui.menu", {
},
expand: function( event ) {
- var newItem = this.active && this.active.children( ".ui-menu " ).children( ".ui-menu-item" ).first();
+ var newItem = this.active && this.active.children( ".ui-menu " ).children( ".ui-menu-item" ).not( ".ui-state-disabled" ).first();
if ( newItem && newItem.length ) {
this._open( newItem.parent() );
@@ -447,28 +447,27 @@ $.widget( "ui.menu", {
},
_move: function( direction, filter, event ) {
- if ( !this.active ) {
- this.focus( event, this.activeMenu.children( ".ui-menu-item" )[ filter ]() );
- return;
- }
-
var next;
- if ( direction === "first" || direction === "last" ) {
- next = this.active[ direction === "first" ? "prevAll" : "nextAll" ]( ".ui-menu-item" ).eq( -1 );
- } else {
- next = this.active[ direction + "All" ]( ".ui-menu-item" ).eq( 0 );
+ if ( this.active ) {
+ if ( direction === "first" || direction === "last" ) {
+ next = this.active[ direction === "first" ? "prevAll" : "nextAll" ]( ".ui-menu-item" ).not( ".ui-state-disabled" ).eq( -1 );
+ } else {
+ next = this.active[ direction + "All" ]( ".ui-menu-item" ).not( ".ui-state-disabled" ).eq( 0 );
+ }
+ }
+ if ( !next.length || !this.active ) {
+ next = this.activeMenu.children( ".ui-menu-item" )[ filter ]();
}
- if ( next.length ) {
- this.focus( event, next );
- } else {
- this.focus( event, this.activeMenu.children( ".ui-menu-item" )[ filter ]() );
+ this.focus( event, next );
+ if ( next.is( ".ui-state-disabled" ) ) {
+ this._move( direction, filter, event );
}
},
nextPage: function( event ) {
if ( !this.active ) {
- this.focus( event, this.activeMenu.children( ".ui-menu-item" ).first() );
+ this._move( "next", "first", event );
return;
}
if ( this.isLastItem() ) {
@@ -478,21 +477,21 @@ $.widget( "ui.menu", {
var base = this.active.offset().top,
height = this.element.height(),
result;
- this.active.nextAll( ".ui-menu-item" ).each( function() {
+ this.active.nextAll( ".ui-menu-item" ).not( ".ui-state-disabled" ).each( function() {
result = $( this );
return $( this ).offset().top - base - height < 0;
});
this.focus( event, result );
} else {
- this.focus( event, this.activeMenu.children( ".ui-menu-item" )
+ this.focus( event, this.activeMenu.children( ".ui-menu-item" ).not( ".ui-state-disabled" )
[ !this.active ? "first" : "last" ]() );
}
},
previousPage: function( event ) {
if ( !this.active ) {
- this.focus( event, this.activeMenu.children( ".ui-menu-item" ).first() );
+ this._move( "next", "first", event );
return;
}
if ( this.isFirstItem() ) {
@@ -502,14 +501,14 @@ $.widget( "ui.menu", {
var base = this.active.offset().top,
height = this.element.height(),
result;
- this.active.prevAll( ".ui-menu-item" ).each( function() {
+ this.active.prevAll( ".ui-menu-item" ).not( ".ui-state-disabled" ).each( function() {
result = $( this );
return $(this).offset().top - base + height > 0;
});
this.focus( event, result );
} else {
- this.focus( event, this.activeMenu.children( ".ui-menu-item" ).first() );
+ this.focus( event, this.activeMenu.children( ".ui-menu-item" ).not( ".ui-state-disabled" ).first() );
}
},