2012-02-27 00:49:51 +00:00
|
|
|
/*!
|
2008-09-04 22:03:30 +00:00
|
|
|
* jQuery UI Datepicker @VERSION
|
2012-07-04 13:08:08 +00:00
|
|
|
* http://jqueryui.com
|
2008-06-04 02:34:33 +00:00
|
|
|
*
|
2014-12-21 18:27:43 +00:00
|
|
|
* Copyright jQuery Foundation and other contributors
|
2012-08-09 14:13:24 +00:00
|
|
|
* Released under the MIT license.
|
2010-07-09 13:01:04 +00:00
|
|
|
* http://jquery.org/license
|
2008-06-04 02:34:33 +00:00
|
|
|
*/
|
2014-10-30 19:55:08 +00:00
|
|
|
|
|
|
|
//>>label: Datepicker
|
|
|
|
//>>group: Widgets
|
|
|
|
//>>description: Displays a calendar from an input or inline for selecting dates.
|
|
|
|
//>>docs: http://api.jqueryui.com/datepicker/
|
|
|
|
//>>demos: http://jqueryui.com/datepicker/
|
|
|
|
|
2013-07-12 16:40:48 +00:00
|
|
|
(function( factory ) {
|
|
|
|
if ( typeof define === "function" && define.amd ) {
|
|
|
|
|
|
|
|
// AMD. Register as an anonymous module.
|
|
|
|
define([
|
|
|
|
"jquery",
|
2013-08-26 10:44:20 +00:00
|
|
|
"./core",
|
|
|
|
"./widget",
|
2014-06-03 21:18:51 +00:00
|
|
|
"./calendar",
|
2013-08-26 10:44:20 +00:00
|
|
|
"./position"
|
2013-07-12 16:40:48 +00:00
|
|
|
], factory );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Browser globals
|
|
|
|
factory( jQuery );
|
|
|
|
}
|
|
|
|
}(function( $ ) {
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2014-06-12 12:36:45 +00:00
|
|
|
var widget,
|
2014-09-01 13:36:38 +00:00
|
|
|
calendarOptions = [ "buttons", "dateFormat", "disabled", "eachDay", "max", "min", "numberOfMonths", "showWeek" ];
|
2013-08-26 10:44:20 +00:00
|
|
|
|
2014-06-12 12:36:45 +00:00
|
|
|
widget = $.widget( "ui.datepicker", {
|
2014-06-03 21:18:51 +00:00
|
|
|
version: "@VERSION",
|
2013-08-26 10:44:20 +00:00
|
|
|
options: {
|
|
|
|
appendTo: null,
|
|
|
|
position: {
|
|
|
|
my: "left top",
|
|
|
|
at: "left bottom"
|
|
|
|
},
|
|
|
|
show: true,
|
|
|
|
hide: true,
|
|
|
|
|
|
|
|
// callbacks
|
2013-08-30 12:27:19 +00:00
|
|
|
beforeOpen: null,
|
2013-08-26 10:44:20 +00:00
|
|
|
close: null,
|
|
|
|
open: null,
|
|
|
|
select: null
|
|
|
|
},
|
2014-04-23 15:49:03 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
_create: function() {
|
2014-06-18 00:31:31 +00:00
|
|
|
this.suppressExpandOnFocus = false;
|
2014-06-03 21:18:51 +00:00
|
|
|
this._createCalendar();
|
2014-06-05 00:39:46 +00:00
|
|
|
|
|
|
|
this._on( this._inputEvents );
|
|
|
|
this._on( this.calendar, this._calendarEvents );
|
|
|
|
this._on( this.document, this._documentEvents );
|
2014-06-03 21:18:51 +00:00
|
|
|
},
|
|
|
|
|
2014-06-04 17:07:23 +00:00
|
|
|
_getCreateOptions: function() {
|
|
|
|
var max = this.element.attr( "max" ),
|
|
|
|
min = this.element.attr( "min" ),
|
|
|
|
options = {};
|
|
|
|
|
|
|
|
if ( max !== undefined ) {
|
|
|
|
options.max = Globalize.parseDate( max, { pattern: "yyyy-MM-dd" } );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( min !== undefined ) {
|
|
|
|
options.min = Globalize.parseDate( min, { pattern: "yyyy-MM-dd" } );
|
|
|
|
}
|
|
|
|
|
|
|
|
return options;
|
|
|
|
},
|
|
|
|
|
2014-06-03 21:18:51 +00:00
|
|
|
_createCalendar: function() {
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
this.calendar = $( "<div>" )
|
|
|
|
.addClass( "ui-front ui-datepicker" )
|
|
|
|
.appendTo( this._appendTo() );
|
|
|
|
|
|
|
|
// Initialize calendar widget
|
|
|
|
this.calendarInstance = this.calendar
|
2014-06-12 12:36:45 +00:00
|
|
|
.calendar( $.extend( {}, this.options, {
|
2014-06-03 21:18:51 +00:00
|
|
|
value: this._getParsedValue(),
|
2014-06-04 21:40:39 +00:00
|
|
|
select: function( event ) {
|
|
|
|
that.element.val( that.calendarInstance.value() );
|
2014-06-03 21:18:51 +00:00
|
|
|
that.close();
|
|
|
|
that._focusTrigger();
|
2014-06-04 21:40:39 +00:00
|
|
|
that._trigger( "select", event );
|
2012-11-18 20:01:30 +00:00
|
|
|
}
|
2014-06-12 12:36:45 +00:00
|
|
|
}) )
|
2014-06-03 21:18:51 +00:00
|
|
|
.calendar( "instance" );
|
2014-05-15 22:19:32 +00:00
|
|
|
|
2014-06-19 22:13:20 +00:00
|
|
|
this.calendarInstance.buttonClickContext = that.element[ 0 ];
|
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
this._setHiddenPicker();
|
|
|
|
|
2014-06-18 00:31:31 +00:00
|
|
|
this.element.attr({
|
|
|
|
"aria-haspopup": true,
|
|
|
|
"aria-owns": this.calendar.attr( "id" )
|
|
|
|
});
|
2014-06-05 00:39:46 +00:00
|
|
|
},
|
2013-08-26 10:44:20 +00:00
|
|
|
|
2014-06-05 00:39:46 +00:00
|
|
|
_inputEvents: {
|
|
|
|
keydown: function( event ) {
|
|
|
|
switch ( event.keyCode ) {
|
|
|
|
case $.ui.keyCode.TAB:
|
|
|
|
// Waiting for close() will make popup hide too late, which breaks tab key behavior
|
|
|
|
this.calendar.hide();
|
|
|
|
this.close( event );
|
|
|
|
break;
|
|
|
|
case $.ui.keyCode.ESCAPE:
|
2014-05-15 22:19:32 +00:00
|
|
|
if ( this.isOpen ) {
|
2014-06-05 00:39:46 +00:00
|
|
|
this.close( event );
|
2013-08-26 10:44:20 +00:00
|
|
|
}
|
2014-06-05 00:39:46 +00:00
|
|
|
break;
|
|
|
|
case $.ui.keyCode.DOWN:
|
|
|
|
case $.ui.keyCode.UP:
|
2013-08-26 10:44:20 +00:00
|
|
|
clearTimeout( this.closeTimer );
|
2014-06-05 00:39:46 +00:00
|
|
|
this._delay( function() {
|
|
|
|
this.open( event );
|
|
|
|
this.calendarInstance.grid.focus();
|
|
|
|
}, 1 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
keyup: function() {
|
|
|
|
if ( this.isValid() ) {
|
|
|
|
this.refresh();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mousedown: function( event ) {
|
|
|
|
if ( this.isOpen ) {
|
2014-06-18 00:31:31 +00:00
|
|
|
this.suppressExpandOnFocus = true;
|
2014-06-05 00:39:46 +00:00
|
|
|
this.close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.open( event );
|
|
|
|
clearTimeout( this.closeTimer );
|
|
|
|
},
|
|
|
|
focus: function( event ) {
|
2014-06-18 00:31:31 +00:00
|
|
|
if ( !this.suppressExpandOnFocus && !this.isOpen ) {
|
2013-08-26 10:44:20 +00:00
|
|
|
this._delay( function() {
|
2014-06-18 00:31:31 +00:00
|
|
|
this.open( event );
|
2014-06-05 00:39:46 +00:00
|
|
|
});
|
2009-12-15 04:00:17 +00:00
|
|
|
}
|
2014-06-05 00:39:46 +00:00
|
|
|
this._delay( function() {
|
2014-06-18 00:31:31 +00:00
|
|
|
this.suppressExpandOnFocus = false;
|
2014-06-05 00:39:46 +00:00
|
|
|
}, 100 );
|
|
|
|
},
|
|
|
|
blur: function() {
|
2014-06-18 00:31:31 +00:00
|
|
|
this.suppressExpandOnFocus = false;
|
2014-06-05 00:39:46 +00:00
|
|
|
}
|
|
|
|
},
|
2014-05-15 22:19:32 +00:00
|
|
|
|
2014-06-05 00:39:46 +00:00
|
|
|
_calendarEvents: {
|
|
|
|
focusout: function( event ) {
|
|
|
|
// use a timer to allow click to clear it and letting that
|
|
|
|
// handle the closing instead of opening again
|
|
|
|
// also allows tabbing inside the calendar without it closing
|
|
|
|
this.closeTimer = this._delay( function() {
|
|
|
|
this.close( event );
|
|
|
|
}, 150 );
|
|
|
|
},
|
|
|
|
focusin: function() {
|
|
|
|
clearTimeout( this.closeTimer );
|
|
|
|
},
|
|
|
|
mouseup: function() {
|
|
|
|
clearTimeout( this.closeTimer );
|
|
|
|
},
|
|
|
|
// TODO on TAB (or shift TAB), make sure it ends up on something useful in DOM order
|
|
|
|
keyup: function( event ) {
|
|
|
|
if ( event.keyCode === $.ui.keyCode.ESCAPE && this.calendar.is( ":visible" ) ) {
|
|
|
|
this.close( event );
|
|
|
|
this._focusTrigger();
|
2012-11-18 20:01:30 +00:00
|
|
|
}
|
2014-06-05 00:39:46 +00:00
|
|
|
}
|
|
|
|
},
|
2012-11-18 20:01:30 +00:00
|
|
|
|
2014-06-05 00:39:46 +00:00
|
|
|
_documentEvents: {
|
2014-06-17 14:25:24 +00:00
|
|
|
mousedown: function( event ) {
|
|
|
|
if ( !this.isOpen ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !$( event.target ).closest( this.element.add( this.calendar ) ).length ) {
|
2014-06-05 00:39:46 +00:00
|
|
|
this.close( event );
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
2014-06-05 00:39:46 +00:00
|
|
|
}
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2014-04-23 15:49:03 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
_appendTo: function() {
|
|
|
|
var element = this.options.appendTo;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
if ( element ) {
|
|
|
|
element = element.jquery || element.nodeType ?
|
|
|
|
$( element ) :
|
|
|
|
this.document.find( element ).eq( 0 );
|
2012-11-18 20:01:30 +00:00
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2014-06-03 21:18:51 +00:00
|
|
|
if ( !element || !element[ 0 ] ) {
|
2013-08-26 10:44:20 +00:00
|
|
|
element = this.element.closest( ".ui-front" );
|
2008-12-22 19:18:15 +00:00
|
|
|
}
|
2012-11-18 20:01:30 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
if ( !element.length ) {
|
2014-04-23 15:49:03 +00:00
|
|
|
element = this.document[ 0 ].body;
|
2008-07-06 05:31:06 +00:00
|
|
|
}
|
2012-11-18 20:01:30 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
return element;
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2014-05-15 22:19:32 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
_focusTrigger: function() {
|
2014-06-18 00:31:31 +00:00
|
|
|
this.suppressExpandOnFocus = true;
|
2013-08-26 10:44:20 +00:00
|
|
|
this.element.focus();
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2014-04-23 15:49:03 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
refresh: function() {
|
2014-06-03 21:18:51 +00:00
|
|
|
this.calendarInstance.option( "value", this._getParsedValue() );
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2014-04-23 15:49:03 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
open: function( event ) {
|
2014-06-03 21:18:51 +00:00
|
|
|
if ( this.isOpen ) {
|
2013-08-26 10:44:20 +00:00
|
|
|
return;
|
2012-11-18 20:01:30 +00:00
|
|
|
}
|
2013-08-30 12:27:19 +00:00
|
|
|
if ( this._trigger( "beforeOpen", event ) === false ) {
|
|
|
|
return;
|
|
|
|
}
|
2012-11-18 20:01:30 +00:00
|
|
|
|
2014-06-03 21:18:51 +00:00
|
|
|
this.calendarInstance.refresh();
|
|
|
|
this.calendar
|
2014-06-18 00:31:31 +00:00
|
|
|
.attr({
|
|
|
|
"aria-hidden": false,
|
|
|
|
"aria-expanded": true
|
|
|
|
})
|
2013-08-26 10:44:20 +00:00
|
|
|
.show()
|
2013-11-18 14:23:15 +00:00
|
|
|
.position( this._buildPosition() )
|
2013-08-26 10:44:20 +00:00
|
|
|
.hide();
|
2014-06-03 21:18:51 +00:00
|
|
|
this._show( this.calendar, this.options.show );
|
2012-11-18 20:01:30 +00:00
|
|
|
|
2014-05-15 22:19:32 +00:00
|
|
|
// Take trigger out of tab order to allow shift-tab to skip trigger
|
|
|
|
// TODO Does this really make sense? related bug: tab-shift moves focus to last element on page
|
2013-08-26 10:44:20 +00:00
|
|
|
this.element.attr( "tabindex", -1 );
|
|
|
|
this.isOpen = true;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
this._trigger( "open", event );
|
2009-04-10 08:04:57 +00:00
|
|
|
},
|
2014-04-23 15:49:03 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
close: function( event ) {
|
|
|
|
this._setHiddenPicker();
|
2014-06-03 21:18:51 +00:00
|
|
|
this._hide( this.calendar, this.options.hide );
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
this.element.attr( "tabindex" , 0 );
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
this.isOpen = false;
|
|
|
|
this._trigger( "close", event );
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2014-04-23 15:49:03 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
_setHiddenPicker: function() {
|
2014-06-18 00:31:31 +00:00
|
|
|
this.calendar.attr({
|
|
|
|
"aria-hidden": true,
|
|
|
|
"aria-expanded": false
|
|
|
|
});
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2014-04-23 15:49:03 +00:00
|
|
|
|
2013-11-18 14:23:15 +00:00
|
|
|
_buildPosition: function() {
|
2014-05-15 22:19:32 +00:00
|
|
|
return $.extend( { of: this.element }, this.options.position );
|
2013-11-18 14:23:15 +00:00
|
|
|
},
|
2014-04-23 15:49:03 +00:00
|
|
|
|
2013-11-21 14:03:08 +00:00
|
|
|
value: function( value ) {
|
|
|
|
if ( arguments.length ) {
|
2014-06-04 17:07:23 +00:00
|
|
|
this.valueAsDate( Globalize.parseDate( value , this.options.dateFormat ) );
|
2014-06-03 21:18:51 +00:00
|
|
|
} else {
|
|
|
|
return this._getParsedValue() ? this.element.val() : null;
|
2013-11-21 14:03:08 +00:00
|
|
|
}
|
|
|
|
},
|
2014-04-23 15:49:03 +00:00
|
|
|
|
2013-11-21 14:03:08 +00:00
|
|
|
valueAsDate: function( value ) {
|
|
|
|
if ( arguments.length ) {
|
2014-06-04 17:07:23 +00:00
|
|
|
if ( this.calendarInstance._isValid( value ) ) {
|
2014-06-03 21:18:51 +00:00
|
|
|
this.calendarInstance.valueAsDate( value );
|
|
|
|
this.element.val( Globalize.format( value, this.options.dateFormat ) );
|
|
|
|
}
|
2013-11-21 14:03:08 +00:00
|
|
|
} else {
|
2014-06-03 21:18:51 +00:00
|
|
|
return this._getParsedValue();
|
2013-11-21 14:03:08 +00:00
|
|
|
}
|
|
|
|
},
|
2014-04-23 15:49:03 +00:00
|
|
|
|
2014-01-03 14:07:38 +00:00
|
|
|
isValid: function() {
|
2014-06-04 17:07:23 +00:00
|
|
|
return this.calendarInstance._isValid( this._getParsedValue() );
|
2014-01-03 14:07:38 +00:00
|
|
|
},
|
2014-04-23 15:49:03 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
_destroy: function() {
|
2014-06-03 21:18:51 +00:00
|
|
|
this.calendarInstance.destroy();
|
|
|
|
this.calendar.remove();
|
2014-06-18 00:31:31 +00:00
|
|
|
this.element.removeAttr( "aria-haspopup aria-owns" );
|
2013-08-26 10:44:20 +00:00
|
|
|
},
|
2014-04-23 15:49:03 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
widget: function() {
|
2014-06-03 21:18:51 +00:00
|
|
|
return this.calendar;
|
2013-11-15 13:42:20 +00:00
|
|
|
},
|
2014-04-23 15:49:03 +00:00
|
|
|
|
2014-05-15 22:19:32 +00:00
|
|
|
_getParsedValue: function() {
|
|
|
|
return Globalize.parseDate( this.element.val(), this.options.dateFormat );
|
|
|
|
},
|
|
|
|
|
2013-11-15 13:42:20 +00:00
|
|
|
_setOption: function( key, value ) {
|
|
|
|
this._super( key, value );
|
|
|
|
|
2014-06-12 12:36:45 +00:00
|
|
|
if ( $.inArray( key, calendarOptions ) !== -1 ) {
|
2014-06-03 21:18:51 +00:00
|
|
|
this.calendarInstance.option( key, value );
|
2013-11-15 13:42:20 +00:00
|
|
|
}
|
2013-11-15 14:17:13 +00:00
|
|
|
|
2014-06-03 21:18:51 +00:00
|
|
|
if ( key === "appendTo" ) {
|
|
|
|
this.calendar.appendTo( this._appendTo() );
|
2013-11-19 13:35:19 +00:00
|
|
|
}
|
|
|
|
|
2013-11-20 13:37:24 +00:00
|
|
|
if ( key === "dateFormat" ) {
|
2014-06-03 21:18:51 +00:00
|
|
|
this.element.val( this.calendarInstance.value() );
|
2013-11-15 14:17:13 +00:00
|
|
|
}
|
2013-11-18 14:23:15 +00:00
|
|
|
|
2014-09-01 13:36:38 +00:00
|
|
|
if ( key === "disabled" ) {
|
|
|
|
this.element
|
|
|
|
.prop( "disabled", value )
|
|
|
|
.toggleClass( "ui-state-disabled", value )
|
|
|
|
.attr( "aria-disabled", value );
|
|
|
|
|
|
|
|
if ( value ) {
|
|
|
|
this.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-18 14:23:15 +00:00
|
|
|
if ( key === "position" ) {
|
2014-06-03 21:18:51 +00:00
|
|
|
this.calendar.position( this._buildPosition() );
|
2013-11-18 14:23:15 +00:00
|
|
|
}
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
|
|
|
});
|
2014-06-18 00:31:31 +00:00
|
|
|
|
2014-06-12 12:36:45 +00:00
|
|
|
$.each( calendarOptions, function( index, option ) {
|
|
|
|
$.ui.datepicker.prototype.options[ option ] = $.ui.calendar.prototype.options[ option ];
|
|
|
|
});
|
|
|
|
|
|
|
|
return widget;
|
|
|
|
|
2013-07-12 16:40:48 +00:00
|
|
|
}));
|