]> source.dussan.org Git - jquery-ui.git/commitdiff
Menu: Better handling of divider elements and menu items without anchors.
authorkborchers <kris.borchers@gmail.com>
Fri, 25 May 2012 04:44:51 +0000 (23:44 -0500)
committerkborchers <kris.borchers@gmail.com>
Fri, 25 May 2012 04:45:12 +0000 (23:45 -0500)
tests/unit/menu/menu.html
tests/unit/menu/menu_events.js
tests/unit/menu/menu_methods.js
tests/visual/menu/menu.html
ui/jquery.ui.menu.js

index 62585d86363e079bb34d980d344a166fde270f58..a8a76bf14db4c98903ab9491dbbde568ad8b8c1e 100644 (file)
                                <a href="#">Delphi</a>
                                <ul>
                                        <li class="foo"><a class="foo" href="#">Ada</a></li>
+                                       <li> - </li>
                                        <li class="foo"><a class="foo" href="#">Saarland</a></li>
+                                       <li></li>
                                        <li class="foo"><a class="foo" href="#">Salzburg</a></li>
+                                       <li>&ndash;</li>
                                </ul>
                        </li>
                        <li class="foo"><a class="foo" href="#">Perch</a></li>
index ec3e7d3c43988f13e860f2159e98e87b5558fae7..2132ff76457c9f410bfc9ba6bafb642a8cc7f697 100644 (file)
@@ -315,16 +315,27 @@ asyncTest("handle keyboard navigation on menu without scroll and with submenus",
                equal( $("#log").html(), "4,keydown,", "Keydown ESCAPE (close submenu)");
 
                log("keydown",true);
-               element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
-               setTimeout( menukeyboard5, 50 );
+               element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+               element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+               element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
+               setTimeout( function() {
+                       element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+                       element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
+                       setTimeout( function() {
+                               element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+                               element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+                               element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+                               equal( $("#log").html(), "0,4,2,0,1,0,6,5,keydown,", "Keydown skip dividers and items without anchors");
+
+                               log("keydown",true);
+                               element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
+                               setTimeout( menukeyboard6, 50 );
+                       }, 50 );
+               }, 50 );
        }
 
-       function menukeyboard5() {
-               equal( $("#log").html(), "0,keydown,", "Keydown ENTER (open submenu)");
-
-               log("keydown",true);
-               element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
-               equal( $("#log").html(), "Ada,keydown,", "Keydown ENTER (select item)");
+       function menukeyboard6() {
+               equal( $("#log").html(), "Ada,keydown,", "Keydown ENTER (open submenu)");
 
                start();
        }
index fc4fce4f1062baf2be2832245d5e12b748679e4e..c17986816357f4f7d73edab1f565c2e7610eb3e0 100644 (file)
@@ -29,13 +29,17 @@ test( "enable/disable", function() {
 });
 
 test( "refresh", function() {
-       expect( 3 );
+       expect( 5 );
        var menu = $( "#menu1" ).menu();
        equal(menu.find(".ui-menu-item").length,5,"Incorrect number of menu items");
        menu.append("<li><a href='#'>test item</a></li>").menu("refresh");
        equal(menu.find(".ui-menu-item").length,6,"Incorrect number of menu items");
        menu.find(".ui-menu-item:last").remove().end().menu("refresh");
        equal(menu.find(".ui-menu-item").length,5,"Incorrect number of menu items");
+       menu.append("<li>---</li>").menu("refresh");
+       equal(menu.find(".ui-menu-item").length,5,"Incorrect number of menu items");
+       menu.children(":last").remove().end().menu("refresh");
+       equal(menu.find(".ui-menu-item").length,5,"Incorrect number of menu items");
 });
 
 test("destroy", function() {
index f92de61dbc61725dab9b75160ed90ee68959fe39..dd86a6e4b846644019acf911ab7c53feb8147d09 100644 (file)
@@ -15,7 +15,7 @@
                        $( "<p>" ).text( "Selected: " + ui.item.text() ).appendTo( "#log" );
                }
 
-               $( "#menu1, #menu2, #menu3, .menu4" ).menu({
+               $( "#menu1, #menu2, #menu3, .menu4, #menu7" ).menu({
                        select: logger
                });
 
@@ -58,7 +58,6 @@
        <li><a href="#">Ada</a></li>
        <li><a href="#">Adamsville</a></li>
        <li><a href="#">Addyston</a></li>
-       <li></li>
        <li>
                <a href="#">Delphi</a>
                <ul>
        </div>
 </div>
 
+<h2>Inline with dividers and elements without anchors</h2>
+<ul id="menu7">
+       <li>Group 1</li>
+       <li class="ui-state-disabled"><a href="#">Aberdeen</a></li>
+       <li><a href="#">Ada</a></li>
+       <li><a href="#">Adamsville</a></li>
+       <li><a href="#">Addyston</a></li>
+       <li></li>
+       <li>Group 2</li>
+       <li>
+               <a href="#">Delphi</a>
+               <ul>
+                       <li class="ui-state-disabled"><a href="#">Ada</a></li>
+                       <li><a href="#">Saarland</a></li>
+                       <li><a href="#">Salzburg</a></li>
+               </ul>
+       </li>
+       <li><a href="#">Saarland</a></li>
+       <li>---</li>
+       <li>Group 3</li>
+       <li>
+               <a href="#">Salzburg</a>
+               <ul>
+                       <li>
+                               <a href="#">Delphi</a>
+                               <ul>
+                                       <li><a href="#">Ada</a></li>
+                                       <li> - </li>
+                                       <li><a href="#">Saarland</a></li>
+                                       <li>&mdash;</li>
+                                       <li><a href="#">Salzburg</a></li>
+                                       <li>&ndash;</li>
+                               </ul>
+                       </li>
+                       <li>
+                               <a href="#">Delphi</a>
+                               <ul>
+                                       <li><a href="#">Ada</a></li>
+                                       <li><a href="#">Saarland</a></li>
+                                       <li><a href="#">Salzburg</a></li>
+                               </ul>
+                       </li>
+                       <li><a href="#">Perch</a></li>
+               </ul>
+       </li>
+       <li class="ui-state-disabled"><a href="#">Amesville</a></li>
+</ul>
+
 <div style="position: absolute; top: 1em; right: 1em;">
        Log:
        <div id="log" style="height: 400px; width: 300px; overflow: auto; border: 1px solid #000;"></div>
index e6a047e5319136c34a8885e78461aa5a4dd0823f..5a3afdaafff7eb4c9bef74c5b28f84fb90165dcd 100644 (file)
@@ -299,8 +299,13 @@ $.widget( "ui.menu", {
                                        }
                                });
 
-               // initialize unlinked menu-items as dividers
-               menus.children( ":not(.ui-menu-item)" ).addClass( "ui-widget-content ui-menu-divider" );
+               // initialize unlinked menu-items containing spaces and/or dashes only as dividers
+               menus.children( ":not(.ui-menu-item)" ).each( function() {
+                       var item = $( this );
+                       if ( !/[^\-—–\s]/.test( item.text() ) ) {
+                               item.addClass( "ui-widget-content ui-menu-divider" );
+                       }
+               });
 
                // add aria-disabled attribute to any disabled menu item
                menus.children( ".ui-state-disabled" ).attr( "aria-disabled", "true" );