menu: Second pass style guidance

This commit is contained in:
gnarf 2011-06-10 07:23:01 -05:00
parent e993a9b210
commit 85eeaf0b05

66
ui/jquery.ui.menu.js vendored
View File

@ -144,13 +144,15 @@ $.widget("ui.menu", {
return value.replace( /[-[\]{}()*+?.,\\^$|#\s]/g , "\\$&" );
}
match = self.activeMenu.children( ".ui-menu-item" ).filter( function() {
return new RegExp("^" + escape(character), "i").test($(this).children("a").text());
return new RegExp("^" + escape(character), "i")
.test( $( this ).children( "a" ).text() );
});
match = skip && match.index(self.active.next()) != -1 ? self.active.nextAll(".ui-menu-item") : match;
if ( !match.length ) {
character = String.fromCharCode(event.keyCode);
match = self.activeMenu.children(".ui-menu-item").filter( function() {
return new RegExp("^" + escape(character), "i").test($(this).children("a").text());
return new RegExp("^" + escape(character), "i")
.test( $( this ).children( "a" ).text() );
});
}
if ( match.length ) {
@ -195,22 +197,23 @@ $.widget("ui.menu", {
.removeAttr( "role" )
.removeAttr( "aria-haspopup" )
.removeAttr( "id" )
.children(".ui-icon").remove();
.children( ".ui-icon" )
.remove();
},
refresh: function() {
var self = this;
var self = this,
// initialize nested menus
var submenus = this.element.find( "ul:not(.ui-menu)" )
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" )
;
.attr( "aria-expanded", "false" ),
// don't refresh list items that are already adapted
var items = submenus.add( this.element ).children( "li:not(.ui-menu-item):has(a)" )
items = submenus.add( this.element ).children( "li:not(.ui-menu-item):has(a)" )
.addClass( "ui-menu-item" )
.attr( "role", "presentation" );
@ -233,7 +236,8 @@ $.widget("ui.menu", {
},
focus: function( event, item ) {
var nested, self = this;
var nested,
self = this;
this.blur();
@ -244,6 +248,7 @@ $.widget("ui.menu", {
scroll = this.element.scrollTop(),
elementHeight = this.element.height(),
itemHeight = item.height();
if ( offset < 0 ) {
this.element.scrollTop( scroll + offset );
} else if ( offset + itemHeight > elementHeight ) {
@ -295,45 +300,68 @@ $.widget("ui.menu", {
_open: function( submenu ) {
clearTimeout( this.timer );
this.element.find(".ui-menu").not(submenu.parents()).hide().attr("aria-hidden", "true");
this.element
.find( ".ui-menu" )
.not( submenu.parents() )
.hide()
.attr( "aria-hidden", "true" );
var position = $.extend({}, {
of: this.active
}, $.type(this.options.position) == "function"
? this.options.position(this.active)
: this.options.position
);
submenu.show().removeAttr("aria-hidden").attr("aria-expanded", "true").position(position);
submenu.show()
.removeAttr( "aria-hidden" )
.attr( "aria-expanded", "true" )
.position( position );
},
closeAll: function() {
this.element
.find("ul").hide().attr("aria-hidden", "true").attr("aria-expanded", "false").end()
.find("a.ui-state-active").removeClass("ui-state-active");
.find( "ul" )
.hide()
.attr( "aria-hidden", "true" )
.attr( "aria-expanded", "false" )
.end()
.find( "a.ui-state-active" )
.removeClass( "ui-state-active" );
this.blur();
this.activeMenu = this.element;
},
_close: function() {
this.active.parent()
.find("ul").hide().attr("aria-hidden", "true").attr("aria-expanded", "false").end()
.find("a.ui-state-active").removeClass("ui-state-active");
.find( "ul" )
.hide()
.attr( "aria-hidden", "true" )
.attr( "aria-expanded", "false" )
.end()
.find( "a.ui-state-active" )
.removeClass( "ui-state-active" );
},
left: function( event ) {
var newItem = this.active && this.active.parents("li:not(.ui-menubar-item)").first();
if ( newItem && newItem.length ) {
this.active.parent().attr("aria-hidden", "true").attr("aria-expanded", "false").hide();
this.active.parent()
.attr("aria-hidden", "true")
.attr("aria-expanded", "false")
.hide();
this.focus( event, newItem );
return true;
}
},
right: function( event ) {
var self= this;
var newItem = this.active && this.active.children("ul").children("li").first();
var self = this,
newItem = this.active && this.active.children("ul").children("li").first();
if ( newItem && newItem.length ) {
this._open( newItem.parent() );
var current = this.active;
//timeout so Firefox will not hide activedescendant change in expanding submenu from AT
setTimeout( function() {