Datepicker: Several minor code improvements

Several minor code improvements and make suppressExpandOnFocus
an internal variable, remove partial button widget usage in header
This commit is contained in:
Felix Nagel 2014-06-18 02:31:31 +02:00 committed by Scott González
parent 40e8519437
commit b9d8f624ba
3 changed files with 24 additions and 28 deletions

View File

@ -18,6 +18,7 @@
}
.ui-calendar .ui-calendar-prev,
.ui-calendar .ui-calendar-next {
cursor: pointer;
position: absolute;
top: 2px;
width: 19px;

View File

@ -74,7 +74,7 @@ return $.widget( "ui.calendar", {
});
// TODO Use hoverable (no delegation support)? convert to _on?
this.element.delegate( ".ui-calendar-header a, .ui-calendar-calendar a", "mouseenter.calendar mouseleave.calendar", function() {
this.element.delegate( ".ui-calendar-header button, .ui-calendar-calendar a", "mouseenter.calendar mouseleave.calendar", function() {
$( this ).toggleClass( "ui-state-hover" );
});
@ -158,8 +158,6 @@ return $.widget( "ui.calendar", {
})
.html( pickerHtml );
this.element.find( "button" ).button();
this.grid = this.element.find( ".ui-calendar-calendar" );
},

View File

@ -32,9 +32,7 @@
}(function( $ ) {
var widget,
calendarOptions = [ "dateFormat", "eachDay", "max", "min", "numberOfMonths", "showWeek" ],
// TODO Move this to the instance?
suppressExpandOnFocus = false;
calendarOptions = [ "dateFormat", "eachDay", "max", "min", "numberOfMonths", "showWeek" ];
widget = $.widget( "ui.datepicker", {
version: "@VERSION",
@ -55,6 +53,7 @@ widget = $.widget( "ui.datepicker", {
},
_create: function() {
this.suppressExpandOnFocus = false;
this._createCalendar();
this._on( this._inputEvents );
@ -100,9 +99,10 @@ widget = $.widget( "ui.datepicker", {
this._setHiddenPicker();
this.element
.attr( "aria-haspopup", "true" )
.attr( "aria-owns", this.calendar.attr( "id" ) );
this.element.attr({
"aria-haspopup": true,
"aria-owns": this.calendar.attr( "id" )
});
},
_inputEvents: {
@ -135,7 +135,7 @@ widget = $.widget( "ui.datepicker", {
},
mousedown: function( event ) {
if ( this.isOpen ) {
suppressExpandOnFocus = true;
this.suppressExpandOnFocus = true;
this.close();
return;
}
@ -143,19 +143,17 @@ widget = $.widget( "ui.datepicker", {
clearTimeout( this.closeTimer );
},
focus: function( event ) {
if ( !suppressExpandOnFocus ) {
if ( !this.suppressExpandOnFocus && !this.isOpen ) {
this._delay( function() {
if ( !this.isOpen ) {
this.open( event );
}
this.open( event );
});
}
this._delay( function() {
suppressExpandOnFocus = false;
this.suppressExpandOnFocus = false;
}, 100 );
},
blur: function() {
suppressExpandOnFocus = false;
this.suppressExpandOnFocus = false;
}
},
@ -216,7 +214,7 @@ widget = $.widget( "ui.datepicker", {
},
_focusTrigger: function() {
suppressExpandOnFocus = true;
this.suppressExpandOnFocus = true;
this.element.focus();
},
@ -233,14 +231,14 @@ widget = $.widget( "ui.datepicker", {
}
this.calendarInstance.refresh();
this.calendar
.attr( "aria-hidden", "false" )
.attr( "aria-expanded", "true" )
.attr({
"aria-hidden": false,
"aria-expanded": true
})
.show()
.position( this._buildPosition() )
.hide();
this._show( this.calendar, this.options.show );
// Take trigger out of tab order to allow shift-tab to skip trigger
@ -262,9 +260,10 @@ widget = $.widget( "ui.datepicker", {
},
_setHiddenPicker: function() {
this.calendar
.attr( "aria-hidden", "true" )
.attr( "aria-expanded", "false" );
this.calendar.attr({
"aria-hidden": true,
"aria-expanded": false
});
},
_buildPosition: function() {
@ -297,9 +296,7 @@ widget = $.widget( "ui.datepicker", {
_destroy: function() {
this.calendarInstance.destroy();
this.calendar.remove();
this.element
.removeAttr( "aria-haspopup" )
.removeAttr( "aria-owns" );
this.element.removeAttr( "aria-haspopup aria-owns" );
},
widget: function() {