Skip to content

Commit c0ea81a

Browse files
committed
Selectmenu: replaced self with that
1 parent 7f8f321 commit c0ea81a

File tree

1 file changed

+83
-83
lines changed

1 file changed

+83
-83
lines changed

ui/jquery.ui.selectmenu.js

Lines changed: 83 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -39,60 +39,60 @@ $.widget( "ui.selectmenu", {
3939
},
4040

4141
_create: function() {
42-
var self = this,
42+
var that = this,
4343
options = this.options,
4444
tabindex = this.element.attr( 'tabindex' ),
4545
// set a default id value, generate a new random one if not set by developer
46-
selectmenuId = self.element.attr( 'id' ) || 'ui-selectmenu-' + Math.random().toString( 16 ).slice( 2, 10 );
46+
selectmenuId = that.element.attr( 'id' ) || 'ui-selectmenu-' + Math.random().toString( 16 ).slice( 2, 10 );
4747

4848
// quick array of button and menu id's
49-
self.ids = [ selectmenuId + '-button', selectmenuId + '-menu' ];
49+
that.ids = [ selectmenuId + '-button', selectmenuId + '-menu' ];
5050

5151
// save options
52-
self.items = self.element.find( 'option' );
52+
that.items = that.element.find( 'option' );
5353

5454
// set current value
5555
if ( options.value ) {
56-
self.element[0].value = options.value;
56+
that.element[0].value = options.value;
5757
} else {
58-
options.value = self.element[0].value;
58+
options.value = that.element[0].value;
5959
}
6060

6161
// catch click event of the label
62-
self.element.bind( 'click.selectmenu', function() {
63-
self.newelement.focus();
62+
that.element.bind( 'click.selectmenu', function() {
63+
that.newelement.focus();
6464
return false;
6565
})
6666
.hide();
6767

6868
// create button
69-
self.newelement = $( '<a />', {
69+
that.newelement = $( '<a />', {
7070
href: '#' + selectmenuId,
71-
tabindex: ( tabindex ? tabindex : self.element.attr( 'disabled' ) ? 1 : 0 ),
72-
id: self.ids[ 0 ],
71+
tabindex: ( tabindex ? tabindex : that.element.attr( 'disabled' ) ? 1 : 0 ),
72+
id: that.ids[ 0 ],
7373
css: {
74-
width: self.element.outerWidth()
74+
width: that.element.outerWidth()
7575
},
7676
'aria-disabled': options.disabled,
77-
'aria-owns': self.ids[ 1 ],
77+
'aria-owns': that.ids[ 1 ],
7878
'aria-haspopup': true
7979
})
80-
.addClass( self.widgetBaseClass + '-button' )
80+
.addClass( that.widgetBaseClass + '-button' )
8181
.button({
82-
label: self.items.eq( this.element[0].selectedIndex ).text(),
82+
label: that.items.eq( this.element[0].selectedIndex ).text(),
8383
icons: {
8484
primary: ( options.dropdown ? 'ui-icon-triangle-1-s' : 'ui-icon-triangle-2-n-s' )
8585
}
8686
});
8787

8888
// wrap and insert new button
89-
self.newelementWrap = $( options.wrapperElement )
90-
.append( self.newelement )
91-
.insertAfter( self.element );
89+
that.newelementWrap = $( options.wrapperElement )
90+
.append( that.newelement )
91+
.insertAfter( that.element );
9292

93-
self.newelement.bind({
93+
that.newelement.bind({
9494
'mousedown.selectmenu': function( event ) {
95-
self._toggle( event );
95+
that._toggle( event );
9696
return false;
9797
},
9898
'click.selectmenu': function() {
@@ -101,214 +101,214 @@ $.widget( "ui.selectmenu", {
101101
'keydown.selectmenu': function( event ) {
102102
switch (event.keyCode) {
103103
case $.ui.keyCode.TAB:
104-
if ( self.opened ) self.close();
104+
if ( that.opened ) that.close();
105105
break;
106106
case $.ui.keyCode.ENTER:
107-
if ( self.opened ) self.list.menu( "select", self._getSelectedItem() );
107+
if ( that.opened ) that.list.menu( "select", that._getSelectedItem() );
108108
event.preventDefault();
109109
break;
110110
case $.ui.keyCode.SPACE:
111-
self._toggle(event);
111+
that._toggle(event);
112112
event.preventDefault();
113113
break;
114114
case $.ui.keyCode.UP:
115115
if ( event.altKey ) {
116-
self._toggle( event );
116+
that._toggle( event );
117117
} else {
118-
self._move( "previous", event );
118+
that._move( "previous", event );
119119
}
120120
event.preventDefault();
121121
break;
122122
case $.ui.keyCode.DOWN:
123123
if ( event.altKey ) {
124-
self._toggle( event );
124+
that._toggle( event );
125125
} else {
126-
self._move( "next", event );
126+
that._move( "next", event );
127127
}
128128
event.preventDefault();
129129
break;
130130
case $.ui.keyCode.LEFT:
131-
self._move( "previous", event );
131+
that._move( "previous", event );
132132
event.preventDefault();
133133
break;
134134
case $.ui.keyCode.RIGHT:
135-
self._move( "next", event );
135+
that._move( "next", event );
136136
event.preventDefault();
137137
break;
138138
default:
139-
self.list.trigger( event );
139+
that.list.trigger( event );
140140
}
141141
}
142142
});
143143

144144
// built menu
145-
self.refresh();
145+
that.refresh();
146146

147147
// document click closes menu
148148
$( document ).bind( 'mousedown.selectmenu', function( event ) {
149-
if ( self.opened && !self.hover) {
149+
if ( that.opened && !that.hover) {
150150
window.setTimeout( function() {
151-
self.close( event );
151+
that.close( event );
152152
}, 200 );
153153
}
154154
});
155155
},
156156

157157
// TODO update the value option
158158
refresh: function() {
159-
var self = this,
159+
var that = this,
160160
options = this.options;
161161

162162
// create menu portion, append to body
163-
self.list = $( '<ul />', {
163+
that.list = $( '<ul />', {
164164
'class': 'ui-widget ui-widget-content',
165165
'aria-hidden': true,
166-
'aria-labelledby': self.ids[0],
166+
'aria-labelledby': that.ids[0],
167167
role: 'listbox',
168-
id: self.ids[1]
168+
id: that.ids[1]
169169
});
170170

171171
// wrap list
172172
if ( options.dropdown ) {
173-
var setWidth = self.newelement.outerWidth();
173+
var setWidth = that.newelement.outerWidth();
174174
} else {
175-
var text = self.newelement.find( "span.ui-button-text");
175+
var text = that.newelement.find( "span.ui-button-text");
176176
var setWidth = text.width() + parseFloat( text.css( "padding-left" ) ) + parseFloat( text.css( "margin-left" ) );
177177
}
178-
self.listWrap = $( options.wrapperElement )
179-
.addClass( self.widgetBaseClass + '-menu' )
178+
that.listWrap = $( options.wrapperElement )
179+
.addClass( that.widgetBaseClass + '-menu' )
180180
.width( setWidth )
181-
.append( self.list )
181+
.append( that.list )
182182
.appendTo( options.appendTo );
183183

184-
self._initSource();
185-
self._renderMenu( self.list, options.source );
184+
that._initSource();
185+
that._renderMenu( that.list, options.source );
186186

187187
// init menu widget
188-
self.list
189-
.data( 'element.selectelemenu', self.element )
188+
that.list
189+
.data( 'element.selectelemenu', that.element )
190190
.menu({
191191
select: function( event, ui ) {
192192
var flag = false,
193193
item = ui.item.data( "item.selectmenu" );
194194

195-
if ( item.index != self.element[0].selectedIndex ) flag = true;
195+
if ( item.index != that.element[0].selectedIndex ) flag = true;
196196

197-
self._setOption( "value", item.value );
198-
item.element = self.items[ item.index ];
199-
self._trigger( "select", event, { item: item } );
197+
that._setOption( "value", item.value );
198+
item.element = that.items[ item.index ];
199+
that._trigger( "select", event, { item: item } );
200200

201-
if ( flag ) self._trigger( "change", event, { item: item } );
201+
if ( flag ) that._trigger( "change", event, { item: item } );
202202

203-
self.close( event, true);
203+
that.close( event, true);
204204
},
205205
focus: function( event, ui ) {
206-
self._trigger( "focus", event, { item: ui.item.data( "item.selectmenu" ) } );
206+
that._trigger( "focus", event, { item: ui.item.data( "item.selectmenu" ) } );
207207
}
208208
})
209209
.bind({
210210
'mouseenter.selectelemenu': function() {
211-
self.hover = true;
211+
that.hover = true;
212212
},
213213
'mouseleave .selectelemenu': function() {
214-
self.hover = false;
214+
that.hover = false;
215215
}
216216
});
217217

218218
// adjust ARIA
219-
self.list.find( "li" ).not( '.ui-selectmenu-optgroup' ).find( 'a' ).attr( 'role', 'option' );
219+
that.list.find( "li" ).not( '.ui-selectmenu-optgroup' ).find( 'a' ).attr( 'role', 'option' );
220220

221221
if ( options.dropdown ) {
222-
self.list
222+
that.list
223223
.addClass( 'ui-corner-bottom' )
224224
.removeClass( 'ui-corner-all' );
225225
}
226226

227227
// transfer disabled state
228-
if ( self.element.attr( 'disabled' ) ) {
229-
self.disable();
228+
if ( that.element.attr( 'disabled' ) ) {
229+
that.disable();
230230
} else {
231-
self.enable()
231+
that.enable()
232232
}
233233
},
234234

235235
open: function( event ) {
236-
var self = this,
236+
var that = this,
237237
options = this.options,
238-
currentItem = self._getSelectedItem();
238+
currentItem = that._getSelectedItem();
239239

240240
if ( !options.disabled ) {
241241
// close all other selectmenus
242-
$( '.' + self.widgetBaseClass + '-open' ).not( self.newelement ).each( function() {
242+
$( '.' + that.widgetBaseClass + '-open' ).not( that.newelement ).each( function() {
243243
$( this ).children( 'ul.ui-menu' ).data( 'element.selectelemenu' ).selectmenu( 'close' );
244244
});
245245

246246
if ( options.dropdown ) {
247-
self.newelement
247+
that.newelement
248248
.addClass( 'ui-corner-top' )
249249
.removeClass( 'ui-corner-all' );
250250
}
251251

252-
self.listWrap.addClass( self.widgetBaseClass + '-open' );
253-
self.list.menu( "focus", null, currentItem );
252+
that.listWrap.addClass( that.widgetBaseClass + '-open' );
253+
that.list.menu( "focus", null, currentItem );
254254

255255
if ( !options.dropdown ) {
256256
// center current item
257-
if ( self.list.css("overflow") == "auto" ) {
258-
self.list.scrollTop( self.list.scrollTop() + currentItem.position().top - self.list.outerHeight()/2 + currentItem.outerHeight()/2 );
257+
if ( that.list.css("overflow") == "auto" ) {
258+
that.list.scrollTop( that.list.scrollTop() + currentItem.position().top - that.list.outerHeight()/2 + currentItem.outerHeight()/2 );
259259
}
260260
// calculate offset
261-
var _offset = (self.list.offset().top - currentItem.offset().top + (self.newelement.outerHeight() - currentItem.outerHeight()) / 2);
261+
var _offset = (that.list.offset().top - currentItem.offset().top + (that.newelement.outerHeight() - currentItem.outerHeight()) / 2);
262262
$.extend( options.position, {
263263
my: "left top",
264264
at: "left top",
265265
offset: "0 " + _offset
266266
});
267267
}
268268

269-
self.listWrap
270-
.zIndex( self.element.zIndex() + 1 )
269+
that.listWrap
270+
.zIndex( that.element.zIndex() + 1 )
271271
.position( $.extend({
272-
of: self.newelementWrap
272+
of: that.newelementWrap
273273
}, options.position ));
274274

275-
self.opened = true;
276-
self._trigger( "open", event );
275+
that.opened = true;
276+
that._trigger( "open", event );
277277
}
278278
},
279279

280280
close: function( event, focus ) {
281-
var self = this,
281+
var that = this,
282282
options = this.options;
283283

284-
if ( self.opened ) {
284+
if ( that.opened ) {
285285
if ( options.dropdown ) {
286-
self.newelement
286+
that.newelement
287287
.addClass( 'ui-corner-all' )
288288
.removeClass( 'ui-corner-top' );
289289
}
290290

291-
self.listWrap.removeClass( self.widgetBaseClass + '-open' );
291+
that.listWrap.removeClass( that.widgetBaseClass + '-open' );
292292
this.opened = false;
293293

294-
if (focus) self.newelement.focus();
294+
if (focus) that.newelement.focus();
295295

296-
self._trigger( "close", event );
296+
that._trigger( "close", event );
297297
}
298298
},
299299

300300
_renderMenu: function( ul, items ) {
301-
var self = this,
301+
var that = this,
302302
currentOptgroup = "";
303303

304304
$.each( items, function( index, item ) {
305305
if ( item.optgroup != currentOptgroup ) {
306306
var optgroup = $( '<li class="ui-selectmenu-optgroup">' + item.optgroup + '</li>' );
307-
if ( $( self.items[ item.index ] ).parent( "optgroup" ).attr( "disabled" ) ) optgroup.addClass( 'ui-state-disabled' );
307+
if ( $( that.items[ item.index ] ).parent( "optgroup" ).attr( "disabled" ) ) optgroup.addClass( 'ui-state-disabled' );
308308
ul.append( optgroup );
309309
currentOptgroup = item.optgroup;
310310
}
311-
self._renderItem( ul, item );
311+
that._renderItem( ul, item );
312312
});
313313
},
314314

0 commit comments

Comments
 (0)