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",
|
|
|
|
"./button",
|
|
|
|
"./position"
|
2013-07-12 16:40:48 +00:00
|
|
|
], factory );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Browser globals
|
|
|
|
factory( jQuery );
|
|
|
|
}
|
|
|
|
}(function( $ ) {
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
// TODO use uniqueId, if possible
|
|
|
|
var idIncrement = 0,
|
|
|
|
// TODO move this to the instance
|
|
|
|
suppressExpandOnFocus = false;
|
|
|
|
|
|
|
|
$.widget( "ui.datepicker", {
|
|
|
|
options: {
|
|
|
|
appendTo: null,
|
2013-08-30 12:27:19 +00:00
|
|
|
dateFormat: null,
|
2013-08-26 10:44:20 +00:00
|
|
|
// TODO review
|
|
|
|
eachDay: $.noop,
|
|
|
|
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
|
|
|
|
},
|
|
|
|
_create: function() {
|
2013-11-30 12:22:17 +00:00
|
|
|
this.options.dateFormat = this.options.dateFormat || { date: "short" };
|
2013-08-30 12:27:19 +00:00
|
|
|
this.date = $.date( null, this.options.dateFormat );
|
2013-11-22 14:30:11 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
this.date.eachDay = this.options.eachDay;
|
|
|
|
this.id = "ui-datepicker-" + idIncrement;
|
|
|
|
idIncrement++;
|
|
|
|
if ( this.element.is( "input" ) ) {
|
|
|
|
this._createPicker();
|
|
|
|
} else {
|
|
|
|
this.inline = true;
|
|
|
|
this.picker = this.element;
|
|
|
|
}
|
|
|
|
this._on( this.picker, {
|
|
|
|
"click .ui-datepicker-prev": function( event ) {
|
|
|
|
event.preventDefault();
|
|
|
|
this.date.adjust( "M", -this.options.numberOfMonths );
|
|
|
|
this.refresh();
|
|
|
|
},
|
|
|
|
"click .ui-datepicker-next": function( event ) {
|
|
|
|
event.preventDefault();
|
|
|
|
this.date.adjust( "M", this.options.numberOfMonths );
|
|
|
|
this.refresh();
|
|
|
|
},
|
|
|
|
"click .ui-datepicker-current": function( event ) {
|
|
|
|
event.preventDefault();
|
|
|
|
this.select( event, new Date().getTime() );
|
|
|
|
},
|
|
|
|
"click .ui-datepicker-close": function( event ) {
|
|
|
|
event.preventDefault();
|
|
|
|
this.close( event );
|
|
|
|
},
|
|
|
|
"mousedown .ui-datepicker-calendar a": function( event ) {
|
|
|
|
event.preventDefault();
|
|
|
|
// TODO exclude clicks on lead days or handle them correctly
|
|
|
|
// TODO store/read more then just date, also required for multi month picker
|
|
|
|
this.select( event, $( event.currentTarget ).data( "timestamp" ) );
|
|
|
|
if ( this.inline ) {
|
2015-01-29 22:47:40 +00:00
|
|
|
this.grid.focus();
|
2012-11-18 20:01:30 +00:00
|
|
|
}
|
2013-08-26 10:44:20 +00:00
|
|
|
},
|
|
|
|
"keydown .ui-datepicker-calendar": "_handleKeydown"
|
|
|
|
});
|
2012-11-18 20:01:30 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
// TODO use hoverable (no delegation support)? convert to _on?
|
|
|
|
this.picker.delegate( ".ui-datepicker-header a, .ui-datepicker-calendar a", "mouseenter.datepicker mouseleave.datepicker", function() {
|
|
|
|
$( this ).toggleClass( "ui-state-hover" );
|
|
|
|
});
|
2012-11-18 20:01:30 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
this._createTmpl();
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
_handleKeydown: function( event ) {
|
|
|
|
if ( jQuery.inArray( event.keyCode, [ 13, 33, 34, 35, 36, 37, 38, 39, 40 ] ) === -1 ) {
|
|
|
|
//only interested navigation keys
|
2008-07-23 10:39:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-08-26 10:44:20 +00:00
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
var newId, newCell,
|
|
|
|
activeCell = $( "#" + this.grid.attr( "aria-activedescendant" ) ),
|
|
|
|
oldMonth = this.date.month(),
|
|
|
|
oldYear = this.date.year();
|
|
|
|
|
|
|
|
// TODO: Handle for pickers with multiple months
|
|
|
|
switch ( event.keyCode ) {
|
|
|
|
case $.ui.keyCode.ENTER:
|
|
|
|
activeCell.children( "a:first" ).mousedown();
|
|
|
|
return;
|
|
|
|
case $.ui.keyCode.PAGE_UP:
|
2013-12-27 13:28:00 +00:00
|
|
|
this.date.adjust( event.altKey ? "Y" : "M", -1 );
|
2013-08-26 10:44:20 +00:00
|
|
|
break;
|
|
|
|
case $.ui.keyCode.PAGE_DOWN:
|
2013-12-27 13:28:00 +00:00
|
|
|
this.date.adjust( event.altKey ? "Y" : "M", 1 );
|
2013-08-26 10:44:20 +00:00
|
|
|
break;
|
|
|
|
case $.ui.keyCode.END:
|
|
|
|
this.date.setDay( this.date.daysInMonth() );
|
|
|
|
break;
|
|
|
|
case $.ui.keyCode.HOME:
|
|
|
|
this.date.setDay( 1 );
|
|
|
|
break;
|
|
|
|
case $.ui.keyCode.LEFT:
|
|
|
|
this.date.adjust( "D", -1 );
|
|
|
|
break;
|
|
|
|
case $.ui.keyCode.UP:
|
|
|
|
this.date.adjust( "D", -7 );
|
|
|
|
break;
|
|
|
|
case $.ui.keyCode.RIGHT:
|
|
|
|
this.date.adjust( "D", 1 );
|
|
|
|
break;
|
|
|
|
case $.ui.keyCode.DOWN:
|
|
|
|
this.date.adjust( "D", 7 );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( this.date.month() !== oldMonth || this.date.year() !== oldYear ) {
|
|
|
|
this.refresh();
|
2015-01-29 22:47:40 +00:00
|
|
|
this.grid.focus();
|
2013-08-26 10:44:20 +00:00
|
|
|
} else {
|
|
|
|
newId = this.id + "-" + this.date.day();
|
|
|
|
newCell = $( "#" + newId );
|
2012-11-18 20:01:30 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
// TODO unnecessary optimization? is it really needed?
|
|
|
|
if ( !newCell.length ) {
|
|
|
|
return;
|
2012-11-18 20:01:30 +00:00
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
this.grid.attr("aria-activedescendant", newId);
|
|
|
|
|
2013-10-30 13:11:06 +00:00
|
|
|
this.grid.find( ".ui-state-focus" ).removeClass( "ui-state-focus" );
|
|
|
|
newCell.children( "a" ).addClass( "ui-state-focus" );
|
2013-08-26 10:44:20 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
_createPicker: function() {
|
|
|
|
this.picker = $( "<div>" )
|
|
|
|
.addClass( "ui-front" )
|
|
|
|
// TODO add a ui-datepicker-popup class, move position:absolte to that
|
|
|
|
.css( "position", "absolute" )
|
|
|
|
.uniqueId()
|
|
|
|
.hide();
|
|
|
|
this._setHiddenPicker();
|
|
|
|
this.picker.appendTo( this._appendTo() );
|
|
|
|
|
|
|
|
this.element
|
|
|
|
.attr( "aria-haspopup", "true" )
|
|
|
|
.attr( "aria-owns", this.picker.attr( "id" ) );
|
|
|
|
|
|
|
|
this._on({
|
|
|
|
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.picker.hide();
|
|
|
|
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:
|
|
|
|
this._handleKeydown( event );
|
|
|
|
break;
|
2013-08-26 10:44:20 +00:00
|
|
|
case $.ui.keyCode.DOWN:
|
|
|
|
case $.ui.keyCode.UP:
|
|
|
|
clearTimeout( this.closeTimer );
|
|
|
|
this._delay(function() {
|
|
|
|
this.open( event );
|
2015-01-29 22:47:40 +00:00
|
|
|
this.grid.focus();
|
2013-08-26 10:44:20 +00:00
|
|
|
}, 1);
|
|
|
|
break;
|
2013-11-22 14:30:11 +00:00
|
|
|
case $.ui.keyCode.HOME:
|
|
|
|
if ( event.ctrlKey ) {
|
|
|
|
this.date.setTime( new Date() );
|
|
|
|
event.preventDefault();
|
|
|
|
if ( this.isOpen ) {
|
|
|
|
this.refresh();
|
|
|
|
} 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
|
|
|
}
|
|
|
|
},
|
|
|
|
mousedown: function( event ) {
|
|
|
|
if (this.isOpen) {
|
|
|
|
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;
|
|
|
|
}, 100);
|
|
|
|
},
|
|
|
|
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
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
this._on( this.picker, {
|
|
|
|
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.picker.is( ":visible" ) ) {
|
|
|
|
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 ) {
|
|
|
|
if ( this.isOpen && !$( event.target ).closest( this.element.add( this.picker ) ).length ) {
|
|
|
|
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
|
|
|
},
|
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
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
if ( !element ) {
|
|
|
|
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 ) {
|
|
|
|
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
|
|
|
},
|
2013-08-26 10:44:20 +00:00
|
|
|
_createTmpl: function() {
|
|
|
|
this._createDatepicker();
|
|
|
|
this.picker.find( "button" ).button();
|
2012-11-18 20:01:30 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
if ( this.inline ) {
|
|
|
|
this.picker.children().addClass( "ui-datepicker-inline" );
|
2008-12-22 19:18:15 +00:00
|
|
|
}
|
2013-08-26 10:44:20 +00:00
|
|
|
// against display:none in datepicker.css
|
|
|
|
this.picker.find( ".ui-datepicker" ).css( "display", "block" );
|
|
|
|
this.grid = this.picker.find( ".ui-datepicker-calendar" );
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2013-08-26 10:44:20 +00:00
|
|
|
_createDatepicker: function() {
|
|
|
|
var multiClasses = [],
|
|
|
|
pickerHtml = "";
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
if (this.options.numberOfMonths === 1 ) {
|
|
|
|
pickerHtml = this._buildHeader() + this._buildGrid() + this._buildButtons();
|
2012-11-18 20:01:30 +00:00
|
|
|
} else {
|
2013-08-26 10:44:20 +00:00
|
|
|
pickerHtml = this._buildMultiplePicker();
|
|
|
|
multiClasses.push( "ui-datepicker-multi" );
|
|
|
|
multiClasses.push( "ui-datepicker-multi-" + this.options.numberOfMonths );
|
|
|
|
}
|
|
|
|
|
|
|
|
$( "<div>" )
|
|
|
|
.addClass( "ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" )
|
|
|
|
.addClass( multiClasses.join( " " ) )
|
|
|
|
.attr({
|
|
|
|
role: "region",
|
|
|
|
"aria-labelledby": this.id + "-title"
|
|
|
|
})
|
|
|
|
.html( pickerHtml )
|
|
|
|
.appendTo( this.picker );
|
|
|
|
},
|
|
|
|
_buildMultiplePicker: function() {
|
|
|
|
var headerClass,
|
|
|
|
html = "",
|
|
|
|
currentDate = this.date,
|
|
|
|
months = this.date.months( this.options.numberOfMonths - 1 ),
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
for ( i; i < months.length; i++ ) {
|
2013-11-30 12:22:17 +00:00
|
|
|
// TODO Shouldn't we pass date as a parameter to build* fns instead of setting this.date?
|
2013-08-26 10:44:20 +00:00
|
|
|
this.date = months[ i ];
|
|
|
|
headerClass = months[ i ].first ? "ui-corner-left" :
|
|
|
|
months[ i ].last ? "ui-corner-right" : "";
|
|
|
|
|
|
|
|
html += "<div class='ui-datepicker-group'>" +
|
|
|
|
"<div class='ui-datepicker-header ui-widget-header ui-helper-clearfix " + headerClass + "'>";
|
|
|
|
if ( months[i].first ) {
|
|
|
|
html += this._buildPreviousLink();
|
|
|
|
}
|
|
|
|
if ( months[i].last ) {
|
|
|
|
html += this._buildNextLink();
|
2012-11-18 20:01:30 +00:00
|
|
|
}
|
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
html += this._buildTitlebar();
|
|
|
|
html += "</div>";
|
|
|
|
html += this._buildGrid();
|
|
|
|
html += "</div>";
|
2008-06-21 23:51:34 +00:00
|
|
|
}
|
2012-11-18 20:01:30 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
html += "<div class='ui-datepicker-row-break'></div>";
|
|
|
|
html += this._buildButtons();
|
2012-11-18 20:01:30 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
this.date = currentDate;
|
|
|
|
return html;
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2013-08-26 10:44:20 +00:00
|
|
|
_buildHeader: function() {
|
|
|
|
return "<div class='ui-datepicker-header ui-widget-header ui-helper-clearfix ui-corner-all'>" +
|
|
|
|
this._buildPreviousLink() +
|
|
|
|
this._buildNextLink() +
|
|
|
|
this._buildTitlebar() +
|
|
|
|
"</div>";
|
|
|
|
},
|
|
|
|
_buildPreviousLink: function() {
|
2013-11-30 12:22:17 +00:00
|
|
|
var labels = Globalize.translate( "datepicker" );
|
2013-08-26 10:44:20 +00:00
|
|
|
return "<button class='ui-datepicker-prev ui-corner-all' " +
|
|
|
|
"title='" + labels.prevText + "'>" +
|
|
|
|
"<span class='ui-icon ui-icon-circle-triangle-w'>" +
|
|
|
|
labels.prevText +
|
|
|
|
"</span>" +
|
|
|
|
"</button>";
|
|
|
|
},
|
|
|
|
_buildNextLink: function() {
|
2013-11-30 12:22:17 +00:00
|
|
|
var labels = Globalize.translate( "datepicker" );
|
2013-08-26 10:44:20 +00:00
|
|
|
return "<button class='ui-datepicker-next ui-corner-all' " +
|
|
|
|
"title='" + labels.nextText + "'>" +
|
|
|
|
"<span class='ui-icon ui-icon-circle-triangle-e'>" +
|
|
|
|
labels.nextText +
|
|
|
|
"</span>" +
|
|
|
|
"</button>";
|
|
|
|
},
|
|
|
|
_buildTitlebar: function() {
|
2013-11-30 12:22:17 +00:00
|
|
|
var labels = Globalize.translate( "datepicker" );
|
2013-08-26 10:44:20 +00:00
|
|
|
return "<div role='header' id='" + this.id + "-title'>" +
|
|
|
|
"<div id='" + this.id + "-month-lbl' class='ui-datepicker-title'>" +
|
|
|
|
this._buildTitle() +
|
|
|
|
"</div>" +
|
|
|
|
"<span class='ui-helper-hidden-accessible'>, " + labels.datePickerRole + "</span>" +
|
|
|
|
"</div>";
|
|
|
|
},
|
|
|
|
_buildTitle: function() {
|
|
|
|
return "<span class='ui-datepicker-month'>" +
|
|
|
|
this.date.monthName() +
|
|
|
|
"</span> " +
|
|
|
|
"<span class='ui-datepicker-year'>" +
|
|
|
|
this.date.year() +
|
|
|
|
"</span>";
|
|
|
|
},
|
|
|
|
_buildGrid: function() {
|
|
|
|
return "<table class='ui-datepicker-calendar' role='grid' aria-readonly='true' " +
|
|
|
|
"aria-labelledby='" + this.id + "-month-lbl' tabindex='0' aria-activedescendant='" + this.id + "-" + this.date.day() + "'>" +
|
|
|
|
this._buildGridHeading() +
|
|
|
|
this._buildGridBody() +
|
|
|
|
"</table>";
|
|
|
|
},
|
|
|
|
_buildGridHeading: function() {
|
|
|
|
var cells = "",
|
|
|
|
i = 0,
|
2013-11-30 12:22:17 +00:00
|
|
|
labels = Globalize.translate( "datepicker" );
|
2013-08-26 10:44:20 +00:00
|
|
|
|
|
|
|
if ( this.options.showWeek ) {
|
2013-11-15 14:17:13 +00:00
|
|
|
cells += "<th class='ui-datepicker-week-col'>" + labels.weekHeader + "</th>";
|
2013-08-26 10:44:20 +00:00
|
|
|
}
|
|
|
|
for ( i; i < this.date.weekdays().length; i++ ) {
|
|
|
|
cells += this._buildGridHeaderCell( this.date.weekdays()[i] );
|
|
|
|
}
|
|
|
|
return "<thead role='presentation'>" +
|
|
|
|
"<tr role='row'>" + cells + "</tr>" +
|
|
|
|
"</thead>";
|
|
|
|
},
|
|
|
|
_buildGridHeaderCell: function( day ) {
|
|
|
|
return "<th role='columnheader' abbr='" + day.fullname + "' aria-label='" + day.fullname + "'>" +
|
|
|
|
"<span title='" + day.fullname + "'>" +
|
|
|
|
day.shortname +
|
|
|
|
"</span>" +
|
|
|
|
"</th>";
|
|
|
|
},
|
|
|
|
_buildGridBody: function() {
|
2013-11-30 12:22:17 +00:00
|
|
|
// this.date.days() is not cached, and it has O(n^2) complexity. It is run O(n) times. So, it equals O(n^3). Not good at all. Caching.
|
|
|
|
var days = this.date.days(),
|
|
|
|
i = 0,
|
|
|
|
rows = "";
|
|
|
|
for ( i; i < days.length; i++ ) {
|
|
|
|
rows += this._buildWeekRow( days[i] );
|
2013-08-26 10:44:20 +00:00
|
|
|
}
|
|
|
|
return "<tbody role='presentation'>" + rows + "</tbody>";
|
|
|
|
},
|
|
|
|
_buildWeekRow: function( week ) {
|
|
|
|
var cells = "",
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
if ( this.options.showWeek ) {
|
2013-11-15 14:17:13 +00:00
|
|
|
cells += "<td class='ui-datepicker-week-col'>" + week.number + "</td>";
|
2013-08-26 10:44:20 +00:00
|
|
|
}
|
|
|
|
for ( i; i < week.days.length; i++ ) {
|
|
|
|
cells += this._buildDayCell( week.days[i] );
|
|
|
|
}
|
|
|
|
return "<tr role='row'>" + cells + "</tr>";
|
|
|
|
},
|
|
|
|
_buildDayCell: function( day ) {
|
|
|
|
var contents = "",
|
|
|
|
idAttribute = day.render ? ( "id=" + this.id + "-" + day.date ) : "",
|
|
|
|
ariaSelectedAttribute = "aria-selected=" + ( day.current ? "true" : "false" ),
|
|
|
|
ariaDisabledAttribute = day.selectable ? "" : "aria-disabled=true";
|
|
|
|
|
|
|
|
if ( day.render ) {
|
|
|
|
if ( day.selectable ) {
|
|
|
|
contents = this._buildDayLink( day );
|
2012-11-18 20:01:30 +00:00
|
|
|
} else {
|
2013-08-26 10:44:20 +00:00
|
|
|
contents = this._buildDayDisplay( day );
|
2012-11-18 20:01:30 +00:00
|
|
|
}
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
2012-11-18 20:01:30 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
return "<td role='gridcell' " + idAttribute + " " + ariaSelectedAttribute + " " + ariaDisabledAttribute + ">" +
|
|
|
|
contents +
|
|
|
|
"</td>";
|
|
|
|
},
|
|
|
|
_buildDayLink: function( day ) {
|
|
|
|
var link,
|
|
|
|
classes = [ "ui-state-default" ],
|
2013-11-30 12:22:17 +00:00
|
|
|
labels = Globalize.translate( "datepicker" );
|
2012-11-18 20:01:30 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
if ( day.date === this.date.day() ) {
|
|
|
|
classes.push( "ui-state-focus" );
|
2012-11-18 20:01:30 +00:00
|
|
|
}
|
2013-08-26 10:44:20 +00:00
|
|
|
if ( day.current ) {
|
|
|
|
classes.push( "ui-state-active" );
|
2008-07-11 10:55:16 +00:00
|
|
|
}
|
2013-08-26 10:44:20 +00:00
|
|
|
if ( day.today ) {
|
|
|
|
classes.push( "ui-state-highlight" );
|
2012-11-18 20:01:30 +00:00
|
|
|
}
|
2013-08-26 10:44:20 +00:00
|
|
|
if ( day.extraClasses ) {
|
2013-09-11 16:19:27 +00:00
|
|
|
classes.push( day.extraClasses.split( " " ) );
|
2012-11-18 20:01:30 +00:00
|
|
|
}
|
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
link = "<a href='#' tabindex='-1' data-timestamp='" + day.timestamp + "' class='" + classes.join( " " ) + "'>" +
|
|
|
|
day.date + "</a>";
|
|
|
|
if ( day.today ) {
|
|
|
|
link += "<span class='ui-helper-hidden-accessible'>, " + labels.currentText + "</span>";
|
2012-11-18 20:01:30 +00:00
|
|
|
}
|
2013-08-26 10:44:20 +00:00
|
|
|
return link;
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2013-08-26 10:44:20 +00:00
|
|
|
_buildDayDisplay: function( day ) {
|
|
|
|
var classes = [];
|
|
|
|
if ( day.current ) {
|
|
|
|
classes.push( "ui-state-active" );
|
2012-11-18 20:01:30 +00:00
|
|
|
}
|
2013-08-26 10:44:20 +00:00
|
|
|
if ( day.today ) {
|
|
|
|
classes.push( "ui-state-highlight" );
|
2010-01-29 08:09:03 +00:00
|
|
|
}
|
2013-08-26 10:44:20 +00:00
|
|
|
if ( day.extraClasses ) {
|
2013-09-11 16:19:27 +00:00
|
|
|
classes.push( day.extraClasses.split( " " ) );
|
2008-12-31 08:22:11 +00:00
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
return "<span class='" + classes.join( "" ) + "'>" +
|
|
|
|
day.date + "</span>";
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2013-08-26 10:44:20 +00:00
|
|
|
_buildButtons: function() {
|
2013-11-30 12:22:17 +00:00
|
|
|
var labels = Globalize.translate( "datepicker" );
|
2013-08-26 10:44:20 +00:00
|
|
|
return "<div class='ui-datepicker-buttonpane ui-widget-content'>" +
|
|
|
|
"<button class='ui-datepicker-current'>" + labels.currentText + "</button>" +
|
|
|
|
"<button class='ui-datepicker-close'>" + labels.closeText + "</button>" +
|
|
|
|
"</div>";
|
2008-11-14 13:28:58 +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
|
|
|
},
|
2013-08-26 10:44:20 +00:00
|
|
|
// Refreshing the entire datepicker during interaction confuses screen readers, specifically
|
2013-08-30 12:27:19 +00:00
|
|
|
// because the grid heading is marked up as a live region and will often not update if it's
|
|
|
|
// destroyed and recreated instead of just having its text change. Additionally, interacting
|
2013-08-26 10:44:20 +00:00
|
|
|
// with the prev and next links would cause loss of focus issues because the links being
|
|
|
|
// interacted with will disappear while focused.
|
|
|
|
refresh: function() {
|
|
|
|
//determine which day gridcell to focus after refresh
|
|
|
|
//TODO: Prevent disabled cells from being focused
|
|
|
|
if ( this.options.numberOfMonths === 1 ) {
|
|
|
|
this.grid = $( this._buildGrid() );
|
|
|
|
$( ".ui-datepicker-title", this.picker ).html( this._buildTitle() );
|
|
|
|
$( ".ui-datepicker-calendar", this.picker ).replaceWith( this.grid );
|
|
|
|
} else {
|
|
|
|
this._refreshMultiplePicker();
|
2008-12-21 17:20:54 +00:00
|
|
|
}
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2013-08-26 10:44:20 +00:00
|
|
|
_refreshMultiplePicker: function() {
|
2013-08-30 12:27:19 +00:00
|
|
|
for ( var i = 0; i < this.options.numberOfMonths; i++ ) {
|
2013-08-26 10:44:20 +00:00
|
|
|
$( ".ui-datepicker-title", this.picker ).eq( i ).html( this._buildTitle() );
|
|
|
|
$( ".ui-datepicker-calendar", this.picker ).eq( i ).html( this._buildGrid() );
|
|
|
|
this.date.adjust( "M", 1 );
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
2012-11-18 20:01:30 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
this.date.adjust( "M", -this.options.numberOfMonths );
|
2013-10-30 13:11:06 +00:00
|
|
|
|
|
|
|
// TODO: This assumes focus is on the first grid. For multi pickers, the widget needs
|
|
|
|
// to maintain the currently focused grid and base queries like this off of it.
|
|
|
|
$( this.picker ).find( ".ui-state-focus" ).not( ":first" ).removeClass( "ui-state-focus" );
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2013-08-26 10:44:20 +00:00
|
|
|
open: function( event ) {
|
|
|
|
if ( this.inline || this.isOpen ) {
|
|
|
|
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
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
// TODO explain this
|
2013-08-30 12:27:19 +00:00
|
|
|
this.date = $.date( this.element.val(), this.options.dateFormat );
|
2013-08-26 10:44:20 +00:00
|
|
|
this.date.eachDay = this.options.eachDay;
|
|
|
|
this.date.select();
|
|
|
|
this.refresh();
|
2012-10-22 01:50:03 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
this.picker
|
|
|
|
.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
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
this._show( this.picker, this.options.show );
|
2012-11-18 20:01:30 +00:00
|
|
|
|
2013-08-26 10:44:20 +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
|
|
|
|
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
|
|
|
},
|
2013-08-26 10:44:20 +00:00
|
|
|
close: function( event ) {
|
|
|
|
if ( this.inline ) {
|
|
|
|
return;
|
2012-11-18 20:01:30 +00:00
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2013-08-26 10:44:20 +00:00
|
|
|
this._setHiddenPicker();
|
|
|
|
this._hide( this.picker, 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
|
|
|
},
|
2013-08-26 10:44:20 +00:00
|
|
|
_setHiddenPicker: function() {
|
|
|
|
this.picker
|
|
|
|
.attr( "aria-hidden", "true" )
|
|
|
|
.attr( "aria-expanded", "false" );
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2013-11-18 14:23:15 +00:00
|
|
|
_buildPosition: function() {
|
|
|
|
return $.extend( {}, {
|
|
|
|
of: this.element
|
|
|
|
}, this.options.position );
|
|
|
|
},
|
2013-08-26 10:44:20 +00:00
|
|
|
select: function( event, time ) {
|
|
|
|
this.date.setTime( time ).select();
|
|
|
|
this.refresh();
|
|
|
|
if ( !this.inline ) {
|
|
|
|
this.element.val( this.date.format() );
|
|
|
|
this.close();
|
|
|
|
this._focusTrigger();
|
2012-11-18 20:01:30 +00:00
|
|
|
}
|
2013-08-26 10:44:20 +00:00
|
|
|
this._trigger( "select", event, {
|
|
|
|
// TODO replace with value option to initialise and read
|
|
|
|
date: this.date.format()
|
|
|
|
});
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2013-11-21 14:03:08 +00:00
|
|
|
_value: function( value ) {
|
|
|
|
this.date.setTime( value ).select();
|
|
|
|
if ( !this.inline ) {
|
|
|
|
this.element.val( this.date.format() );
|
|
|
|
}
|
|
|
|
this.refresh();
|
|
|
|
},
|
|
|
|
value: function( value ) {
|
|
|
|
if ( arguments.length ) {
|
|
|
|
this._value( value );
|
|
|
|
} else {
|
|
|
|
return this.date.format();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
valueAsDate: function( value ) {
|
|
|
|
if ( arguments.length ) {
|
|
|
|
this._value( value );
|
|
|
|
} else {
|
|
|
|
return this.date.date();
|
|
|
|
}
|
|
|
|
},
|
2013-08-26 10:44:20 +00:00
|
|
|
_destroy: function() {
|
2013-11-22 13:55:04 +00:00
|
|
|
if ( this.inline ) {
|
|
|
|
this.picker.empty();
|
|
|
|
} else {
|
2013-08-26 10:44:20 +00:00
|
|
|
this.picker.remove();
|
|
|
|
this.element
|
|
|
|
.removeAttr( "aria-haspopup" )
|
|
|
|
.removeAttr( "aria-owns" );
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
2013-08-26 10:44:20 +00:00
|
|
|
},
|
|
|
|
widget: function() {
|
|
|
|
return this.picker;
|
2013-11-15 13:42:20 +00:00
|
|
|
},
|
|
|
|
_setOption: function( key, value ) {
|
|
|
|
this._super( key, value );
|
|
|
|
|
|
|
|
if ( key === "appendTo" ) {
|
|
|
|
this.picker.appendTo( this._appendTo() );
|
|
|
|
}
|
2013-11-15 14:17:13 +00:00
|
|
|
|
2013-11-19 13:35:19 +00:00
|
|
|
if ( key === "eachDay" ) {
|
|
|
|
this.date.eachDay = this.options.eachDay;
|
|
|
|
this.refresh();
|
|
|
|
}
|
|
|
|
|
2013-11-20 13:37:24 +00:00
|
|
|
if ( key === "dateFormat" ) {
|
|
|
|
this.date.setFormat( this.options.dateFormat );
|
|
|
|
if ( !this.inline ) {
|
|
|
|
this.element.val( this.date.format() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-15 14:17:13 +00:00
|
|
|
if ( key === "showWeek" ) {
|
|
|
|
this.refresh();
|
|
|
|
}
|
2013-11-18 14:23:15 +00:00
|
|
|
|
|
|
|
if ( key === "position" ) {
|
|
|
|
this.picker.position( this._buildPosition() );
|
|
|
|
}
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-07-12 16:40:48 +00:00
|
|
|
}));
|