Skip to content

Commit 98ba7bf

Browse files
committed
Datepicker: Several minor code improvements
Several minor code improvements and make suppressExpandOnFocus an internal variable
1 parent be938a0 commit 98ba7bf

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

ui/datepicker.js

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
}(function( $ ) {
2828

2929
var widget,
30-
calendarOptions = [ "dateFormat", "eachDay", "max", "min", "numberOfMonths", "showWeek" ],
31-
// TODO Move this to the instance?
32-
suppressExpandOnFocus = false;
30+
calendarOptions = [ "dateFormat", "eachDay", "max", "min", "numberOfMonths", "showWeek" ];
3331

3432
widget = $.widget( "ui.datepicker", {
3533
version: "@VERSION",
@@ -50,6 +48,7 @@ widget = $.widget( "ui.datepicker", {
5048
},
5149

5250
_create: function() {
51+
this.suppressExpandOnFocus = false;
5352
this._createCalendar();
5453

5554
this._on( this._inputEvents );
@@ -92,9 +91,10 @@ widget = $.widget( "ui.datepicker", {
9291

9392
this._setHiddenPicker();
9493

95-
this.element
96-
.attr( "aria-haspopup", "true" )
97-
.attr( "aria-owns", this.calendar.attr( "id" ) );
94+
this.element.attr({
95+
"aria-haspopup": true,
96+
"aria-owns": this.calendar.attr( "id" )
97+
});
9898
},
9999

100100
_inputEvents: {
@@ -141,27 +141,25 @@ widget = $.widget( "ui.datepicker", {
141141
},
142142
mousedown: function( event ) {
143143
if ( this.isOpen ) {
144-
suppressExpandOnFocus = true;
144+
this.suppressExpandOnFocus = true;
145145
this.close();
146146
return;
147147
}
148148
this.open( event );
149149
clearTimeout( this.closeTimer );
150150
},
151151
focus: function( event ) {
152-
if ( !suppressExpandOnFocus ) {
152+
if ( !this.suppressExpandOnFocus && !this.isOpen ) {
153153
this._delay( function() {
154-
if ( !this.isOpen ) {
155-
this.open( event );
156-
}
154+
this.open( event );
157155
}, 1);
158156
}
159157
this._delay( function() {
160-
suppressExpandOnFocus = false;
158+
this.suppressExpandOnFocus = false;
161159
}, 100 );
162160
},
163161
blur: function() {
164-
suppressExpandOnFocus = false;
162+
this.suppressExpandOnFocus = false;
165163
}
166164
},
167165

@@ -222,7 +220,7 @@ widget = $.widget( "ui.datepicker", {
222220
},
223221

224222
_focusTrigger: function() {
225-
suppressExpandOnFocus = true;
223+
this.suppressExpandOnFocus = true;
226224
this.element.focus();
227225
},
228226

@@ -240,14 +238,14 @@ widget = $.widget( "ui.datepicker", {
240238
}
241239

242240
this.calendarInstance.refresh();
243-
244241
this.calendar
245-
.attr( "aria-hidden", "false" )
246-
.attr( "aria-expanded", "true" )
242+
.attr({
243+
"aria-hidden": false,
244+
"aria-expanded": true
245+
})
247246
.show()
248247
.position( this._buildPosition() )
249248
.hide();
250-
251249
this._show( this.calendar, this.options.show );
252250

253251
// Take trigger out of tab order to allow shift-tab to skip trigger
@@ -269,9 +267,10 @@ widget = $.widget( "ui.datepicker", {
269267
},
270268

271269
_setHiddenPicker: function() {
272-
this.calendar
273-
.attr( "aria-hidden", "true" )
274-
.attr( "aria-expanded", "false" );
270+
this.calendar.attr({
271+
"aria-hidden": true,
272+
"aria-expanded": false
273+
});
275274
},
276275

277276
_buildPosition: function() {
@@ -304,9 +303,7 @@ widget = $.widget( "ui.datepicker", {
304303
_destroy: function() {
305304
this.calendarInstance.destroy();
306305
this.calendar.remove();
307-
this.element
308-
.removeAttr( "aria-haspopup" )
309-
.removeAttr( "aria-owns" );
306+
this.element.removeAttr( "aria-haspopup aria-owns" );
310307
},
311308

312309
widget: function() {
@@ -337,7 +334,7 @@ widget = $.widget( "ui.datepicker", {
337334
}
338335
}
339336
});
340-
337+
341338
$.each( calendarOptions, function( index, option ) {
342339
$.ui.datepicker.prototype.options[ option ] = $.ui.calendar.prototype.options[ option ];
343340
});

0 commit comments

Comments
 (0)