Skip to content

Commit e993a9b

Browse files
committed
menu: Partial Style Guidance - Fixing JSLint Warnings
1 parent 596f61b commit e993a9b

File tree

1 file changed

+54
-45
lines changed

1 file changed

+54
-45
lines changed

ui/jquery.ui.menu.js

Lines changed: 54 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* jQuery UI Menu @VERSION
3-
*
3+
*
44
* Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
55
* Dual licensed under the MIT or GPL Version 2 licenses.
66
* http://jquery.org/license
@@ -12,7 +12,7 @@
1212
* jquery.ui.widget.js
1313
*/
1414
(function($) {
15-
15+
1616
var idIncrement = 0;
1717

1818
$.widget("ui.menu", {
@@ -71,7 +71,7 @@ $.widget("ui.menu", {
7171
}
7272
});
7373
this.refresh();
74-
74+
7575
this.element.attr( "tabIndex", 0 ).bind( "keydown.menu", function( event ) {
7676
if ( self.options.disabled ) {
7777
return;
@@ -130,9 +130,11 @@ $.widget("ui.menu", {
130130
default:
131131
event.stopPropagation();
132132
clearTimeout(self.filterTimer);
133-
var prev = self.previousFilter || "";
134-
var character = String.fromCharCode(event.keyCode);
135-
var skip = false;
133+
var match,
134+
prev = self.previousFilter || "",
135+
character = String.fromCharCode( event.keyCode ),
136+
skip = false;
137+
136138
if (character == prev) {
137139
skip = true;
138140
} else {
@@ -141,10 +143,10 @@ $.widget("ui.menu", {
141143
function escape(value) {
142144
return value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
143145
}
144-
var match = self.activeMenu.children(".ui-menu-item").filter(function() {
146+
match = self.activeMenu.children(".ui-menu-item").filter(function() {
145147
return new RegExp("^" + escape(character), "i").test($(this).children("a").text());
146148
});
147-
var match = skip && match.index(self.active.next()) != -1 ? self.active.nextAll(".ui-menu-item") : match;
149+
match = skip && match.index(self.active.next()) != -1 ? self.active.nextAll(".ui-menu-item") : match;
148150
if (!match.length) {
149151
character = String.fromCharCode(event.keyCode);
150152
match = self.activeMenu.children(".ui-menu-item").filter(function() {
@@ -167,7 +169,7 @@ $.widget("ui.menu", {
167169
}
168170
});
169171
},
170-
172+
171173
_destroy: function() {
172174
//destroy (sub)menus
173175
this.element
@@ -181,7 +183,7 @@ $.widget("ui.menu", {
181183
.removeAttr( "aria-expanded" )
182184
.removeAttr( "aria-hidden" )
183185
.show();
184-
186+
185187
//destroy menu items
186188
this.element.find( ".ui-menu-item" )
187189
.unbind( ".menu" )
@@ -193,45 +195,48 @@ $.widget("ui.menu", {
193195
.removeAttr( "role" )
194196
.removeAttr( "aria-haspopup" )
195197
.removeAttr( "id" )
196-
.children(".ui-icon").remove();
198+
.children(".ui-icon").remove();
197199
},
198-
200+
199201
refresh: function() {
200202
var self = this;
201203
// initialize nested menus
202-
var submenus = this.element.find("ul:not(.ui-menu)")
204+
var submenus = this.element.find( "ul:not(.ui-menu)" )
203205
.addClass( "ui-menu ui-widget ui-widget-content ui-corner-all" )
204-
.attr("role", "menu")
206+
.attr( "role", "menu" )
205207
.hide()
206-
.attr("aria-hidden", "true")
207-
.attr("aria-expanded", "false")
208+
.attr( "aria-hidden", "true" )
209+
.attr( "aria-expanded", "false" )
208210
;
209-
211+
210212
// don't refresh list items that are already adapted
211-
var items = submenus.add(this.element).children( "li:not(.ui-menu-item):has(a)" )
213+
var items = submenus.add( this.element ).children( "li:not(.ui-menu-item):has(a)" )
212214
.addClass( "ui-menu-item" )
213215
.attr( "role", "presentation" );
214-
216+
215217
items.children( "a" )
216218
.addClass( "ui-corner-all" )
217219
.attr( "tabIndex", -1 )
218220
.attr( "role", "menuitem" )
219-
.attr("id", function(i) {return self.element.attr("id") + "-" + i});
220-
221-
submenus.each(function() {
222-
var menu = $(this);
223-
var item = menu.prev("a")
224-
item.attr("aria-haspopup", "true")
225-
.prepend('<span class="ui-menu-icon ui-icon ui-icon-carat-1-e"></span>');
226-
menu.attr("aria-labelledby", item.attr("id"));
221+
.attr( "id", function( i ) {
222+
return self.element.attr( "id" ) + "-" + i;
223+
});
224+
225+
submenus.each( function() {
226+
var menu = $( this ),
227+
item = menu.prev( "a" );
228+
229+
item.attr( "aria-haspopup", "true" )
230+
.prepend( '<span class="ui-menu-icon ui-icon ui-icon-carat-1-e"></span>' );
231+
menu.attr( "aria-labelledby", item.attr( "id" ) );
227232
});
228233
},
229234

230235
focus: function( event, item ) {
231-
var self = this;
232-
236+
var nested, self = this;
237+
233238
this.blur();
234-
239+
235240
if ( this._hasScroll() ) {
236241
var borderTop = parseFloat( $.curCSS( this.element[0], "borderTopWidth", true) ) || 0,
237242
paddingTop = parseFloat( $.curCSS( this.element[0], "paddingTop", true) ) || 0,
@@ -245,35 +250,36 @@ $.widget("ui.menu", {
245250
this.element.scrollTop( scroll + offset - elementHeight + itemHeight );
246251
}
247252
}
248-
253+
249254
this.active = item.first()
250255
.children( "a" )
251256
.addClass( "ui-state-focus" )
252257
.end();
253-
self.element.attr("aria-activedescendant", self.active.children("a").attr("id"))
258+
self.element.attr( "aria-activedescendant", self.active.children("a").attr("id") );
254259

255260
// highlight active parent menu item, if any
256261
this.active.parent().closest(".ui-menu-item").children("a:first").addClass("ui-state-active");
257-
258-
self.timer = setTimeout(function() {
262+
263+
self.timer = setTimeout( function() {
259264
self._close();
260-
}, self.delay)
261-
var nested = $(">ul", item);
262-
if (nested.length && /^mouse/.test(event.type)) {
265+
}, self.delay );
266+
267+
nested = $( ">ul", item );
268+
if ( nested.length && ( /^mouse/.test( event.type ) ) ) {
263269
self._startOpening(nested);
264270
}
265271
this.activeMenu = item.parent();
266-
272+
267273
this._trigger( "focus", event, { item: item } );
268274
},
269275

270276
blur: function(event) {
271277
if (!this.active) {
272278
return;
273279
}
274-
280+
275281
clearTimeout(this.timer);
276-
282+
277283
this.active.children( "a" ).removeClass( "ui-state-focus" );
278284
this.active = null;
279285
},
@@ -286,7 +292,7 @@ $.widget("ui.menu", {
286292
self._open(submenu);
287293
}, self.delay);
288294
},
289-
295+
290296
_open: function(submenu) {
291297
clearTimeout(this.timer);
292298
this.element.find(".ui-menu").not(submenu.parents()).hide().attr("aria-hidden", "true");
@@ -298,15 +304,15 @@ $.widget("ui.menu", {
298304
);
299305
submenu.show().removeAttr("aria-hidden").attr("aria-expanded", "true").position(position);
300306
},
301-
307+
302308
closeAll: function() {
303309
this.element
304310
.find("ul").hide().attr("aria-hidden", "true").attr("aria-expanded", "false").end()
305311
.find("a.ui-state-active").removeClass("ui-state-active");
306312
this.blur();
307313
this.activeMenu = this.element;
308314
},
309-
315+
310316
_close: function() {
311317
this.active.parent()
312318
.find("ul").hide().attr("aria-hidden", "true").attr("aria-expanded", "false").end()
@@ -328,8 +334,11 @@ $.widget("ui.menu", {
328334
if (newItem && newItem.length) {
329335
this._open(newItem.parent());
330336
var current = this.active;
337+
331338
//timeout so Firefox will not hide activedescendant change in expanding submenu from AT
332-
setTimeout(function(){self.focus(event, newItem)}, 20);
339+
setTimeout( function() {
340+
self.focus( event, newItem );
341+
}, 20 );
333342
return true;
334343
}
335344
},
@@ -362,7 +371,7 @@ $.widget("ui.menu", {
362371
this.focus( event, this.activeMenu.children(edge)[filter]() );
363372
}
364373
},
365-
374+
366375
nextPage: function( event ) {
367376
if ( this._hasScroll() ) {
368377
if ( !this.active || this.last() ) {

0 commit comments

Comments
 (0)