mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
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:
parent
40e8519437
commit
b9d8f624ba
@ -18,6 +18,7 @@
|
|||||||
}
|
}
|
||||||
.ui-calendar .ui-calendar-prev,
|
.ui-calendar .ui-calendar-prev,
|
||||||
.ui-calendar .ui-calendar-next {
|
.ui-calendar .ui-calendar-next {
|
||||||
|
cursor: pointer;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 2px;
|
top: 2px;
|
||||||
width: 19px;
|
width: 19px;
|
||||||
|
@ -74,7 +74,7 @@ return $.widget( "ui.calendar", {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// TODO Use hoverable (no delegation support)? convert to _on?
|
// 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" );
|
$( this ).toggleClass( "ui-state-hover" );
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -158,8 +158,6 @@ return $.widget( "ui.calendar", {
|
|||||||
})
|
})
|
||||||
.html( pickerHtml );
|
.html( pickerHtml );
|
||||||
|
|
||||||
this.element.find( "button" ).button();
|
|
||||||
|
|
||||||
this.grid = this.element.find( ".ui-calendar-calendar" );
|
this.grid = this.element.find( ".ui-calendar-calendar" );
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -32,9 +32,7 @@
|
|||||||
}(function( $ ) {
|
}(function( $ ) {
|
||||||
|
|
||||||
var widget,
|
var widget,
|
||||||
calendarOptions = [ "dateFormat", "eachDay", "max", "min", "numberOfMonths", "showWeek" ],
|
calendarOptions = [ "dateFormat", "eachDay", "max", "min", "numberOfMonths", "showWeek" ];
|
||||||
// TODO Move this to the instance?
|
|
||||||
suppressExpandOnFocus = false;
|
|
||||||
|
|
||||||
widget = $.widget( "ui.datepicker", {
|
widget = $.widget( "ui.datepicker", {
|
||||||
version: "@VERSION",
|
version: "@VERSION",
|
||||||
@ -55,6 +53,7 @@ widget = $.widget( "ui.datepicker", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_create: function() {
|
_create: function() {
|
||||||
|
this.suppressExpandOnFocus = false;
|
||||||
this._createCalendar();
|
this._createCalendar();
|
||||||
|
|
||||||
this._on( this._inputEvents );
|
this._on( this._inputEvents );
|
||||||
@ -100,9 +99,10 @@ widget = $.widget( "ui.datepicker", {
|
|||||||
|
|
||||||
this._setHiddenPicker();
|
this._setHiddenPicker();
|
||||||
|
|
||||||
this.element
|
this.element.attr({
|
||||||
.attr( "aria-haspopup", "true" )
|
"aria-haspopup": true,
|
||||||
.attr( "aria-owns", this.calendar.attr( "id" ) );
|
"aria-owns": this.calendar.attr( "id" )
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_inputEvents: {
|
_inputEvents: {
|
||||||
@ -135,7 +135,7 @@ widget = $.widget( "ui.datepicker", {
|
|||||||
},
|
},
|
||||||
mousedown: function( event ) {
|
mousedown: function( event ) {
|
||||||
if ( this.isOpen ) {
|
if ( this.isOpen ) {
|
||||||
suppressExpandOnFocus = true;
|
this.suppressExpandOnFocus = true;
|
||||||
this.close();
|
this.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -143,19 +143,17 @@ widget = $.widget( "ui.datepicker", {
|
|||||||
clearTimeout( this.closeTimer );
|
clearTimeout( this.closeTimer );
|
||||||
},
|
},
|
||||||
focus: function( event ) {
|
focus: function( event ) {
|
||||||
if ( !suppressExpandOnFocus ) {
|
if ( !this.suppressExpandOnFocus && !this.isOpen ) {
|
||||||
this._delay( function() {
|
this._delay( function() {
|
||||||
if ( !this.isOpen ) {
|
this.open( event );
|
||||||
this.open( event );
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this._delay( function() {
|
this._delay( function() {
|
||||||
suppressExpandOnFocus = false;
|
this.suppressExpandOnFocus = false;
|
||||||
}, 100 );
|
}, 100 );
|
||||||
},
|
},
|
||||||
blur: function() {
|
blur: function() {
|
||||||
suppressExpandOnFocus = false;
|
this.suppressExpandOnFocus = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -216,7 +214,7 @@ widget = $.widget( "ui.datepicker", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_focusTrigger: function() {
|
_focusTrigger: function() {
|
||||||
suppressExpandOnFocus = true;
|
this.suppressExpandOnFocus = true;
|
||||||
this.element.focus();
|
this.element.focus();
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -233,14 +231,14 @@ widget = $.widget( "ui.datepicker", {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.calendarInstance.refresh();
|
this.calendarInstance.refresh();
|
||||||
|
|
||||||
this.calendar
|
this.calendar
|
||||||
.attr( "aria-hidden", "false" )
|
.attr({
|
||||||
.attr( "aria-expanded", "true" )
|
"aria-hidden": false,
|
||||||
|
"aria-expanded": true
|
||||||
|
})
|
||||||
.show()
|
.show()
|
||||||
.position( this._buildPosition() )
|
.position( this._buildPosition() )
|
||||||
.hide();
|
.hide();
|
||||||
|
|
||||||
this._show( this.calendar, this.options.show );
|
this._show( this.calendar, this.options.show );
|
||||||
|
|
||||||
// Take trigger out of tab order to allow shift-tab to skip trigger
|
// Take trigger out of tab order to allow shift-tab to skip trigger
|
||||||
@ -262,9 +260,10 @@ widget = $.widget( "ui.datepicker", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_setHiddenPicker: function() {
|
_setHiddenPicker: function() {
|
||||||
this.calendar
|
this.calendar.attr({
|
||||||
.attr( "aria-hidden", "true" )
|
"aria-hidden": true,
|
||||||
.attr( "aria-expanded", "false" );
|
"aria-expanded": false
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_buildPosition: function() {
|
_buildPosition: function() {
|
||||||
@ -297,9 +296,7 @@ widget = $.widget( "ui.datepicker", {
|
|||||||
_destroy: function() {
|
_destroy: function() {
|
||||||
this.calendarInstance.destroy();
|
this.calendarInstance.destroy();
|
||||||
this.calendar.remove();
|
this.calendar.remove();
|
||||||
this.element
|
this.element.removeAttr( "aria-haspopup aria-owns" );
|
||||||
.removeAttr( "aria-haspopup" )
|
|
||||||
.removeAttr( "aria-owns" );
|
|
||||||
},
|
},
|
||||||
|
|
||||||
widget: function() {
|
widget: function() {
|
||||||
@ -330,7 +327,7 @@ widget = $.widget( "ui.datepicker", {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$.each( calendarOptions, function( index, option ) {
|
$.each( calendarOptions, function( index, option ) {
|
||||||
$.ui.datepicker.prototype.options[ option ] = $.ui.calendar.prototype.options[ option ];
|
$.ui.datepicker.prototype.options[ option ] = $.ui.calendar.prototype.options[ option ];
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user