mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
menu: Partial Style Guidance - Fixing JSLint Warnings
This commit is contained in:
parent
596f61b8dd
commit
e993a9b210
57
ui/jquery.ui.menu.js
vendored
57
ui/jquery.ui.menu.js
vendored
@ -130,9 +130,11 @@ $.widget("ui.menu", {
|
|||||||
default:
|
default:
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
clearTimeout(self.filterTimer);
|
clearTimeout(self.filterTimer);
|
||||||
var prev = self.previousFilter || "";
|
var match,
|
||||||
var character = String.fromCharCode(event.keyCode);
|
prev = self.previousFilter || "",
|
||||||
var skip = false;
|
character = String.fromCharCode( event.keyCode ),
|
||||||
|
skip = false;
|
||||||
|
|
||||||
if (character == prev) {
|
if (character == prev) {
|
||||||
skip = true;
|
skip = true;
|
||||||
} else {
|
} else {
|
||||||
@ -141,10 +143,10 @@ $.widget("ui.menu", {
|
|||||||
function escape(value) {
|
function escape(value) {
|
||||||
return value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
return value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
||||||
}
|
}
|
||||||
var match = self.activeMenu.children(".ui-menu-item").filter(function() {
|
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());
|
||||||
});
|
});
|
||||||
var match = skip && match.index(self.active.next()) != -1 ? self.active.nextAll(".ui-menu-item") : match;
|
match = skip && match.index(self.active.next()) != -1 ? self.active.nextAll(".ui-menu-item") : match;
|
||||||
if (!match.length) {
|
if (!match.length) {
|
||||||
character = String.fromCharCode(event.keyCode);
|
character = String.fromCharCode(event.keyCode);
|
||||||
match = self.activeMenu.children(".ui-menu-item").filter(function() {
|
match = self.activeMenu.children(".ui-menu-item").filter(function() {
|
||||||
@ -199,16 +201,16 @@ $.widget("ui.menu", {
|
|||||||
refresh: function() {
|
refresh: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
// initialize nested menus
|
// initialize nested menus
|
||||||
var submenus = this.element.find("ul:not(.ui-menu)")
|
var submenus = this.element.find( "ul:not(.ui-menu)" )
|
||||||
.addClass( "ui-menu ui-widget ui-widget-content ui-corner-all" )
|
.addClass( "ui-menu ui-widget ui-widget-content ui-corner-all" )
|
||||||
.attr("role", "menu")
|
.attr( "role", "menu" )
|
||||||
.hide()
|
.hide()
|
||||||
.attr("aria-hidden", "true")
|
.attr( "aria-hidden", "true" )
|
||||||
.attr("aria-expanded", "false")
|
.attr( "aria-expanded", "false" )
|
||||||
;
|
;
|
||||||
|
|
||||||
// don't refresh list items that are already adapted
|
// don't refresh list items that are already adapted
|
||||||
var items = submenus.add(this.element).children( "li:not(.ui-menu-item):has(a)" )
|
var items = submenus.add( this.element ).children( "li:not(.ui-menu-item):has(a)" )
|
||||||
.addClass( "ui-menu-item" )
|
.addClass( "ui-menu-item" )
|
||||||
.attr( "role", "presentation" );
|
.attr( "role", "presentation" );
|
||||||
|
|
||||||
@ -216,19 +218,22 @@ $.widget("ui.menu", {
|
|||||||
.addClass( "ui-corner-all" )
|
.addClass( "ui-corner-all" )
|
||||||
.attr( "tabIndex", -1 )
|
.attr( "tabIndex", -1 )
|
||||||
.attr( "role", "menuitem" )
|
.attr( "role", "menuitem" )
|
||||||
.attr("id", function(i) {return self.element.attr("id") + "-" + i});
|
.attr( "id", function( i ) {
|
||||||
|
return self.element.attr( "id" ) + "-" + i;
|
||||||
|
});
|
||||||
|
|
||||||
submenus.each(function() {
|
submenus.each( function() {
|
||||||
var menu = $(this);
|
var menu = $( this ),
|
||||||
var item = menu.prev("a")
|
item = menu.prev( "a" );
|
||||||
item.attr("aria-haspopup", "true")
|
|
||||||
.prepend('<span class="ui-menu-icon ui-icon ui-icon-carat-1-e"></span>');
|
item.attr( "aria-haspopup", "true" )
|
||||||
menu.attr("aria-labelledby", item.attr("id"));
|
.prepend( '<span class="ui-menu-icon ui-icon ui-icon-carat-1-e"></span>' );
|
||||||
|
menu.attr( "aria-labelledby", item.attr( "id" ) );
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
focus: function( event, item ) {
|
focus: function( event, item ) {
|
||||||
var self = this;
|
var nested, self = this;
|
||||||
|
|
||||||
this.blur();
|
this.blur();
|
||||||
|
|
||||||
@ -250,16 +255,17 @@ $.widget("ui.menu", {
|
|||||||
.children( "a" )
|
.children( "a" )
|
||||||
.addClass( "ui-state-focus" )
|
.addClass( "ui-state-focus" )
|
||||||
.end();
|
.end();
|
||||||
self.element.attr("aria-activedescendant", self.active.children("a").attr("id"))
|
self.element.attr( "aria-activedescendant", self.active.children("a").attr("id") );
|
||||||
|
|
||||||
// highlight active parent menu item, if any
|
// highlight active parent menu item, if any
|
||||||
this.active.parent().closest(".ui-menu-item").children("a:first").addClass("ui-state-active");
|
this.active.parent().closest(".ui-menu-item").children("a:first").addClass("ui-state-active");
|
||||||
|
|
||||||
self.timer = setTimeout(function() {
|
self.timer = setTimeout( function() {
|
||||||
self._close();
|
self._close();
|
||||||
}, self.delay)
|
}, self.delay );
|
||||||
var nested = $(">ul", item);
|
|
||||||
if (nested.length && /^mouse/.test(event.type)) {
|
nested = $( ">ul", item );
|
||||||
|
if ( nested.length && ( /^mouse/.test( event.type ) ) ) {
|
||||||
self._startOpening(nested);
|
self._startOpening(nested);
|
||||||
}
|
}
|
||||||
this.activeMenu = item.parent();
|
this.activeMenu = item.parent();
|
||||||
@ -328,8 +334,11 @@ $.widget("ui.menu", {
|
|||||||
if (newItem && newItem.length) {
|
if (newItem && newItem.length) {
|
||||||
this._open(newItem.parent());
|
this._open(newItem.parent());
|
||||||
var current = this.active;
|
var current = this.active;
|
||||||
|
|
||||||
//timeout so Firefox will not hide activedescendant change in expanding submenu from AT
|
//timeout so Firefox will not hide activedescendant change in expanding submenu from AT
|
||||||
setTimeout(function(){self.focus(event, newItem)}, 20);
|
setTimeout( function() {
|
||||||
|
self.focus( event, newItem );
|
||||||
|
}, 20 );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user