diff options
author | Kris Borchers <kris.borchers@gmail.com> | 2013-09-17 23:22:33 -0500 |
---|---|---|
committer | Kris Borchers <kris.borchers@gmail.com> | 2013-10-05 21:52:30 -0500 |
commit | 3a61627a501cb7ba1ce80046bfabbff0f7f2f517 (patch) | |
tree | c52dcac93224fb2258633f481533318376d8c698 /ui | |
parent | e14f75ed480e5b036bb47ab3398d1e0df28a128a (diff) | |
download | jquery-ui-3a61627a501cb7ba1ce80046bfabbff0f7f2f517.tar.gz jquery-ui-3a61627a501cb7ba1ce80046bfabbff0f7f2f517.zip |
Menu: Remove the requirement to use anchors in menu items
Diffstat (limited to 'ui')
-rw-r--r-- | ui/jquery.ui.menu.js | 70 |
1 files changed, 33 insertions, 37 deletions
diff --git a/ui/jquery.ui.menu.js b/ui/jquery.ui.menu.js index 272ab7bf4..0acba14bc 100644 --- a/ui/jquery.ui.menu.js +++ b/ui/jquery.ui.menu.js @@ -66,14 +66,14 @@ $.widget( "ui.menu", { this._on({ // Prevent focus from sticking to links inside menu after clicking // them (focus should always stay on UL during navigation). - "mousedown .ui-menu-item > a": function( event ) { + "mousedown .ui-menu-item": function( event ) { event.preventDefault(); }, - "click .ui-state-disabled > a": function( event ) { + "click .ui-state-disabled": function( event ) { event.preventDefault(); }, - "click .ui-menu-item:has(a)": function( event ) { - var target = $( event.target ).closest( ".ui-menu-item" ); + "click .ui-menu-item": function( event ) { + var target = $( event.target ); if ( !this.mouseHandled && target.not( ".ui-state-disabled" ).length ) { this.select( event ); @@ -102,7 +102,7 @@ $.widget( "ui.menu", { var target = $( event.currentTarget ); // Remove ui-state-active class from siblings of the newly focused menu item // to avoid a jump caused by adjacent elements both having a class with a border - target.siblings().children( ".ui-state-active" ).removeClass( "ui-state-active" ); + target.siblings( ".ui-state-active" ).removeClass( "ui-state-active" ); this.focus( event, target ); }, mouseleave: "collapseAll", @@ -161,18 +161,17 @@ $.widget( "ui.menu", { .removeClass( "ui-menu-item" ) .removeAttr( "role" ) .removeAttr( "aria-disabled" ) - .children( "a" ) - .removeUniqueId() - .removeClass( "ui-corner-all ui-state-hover" ) - .removeAttr( "tabIndex" ) - .removeAttr( "role" ) - .removeAttr( "aria-haspopup" ) - .children().each( function() { - var elem = $( this ); - if ( elem.data( "ui-menu-submenu-carat" ) ) { - elem.remove(); - } - }); + .removeUniqueId() + .removeClass( "ui-corner-all ui-state-hover" ) + .removeAttr( "tabIndex" ) + .removeAttr( "role" ) + .removeAttr( "aria-haspopup" ) + .children().each( function() { + var elem = $( this ); + if ( elem.data( "ui-menu-submenu-carat" ) ) { + elem.remove(); + } + }); // Destroy menu dividers this.element.find( ".ui-menu-divider" ).removeClass( "ui-menu-divider ui-widget-content" ); @@ -236,7 +235,7 @@ $.widget( "ui.menu", { regex = new RegExp( "^" + escape( character ), "i" ); match = this.activeMenu.children( ".ui-menu-item" ).filter(function() { - return regex.test( $( this ).children( "a" ).text() ); + return regex.test( $( this ).text() ); }); match = skip && match.index( this.active.next() ) !== -1 ? this.active.nextAll( ".ui-menu-item" ) : @@ -248,7 +247,7 @@ $.widget( "ui.menu", { character = String.fromCharCode( event.keyCode ); regex = new RegExp( "^" + escape( character ), "i" ); match = this.activeMenu.children( ".ui-menu-item" ).filter(function() { - return regex.test( $( this ).children( "a" ).text() ); + return regex.test( $( this ).text() ); }); } @@ -274,7 +273,7 @@ $.widget( "ui.menu", { _activate: function( event ) { if ( !this.active.is( ".ui-state-disabled" ) ) { - if ( this.active.children( "a[aria-haspopup='true']" ).length ) { + if ( this.active.is( "[aria-haspopup='true']" ) ) { this.expand( event ); } else { this.select( event ); @@ -300,7 +299,7 @@ $.widget( "ui.menu", { }) .each(function() { var menu = $( this ), - item = menu.prev( "a" ), + item = menu.parent(), submenuCarat = $( "<span>" ) .addClass( "ui-menu-icon ui-icon " + icon ) .data( "ui-menu-submenu-carat", true ); @@ -313,18 +312,6 @@ $.widget( "ui.menu", { menus = submenus.add( this.element ); - // Don't refresh list items that are already adapted - menus.children( ":not(.ui-menu-item):has(a)" ) - .addClass( "ui-menu-item" ) - .attr( "role", "presentation" ) - .children( "a" ) - .uniqueId() - .addClass( "ui-corner-all" ) - .attr({ - tabIndex: -1, - role: this._itemRole() - }); - // Initialize unlinked menu-items containing spaces and/or dashes only as dividers menus.children( ":not(.ui-menu-item)" ).each(function() { var item = $( this ); @@ -334,6 +321,16 @@ $.widget( "ui.menu", { } }); + // Don't refresh list items that are already adapted + menus.children( ":not(.ui-menu-item,.ui-menu-divider)" ) + .addClass( "ui-menu-item" ) + .uniqueId() + .addClass( "ui-corner-all" ) + .attr({ + tabIndex: -1, + role: this._itemRole() + }); + // Add aria-disabled attribute to any disabled menu item menus.children( ".ui-state-disabled" ).attr( "aria-disabled", "true" ); @@ -371,7 +368,7 @@ $.widget( "ui.menu", { this._scrollIntoView( item ); this.active = item.first(); - focused = this.active.children( "a" ).addClass( "ui-state-focus" ); + focused = this.active.addClass( "ui-state-focus" ); // Only update aria-activedescendant if there's a role // otherwise we assume focus is managed elsewhere if ( this.options.role ) { @@ -382,7 +379,6 @@ $.widget( "ui.menu", { this.active .parent() .closest( ".ui-menu-item" ) - .children( "a:first" ) .addClass( "ui-state-active" ); if ( event && event.type === "keydown" ) { @@ -429,7 +425,7 @@ $.widget( "ui.menu", { return; } - this.active.children( "a" ).removeClass( "ui-state-focus" ); + this.active.removeClass( "ui-state-focus" ); this.active = null; this._trigger( "blur", event, { item: this.active } ); @@ -499,7 +495,7 @@ $.widget( "ui.menu", { .attr( "aria-hidden", "true" ) .attr( "aria-expanded", "false" ) .end() - .find( "a.ui-state-active" ) + .find( ".ui-state-active" ) .removeClass( "ui-state-active" ); }, |