]> source.dussan.org Git - jquery-ui.git/commitdiff
Menu: Look into submenus for uninitialized menu items. Fixes #8773 - Menu: refresh...
authorJörn Zaefferer <joern.zaefferer@gmail.com>
Mon, 5 Nov 2012 17:37:48 +0000 (18:37 +0100)
committerScott González <scott.gonzalez@gmail.com>
Thu, 8 Nov 2012 22:54:42 +0000 (17:54 -0500)
(cherry picked from commit 8b3e57024138f1a40be762fd5d29cc390129a8ad)

tests/unit/menu/menu_methods.js
ui/jquery.ui.menu.js

index c49783c3e4dc41ed8769003e4f36d2bf6b672b0c..a7e78ea699453249177d069ec0109cd4378b2ee4 100644 (file)
@@ -60,6 +60,15 @@ test( "refresh", function() {
        equal( element.find( ".ui-menu-item" ).length, 5, "Incorrect number of menu items" );
 });
 
+test( "refresh submenu", function() {
+       expect( 2 );
+       var element = $( "#menu2" ).menu();
+       equal( element.find( "ul:first .ui-menu-item" ).length, 3 );
+       element.find( "ul" ).andSelf().append( "<li><a href=\"#\">New Item</a></li>" );
+       element.menu("refresh");
+       equal( element.find( "ul:first .ui-menu-item" ).length, 4 );
+});
+
 test( "widget", function() {
        expect( 2 );
        var element = $( "#menu1" ).menu(),
index 5d401da5351c4a961dbf6f43e45df3aa9f1bcb62..45c1ec2e4b64722290aa11246a6feaf652d25ad1 100644 (file)
@@ -277,21 +277,35 @@ $.widget( "ui.menu", {
        },
 
        refresh: function() {
-               // Initialize nested menus
                var menus,
                        icon = this.options.icons.submenu,
-                       submenus = this.element.find( this.options.menus + ":not(.ui-menu)" )
-                               .addClass( "ui-menu ui-widget ui-widget-content ui-corner-all" )
-                               .hide()
-                               .attr({
-                                       role: this.options.role,
-                                       "aria-hidden": "true",
-                                       "aria-expanded": "false"
-                               });
+                       submenus = this.element.find( this.options.menus );
+
+               // Initialize nested menus
+               submenus.filter( ":not(.ui-menu)" )
+                       .addClass( "ui-menu ui-widget ui-widget-content ui-corner-all" )
+                       .hide()
+                       .attr({
+                               role: this.options.role,
+                               "aria-hidden": "true",
+                               "aria-expanded": "false"
+                       })
+                       .each(function() {
+                               var menu = $( this ),
+                                       item = menu.prev( "a" ),
+                                       submenuCarat = $( "<span>" )
+                                               .addClass( "ui-menu-icon ui-icon " + icon )
+                                               .data( "ui-menu-submenu-carat", true );
+
+                               item
+                                       .attr( "aria-haspopup", "true" )
+                                       .prepend( submenuCarat );
+                               menu.attr( "aria-labelledby", item.attr( "id" ) );
+                       });
 
-               // Don't refresh list items that are already adapted
                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" )
@@ -315,19 +329,6 @@ $.widget( "ui.menu", {
                // Add aria-disabled attribute to any disabled menu item
                menus.children( ".ui-state-disabled" ).attr( "aria-disabled", "true" );
 
-               submenus.each(function() {
-                       var menu = $( this ),
-                               item = menu.prev( "a" ),
-                               submenuCarat = $( "<span>" )
-                                       .addClass( "ui-menu-icon ui-icon " + icon )
-                                       .data( "ui-menu-submenu-carat", true );
-
-                       item
-                               .attr( "aria-haspopup", "true" )
-                               .prepend( submenuCarat );
-                       menu.attr( "aria-labelledby", item.attr( "id" ) );
-               });
-
                // If the active item has been removed, blur the menu
                if ( this.active && !$.contains( this.element[ 0 ], this.active[ 0 ] ) ) {
                        this.blur();