Skip to content
Permalink
Browse files

Menu: Refactor to get rid of var that. Cleanup some odd formattings a…

…nd unneeded temp vars
  • Loading branch information...
jzaefferer committed Sep 12, 2011
1 parent ae0c4e4 commit e1ec6f8ebb509b636840dfad11aa062c9877beac
Showing with 25 additions and 27 deletions.
  1. +6 −6 tests/visual/menu/menu.html
  2. +19 −21 ui/jquery.ui.menu.js
@@ -16,16 +16,16 @@
right: 10,
top: 10
}).appendTo(document.body).themeswitcher();
function create() {
menus.menu({
select: function(event, ui) {
$("<div/>").text("Selected: " + ui.item.text()).appendTo("#log");
}
});
}
var menus = $("#menu1, #menu2, #menu3, #menu4");
var menus = $("#menu1, #menu2, #menu3, .menu4");
create();
$("#toggle-destroy").toggle(function() {
@@ -41,11 +41,11 @@
<style>
body { font-size:62.5%; }
.ui-menu { width: 200px; margin-bottom: 2em; }
#menu4 { height: 200px; overflow: auto; }
.menu4 { height: 200px; overflow: auto; }
</style>
</head>
<body>

<ul id="menu1">
<li><a href="#">Aberdeen</a></li>
<li><a href="#">Ada</a></li>
@@ -132,7 +132,7 @@
</li>
</ul>

<ul id="menu4">
<ul class="menu4">
<li><a href="#">Aberdeen</a></li>
<li><a href="#">Ada</a></li>
<li><a href="#">Adamsville</a></li>
@@ -220,35 +220,33 @@ $.widget( "ui.menu", {
},

refresh: function() {
var that = this,

// initialize nested menus
submenus = this.element.find( "ul:not(.ui-menu)" )
.addClass( "ui-menu ui-widget ui-widget-content ui-corner-all" )
.attr( "role", "menu" )
.hide()
.attr( "aria-hidden", "true" )
.attr( "aria-expanded", "false" ),
// initialize nested menus
var submenus = this.element.find( "ul:not(.ui-menu)" )
.addClass( "ui-menu ui-widget ui-widget-content ui-corner-all" )
.attr( "role", "menu" )
.hide()
.attr( "aria-hidden", "true" )
.attr( "aria-expanded", "false" );

// don't refresh list items that are already adapted
items = submenus.add( this.element ).children( "li:not(.ui-menu-item):has(a)" )
.addClass( "ui-menu-item" )
.attr( "role", "presentation" );

items.children( "a" )
.addClass( "ui-corner-all" )
.attr( "tabIndex", -1 )
.attr( "role", "menuitem" )
.attr( "id", function( i ) {
return that.element.attr( "id" ) + "-" + i;
});
var menuId = this.menuId;
submenus.add( this.element ).children( "li:not(.ui-menu-item):has(a)" )
.addClass( "ui-menu-item" )
.attr( "role", "presentation" )
.children( "a" )
.addClass( "ui-corner-all" )
.attr( "tabIndex", -1 )
.attr( "role", "menuitem" )
.attr( "id", function( i ) {
return menuId + "-" + i;
});

submenus.each( function() {
var menu = $( this ),
item = menu.prev( "a" );

item.attr( "aria-haspopup", "true" )
.prepend( '<span class="ui-menu-icon ui-icon ui-icon-carat-1-e"></span>' );
.prepend( '<span class="ui-menu-icon ui-icon ui-icon-carat-1-e"></span>' );
menu.attr( "aria-labelledby", item.attr( "id" ) );
});
},

0 comments on commit e1ec6f8

Please sign in to comment.
You can’t perform that action at this time.