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-03 21:18:51 +00:00
|
|
|
// TODO Use uniqueId, if possible
|
2013-08-26 10:44:20 +00:00
|
|
|
var idIncrement = 0,
|
2014-05-15 22:19:32 +00:00
|
|
|
// TODO Move this to the instance
|
2013-08-26 10:44:20 +00:00
|
|
|
suppressExpandOnFocus = false;
|
|
|
|
|
|
|
|
$.widget( "ui.datepicker", {
|
2014-06-03 21:18:51 +00:00
|
|
|
version: "@VERSION",
|
2013-08-26 10:44:20 +00:00
|
|
|
options: {
|
|
|
|
appendTo: null,
|
2014-04-26 12:44:31 +00:00
|
|
|
dateFormat: { date: "short" },
|
2014-05-15 22:19:32 +00:00
|
|
|
// TODO Review
|
2013-08-26 10:44:20 +00:00
|
|
|
eachDay: $.noop,
|
2014-06-04 17:07:23 +00:00
|
|
|
max: null,
|
|
|
|
min: null,
|
2013-08-26 10:44:20 +00:00
|
|
|
numberOfMonths: 1,
|
|
|
|
position: {
|
|
|
|
my: "left top",
|
|
|
|
at: "left bottom"
|
|
|
|
},
|
|
|
|
showWeek: false,
|
|
|
|
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-03 21:18:51 +00:00
|
|
|
this._createCalendar();
|
|
|
|
},
|
|
|
|
|
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
|
|
|
|
.calendar({
|
|
|
|
dateFormat: this.options.dateFormat,
|
|
|
|
eachDay: this.options.eachDay,
|
2014-06-04 17:07:23 +00:00
|
|
|
max: this.options.max,
|
|
|
|
min: this.options.min,
|
2014-06-03 21:18:51 +00:00
|
|
|
numberOfMonths: this.options.numberOfMonths,
|
|
|
|
showWeek: this.options.showWeek,
|
|
|
|
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-03 21:18:51 +00:00
|
|
|
})
|
|
|
|
.calendar( "instance" );
|
2014-05-15 22:19:32 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
this._setHiddenPicker();
|
|
|
|
|
|
|
|
this.element
|
|
|
|
.attr( "aria-haspopup", "true" )
|
2014-06-03 21:18:51 +00:00
|
|
|
.attr( "aria-owns", this.calendar.attr( "id" ) );
|
2013-08-26 10:44:20 +00:00
|
|
|
|
|
|
|
this._on({
|
|
|
|
keydown: function( event ) {
|
|
|
|
switch ( event.keyCode ) {
|
|
|
|
case $.ui.keyCode.TAB:
|
2014-05-15 22:19:32 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
// Waiting for close() will make popup hide too late, which breaks tab key behavior
|
2014-06-03 21:18:51 +00:00
|
|
|
this.calendar.hide();
|
2013-08-26 10:44:20 +00:00
|
|
|
this.close( event );
|
2008-11-20 04:10:34 +00:00
|
|
|
break;
|
2013-08-26 10:44:20 +00:00
|
|
|
case $.ui.keyCode.ESCAPE:
|
|
|
|
if ( this.isOpen ) {
|
|
|
|
this.close( event );
|
2012-11-18 20:01:30 +00:00
|
|
|
}
|
2008-11-20 04:10:34 +00:00
|
|
|
break;
|
2013-11-22 14:30:11 +00:00
|
|
|
case $.ui.keyCode.ENTER:
|
2014-06-03 21:18:51 +00:00
|
|
|
this.calendarInstance._handleKeydown( event );
|
2013-11-22 14:30:11 +00:00
|
|
|
break;
|
2013-08-26 10:44:20 +00:00
|
|
|
case $.ui.keyCode.DOWN:
|
|
|
|
case $.ui.keyCode.UP:
|
|
|
|
clearTimeout( this.closeTimer );
|
2014-04-23 15:49:03 +00:00
|
|
|
this._delay( function() {
|
2013-08-26 10:44:20 +00:00
|
|
|
this.open( event );
|
2014-06-03 21:18:51 +00:00
|
|
|
this.calendarInstance.grid.focus();
|
2014-04-23 15:49:03 +00:00
|
|
|
}, 1 );
|
2013-08-26 10:44:20 +00:00
|
|
|
break;
|
2013-11-22 14:30:11 +00:00
|
|
|
case $.ui.keyCode.HOME:
|
|
|
|
if ( event.ctrlKey ) {
|
2014-06-03 21:18:51 +00:00
|
|
|
this.valueAsDate( new Date() );
|
2013-11-22 14:30:11 +00:00
|
|
|
event.preventDefault();
|
|
|
|
if ( this.isOpen ) {
|
2014-06-03 21:18:51 +00:00
|
|
|
this.calendarInstance.refresh();
|
2013-11-22 14:30:11 +00:00
|
|
|
} else {
|
|
|
|
this.open( event );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case $.ui.keyCode.END:
|
|
|
|
if ( event.ctrlKey ) {
|
|
|
|
this.element.val( "" );
|
|
|
|
event.preventDefault();
|
|
|
|
if ( this.isOpen ) {
|
|
|
|
this.close( event );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2013-08-26 10:44:20 +00:00
|
|
|
}
|
|
|
|
},
|
2014-01-03 14:55:06 +00:00
|
|
|
keyup: function() {
|
2014-06-03 21:18:51 +00:00
|
|
|
if ( this.isValid() ) {
|
2014-01-03 14:55:06 +00:00
|
|
|
this.refresh();
|
|
|
|
}
|
|
|
|
},
|
2013-08-26 10:44:20 +00:00
|
|
|
mousedown: function( event ) {
|
2014-05-15 22:19:32 +00:00
|
|
|
if ( this.isOpen ) {
|
2013-08-26 10:44:20 +00:00
|
|
|
suppressExpandOnFocus = true;
|
|
|
|
this.close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.open( event );
|
|
|
|
clearTimeout( this.closeTimer );
|
|
|
|
},
|
|
|
|
focus: function( event ) {
|
|
|
|
if ( !suppressExpandOnFocus ) {
|
|
|
|
this._delay( function() {
|
|
|
|
if ( !this.isOpen ) {
|
|
|
|
this.open( event );
|
2012-11-18 20:01:30 +00:00
|
|
|
}
|
2013-08-26 10:44:20 +00:00
|
|
|
}, 1);
|
2009-12-15 04:00:17 +00:00
|
|
|
}
|
2013-08-26 10:44:20 +00:00
|
|
|
this._delay( function() {
|
|
|
|
suppressExpandOnFocus = false;
|
2014-04-23 15:49:03 +00:00
|
|
|
}, 100 );
|
2013-08-26 10:44:20 +00:00
|
|
|
},
|
|
|
|
blur: function() {
|
|
|
|
suppressExpandOnFocus = false;
|
2009-12-15 04:00:17 +00:00
|
|
|
}
|
2008-06-04 02:34:33 +00:00
|
|
|
});
|
2012-11-18 20:01:30 +00:00
|
|
|
|
2014-06-03 21:18:51 +00:00
|
|
|
this._on( this.calendar, {
|
2013-08-26 10:44:20 +00:00
|
|
|
focusout: function( event ) {
|
2014-05-15 22:19:32 +00:00
|
|
|
|
|
|
|
// Use a timer to allow click to clear it and letting that
|
2013-08-26 10:44:20 +00:00
|
|
|
// handle the closing instead of opening again
|
|
|
|
// also allows tabbing inside the calendar without it closing
|
|
|
|
this.closeTimer = this._delay( function() {
|
|
|
|
this.close( event );
|
2014-04-23 15:49:03 +00:00
|
|
|
}, 150 );
|
2013-08-26 10:44:20 +00:00
|
|
|
},
|
|
|
|
focusin: function() {
|
|
|
|
clearTimeout( this.closeTimer );
|
|
|
|
},
|
|
|
|
mouseup: function() {
|
|
|
|
clearTimeout( this.closeTimer );
|
|
|
|
},
|
2014-05-15 22:19:32 +00:00
|
|
|
|
|
|
|
// TODO On TAB (or shift TAB), make sure it ends up on something useful in DOM order
|
2013-08-26 10:44:20 +00:00
|
|
|
keyup: function( event ) {
|
2014-06-03 21:18:51 +00:00
|
|
|
if ( event.keyCode === $.ui.keyCode.ESCAPE && this.calendar.is( ":visible" ) ) {
|
2013-08-26 10:44:20 +00:00
|
|
|
this.close( event );
|
|
|
|
this._focusTrigger();
|
2010-11-05 14:25:06 +00:00
|
|
|
}
|
2012-11-18 20:01:30 +00:00
|
|
|
}
|
2013-08-26 10:44:20 +00:00
|
|
|
});
|
2012-11-18 20:01:30 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
this._on( this.document, {
|
|
|
|
click: function( event ) {
|
2014-06-03 21:18:51 +00:00
|
|
|
if ( this.isOpen && !$( event.target ).closest( this.element.add( this.calendar ) ).length ) {
|
2013-08-26 10:44:20 +00:00
|
|
|
this.close( event );
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-26 10:44:20 +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() {
|
|
|
|
suppressExpandOnFocus = true;
|
|
|
|
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();
|
2012-10-22 01:50:03 +00:00
|
|
|
|
2014-06-03 21:18:51 +00:00
|
|
|
this.calendar
|
2013-08-26 10:44:20 +00:00
|
|
|
.attr( "aria-hidden", "false" )
|
|
|
|
.attr( "aria-expanded", "true" )
|
|
|
|
.show()
|
2013-11-18 14:23:15 +00:00
|
|
|
.position( this._buildPosition() )
|
2013-08-26 10:44:20 +00:00
|
|
|
.hide();
|
2008-11-18 02:55:25 +00:00
|
|
|
|
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-03 21:18:51 +00:00
|
|
|
this.calendar
|
2013-08-26 10:44:20 +00:00
|
|
|
.attr( "aria-hidden", "true" )
|
|
|
|
.attr( "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();
|
|
|
|
this.element
|
|
|
|
.removeAttr( "aria-haspopup" )
|
|
|
|
.removeAttr( "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-03 21:18:51 +00:00
|
|
|
if ( $.inArray( key, [ "showWeek", "numberOfMonths", "dateFormat", "eachDay", "min", "max" ] ) !== -1 ) {
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
});
|
2013-07-12 16:40:48 +00:00
|
|
|
}));
|