Skip to content

Commit bf26bf1

Browse files
committed
Menu: Get rid of var self, replacing with that or calls to _delay
1 parent 3a0340f commit bf26bf1

File tree

1 file changed

+41
-47
lines changed

1 file changed

+41
-47
lines changed

ui/jquery.ui.menu.js

Lines changed: 41 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ $.widget( "ui.menu", {
2626
}
2727
},
2828
_create: function() {
29-
var self = this;
3029
this.activeMenu = this.element;
3130
this.menuId = this.element.attr( "id" ) || "ui-menu-" + idIncrement++;
3231
if ( this.element.find( ".ui-icon" ).length ) {
@@ -40,11 +39,11 @@ $.widget( "ui.menu", {
4039
})
4140
// need to catch all clicks on disabled menu
4241
// not possible through _bind
43-
.bind( "click.menu", function( event ) {
44-
if ( self.options.disabled ) {
42+
.bind( "click.menu", $.proxy( function( event ) {
43+
if ( this.options.disabled ) {
4544
event.preventDefault();
4645
}
47-
});
46+
}, this));
4847
this._bind({
4948
"click .ui-menu-item:has(a)": function( event ) {
5049
event.stopImmediatePropagation();
@@ -76,70 +75,70 @@ $.widget( "ui.menu", {
7675
"keydown": function( event ) {
7776
switch ( event.keyCode ) {
7877
case $.ui.keyCode.PAGE_UP:
79-
self.previousPage( event );
78+
this.previousPage( event );
8079
event.preventDefault();
8180
event.stopImmediatePropagation();
8281
break;
8382
case $.ui.keyCode.PAGE_DOWN:
84-
self.nextPage( event );
83+
this.nextPage( event );
8584
event.preventDefault();
8685
event.stopImmediatePropagation();
8786
break;
8887
case $.ui.keyCode.HOME:
89-
self._move( "first", "first", event );
88+
this._move( "first", "first", event );
9089
event.preventDefault();
9190
event.stopImmediatePropagation();
9291
break;
9392
case $.ui.keyCode.END:
94-
self._move( "last", "last", event );
93+
this._move( "last", "last", event );
9594
event.preventDefault();
9695
event.stopImmediatePropagation();
9796
break;
9897
case $.ui.keyCode.UP:
99-
self.previous( event );
98+
this.previous( event );
10099
event.preventDefault();
101100
event.stopImmediatePropagation();
102101
break;
103102
case $.ui.keyCode.DOWN:
104-
self.next( event );
103+
this.next( event );
105104
event.preventDefault();
106105
event.stopImmediatePropagation();
107106
break;
108107
case $.ui.keyCode.LEFT:
109-
if (self.collapse( event )) {
108+
if (this.collapse( event )) {
110109
event.stopImmediatePropagation();
111110
}
112111
event.preventDefault();
113112
break;
114113
case $.ui.keyCode.RIGHT:
115-
if (self.expand( event )) {
114+
if (this.expand( event )) {
116115
event.stopImmediatePropagation();
117116
}
118117
event.preventDefault();
119118
break;
120119
case $.ui.keyCode.ENTER:
121-
if ( self.active.children( "a[aria-haspopup='true']" ).length ) {
122-
if ( self.expand( event ) ) {
120+
if ( this.active.children( "a[aria-haspopup='true']" ).length ) {
121+
if ( this.expand( event ) ) {
123122
event.stopImmediatePropagation();
124123
}
125124
}
126125
else {
127-
self.select( event );
126+
this.select( event );
128127
event.stopImmediatePropagation();
129128
}
130129
event.preventDefault();
131130
break;
132131
case $.ui.keyCode.ESCAPE:
133-
if ( self.collapse( event ) ) {
132+
if ( this.collapse( event ) ) {
134133
event.stopImmediatePropagation();
135134
}
136135
event.preventDefault();
137136
break;
138137
default:
139138
event.stopPropagation();
140-
clearTimeout( self.filterTimer );
139+
clearTimeout( this.filterTimer );
141140
var match,
142-
prev = self.previousFilter || "",
141+
prev = this.previousFilter || "",
143142
character = String.fromCharCode( event.keyCode ),
144143
skip = false;
145144

@@ -151,30 +150,30 @@ $.widget( "ui.menu", {
151150
function escape( value ) {
152151
return value.replace( /[-[\]{}()*+?.,\\^$|#\s]/g , "\\$&" );
153152
}
154-
match = self.activeMenu.children( ".ui-menu-item" ).filter( function() {
153+
match = this.activeMenu.children( ".ui-menu-item" ).filter( function() {
155154
return new RegExp("^" + escape(character), "i")
156155
.test( $( this ).children( "a" ).text() );
157156
});
158-
match = skip && match.index(self.active.next()) != -1 ? self.active.nextAll(".ui-menu-item") : match;
157+
match = skip && match.index(this.active.next()) != -1 ? this.active.nextAll(".ui-menu-item") : match;
159158
if ( !match.length ) {
160159
character = String.fromCharCode(event.keyCode);
161-
match = self.activeMenu.children(".ui-menu-item").filter( function() {
160+
match = this.activeMenu.children(".ui-menu-item").filter( function() {
162161
return new RegExp("^" + escape(character), "i")
163162
.test( $( this ).children( "a" ).text() );
164163
});
165164
}
166165
if ( match.length ) {
167-
self.focus( event, match );
166+
this.focus( event, match );
168167
if (match.length > 1) {
169-
self.previousFilter = character;
170-
self.filterTimer = setTimeout( function() {
171-
delete self.previousFilter;
168+
this.previousFilter = character;
169+
this.filterTimer = this._delay( function() {
170+
delete this.previousFilter;
172171
}, 1000 );
173172
} else {
174-
delete self.previousFilter;
173+
delete this.previousFilter;
175174
}
176175
} else {
177-
delete self.previousFilter;
176+
delete this.previousFilter;
178177
}
179178
}
180179
}
@@ -219,7 +218,7 @@ $.widget( "ui.menu", {
219218
},
220219

221220
refresh: function() {
222-
var self = this,
221+
var that = this,
223222

224223
// initialize nested menus
225224
submenus = this.element.find( "ul:not(.ui-menu)" )
@@ -239,7 +238,7 @@ $.widget( "ui.menu", {
239238
.attr( "tabIndex", -1 )
240239
.attr( "role", "menuitem" )
241240
.attr( "id", function( i ) {
242-
return self.element.attr( "id" ) + "-" + i;
241+
return that.element.attr( "id" ) + "-" + i;
243242
});
244243

245244
submenus.each( function() {
@@ -253,9 +252,6 @@ $.widget( "ui.menu", {
253252
},
254253

255254
focus: function( event, item ) {
256-
var nested,
257-
self = this;
258-
259255
this.blur( event );
260256

261257
if ( this._hasScroll() ) {
@@ -277,18 +273,18 @@ $.widget( "ui.menu", {
277273
.children( "a" )
278274
.addClass( "ui-state-focus" )
279275
.end();
280-
self.element.attr( "aria-activedescendant", self.active.children("a").attr("id") );
276+
this.element.attr( "aria-activedescendant", this.active.children("a").attr("id") );
281277

282278
// highlight active parent menu item, if any
283279
this.active.parent().closest(".ui-menu-item").children("a:first").addClass("ui-state-active");
284280

285-
self.timer = setTimeout( function() {
286-
self._close();
287-
}, self.delay );
281+
this.timer = this._delay( function() {
282+
this._close();
283+
}, this.delay );
288284

289-
nested = $( ">ul", item );
285+
var nested = $( ">ul", item );
290286
if ( nested.length && ( /^mouse/.test( event.type ) ) ) {
291-
self._startOpening(nested);
287+
this._startOpening(nested);
292288
}
293289
this.activeMenu = item.parent();
294290

@@ -317,11 +313,10 @@ $.widget( "ui.menu", {
317313
return;
318314
}
319315

320-
var self = this;
321-
self.timer = setTimeout( function() {
322-
self._close();
323-
self._open( submenu );
324-
}, self.delay );
316+
this.timer = this._delay( function() {
317+
this._close();
318+
this._open( submenu );
319+
}, this.delay );
325320
},
326321

327322
_open: function( submenu ) {
@@ -383,15 +378,14 @@ $.widget( "ui.menu", {
383378
},
384379

385380
expand: function( event ) {
386-
var self = this,
387-
newItem = this.active && this.active.children("ul").children("li").first();
381+
var newItem = this.active && this.active.children("ul").children("li").first();
388382

389383
if ( newItem && newItem.length ) {
390384
this._open( newItem.parent() );
391385

392386
//timeout so Firefox will not hide activedescendant change in expanding submenu from AT
393-
setTimeout( function() {
394-
self.focus( event, newItem );
387+
this._delay( function() {
388+
this.focus( event, newItem );
395389
}, 20 );
396390
return true;
397391
}

0 commit comments

Comments
 (0)