2015-12-02 17:54:47 +00:00
|
|
|
/*!
|
|
|
|
* jQuery UI Date @VERSION
|
|
|
|
* http://jqueryui.com
|
2013-08-26 10:44:20 +00:00
|
|
|
*
|
2015-12-02 17:54:47 +00:00
|
|
|
* Copyright jQuery Foundation and other contributors
|
|
|
|
* Released under the MIT license.
|
|
|
|
* http://jquery.org/license
|
2013-08-26 10:44:20 +00:00
|
|
|
*/
|
2015-12-02 17:54:47 +00:00
|
|
|
|
|
|
|
//>>label: Date
|
|
|
|
//>>group: Core
|
|
|
|
//>>description: Calendar math built on Globalize.
|
|
|
|
//>>docs: http://api.jqueryui.com/date/
|
|
|
|
|
2015-07-15 13:40:38 +00:00
|
|
|
( function( factory ) {
|
|
|
|
if ( typeof define === "function" && define.amd ) {
|
|
|
|
|
|
|
|
// AMD. Register as an anonymous module.
|
|
|
|
define( [
|
2015-09-27 16:35:35 +00:00
|
|
|
"jquery", "./version" ], factory );
|
2015-07-15 13:40:38 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
// Browser globals
|
2015-04-30 15:38:01 +00:00
|
|
|
factory( jQuery );
|
2015-07-15 13:40:38 +00:00
|
|
|
}
|
2015-04-30 15:38:01 +00:00
|
|
|
}( function( $ ) {
|
2013-08-26 10:44:20 +00:00
|
|
|
|
2015-09-27 16:35:35 +00:00
|
|
|
$.ui.date = function( date, attributes ) {
|
|
|
|
if ( !( this instanceof $.ui.date ) ) {
|
|
|
|
return new $.ui.date( date, attributes );
|
2014-01-09 14:48:43 +00:00
|
|
|
}
|
2015-04-30 15:38:01 +00:00
|
|
|
|
|
|
|
this.setAttributes( attributes );
|
|
|
|
|
2013-11-30 12:22:17 +00:00
|
|
|
if ( typeof date === "string" && date.length ) {
|
2015-04-30 15:38:01 +00:00
|
|
|
this.dateObject = attributes.parse( date );
|
|
|
|
} else if ( $.type( date ) === "date" ) {
|
2014-05-15 22:19:32 +00:00
|
|
|
this.dateObject = date;
|
|
|
|
}
|
2013-08-26 10:44:20 +00:00
|
|
|
|
2014-01-09 14:48:43 +00:00
|
|
|
this.dateObject = this.dateObject || new Date();
|
|
|
|
};
|
2013-11-30 12:22:17 +00:00
|
|
|
|
2015-09-27 16:35:35 +00:00
|
|
|
$.extend( $.ui.date.prototype, {
|
2015-04-30 15:38:01 +00:00
|
|
|
|
|
|
|
setAttributes: function( attributes ) {
|
|
|
|
this.attributes = attributes;
|
2015-11-16 21:30:51 +00:00
|
|
|
this.firstDay = this.attributes.firstDay;
|
2014-01-09 14:48:43 +00:00
|
|
|
},
|
2015-04-30 15:38:01 +00:00
|
|
|
|
2017-03-31 19:31:45 +00:00
|
|
|
setTimestamp: function( time ) {
|
|
|
|
this.dateObject.setTime( time );
|
2014-01-09 14:48:43 +00:00
|
|
|
return this;
|
|
|
|
},
|
2015-04-30 15:38:01 +00:00
|
|
|
|
2014-01-09 14:48:43 +00:00
|
|
|
setDay: function( day ) {
|
2017-03-31 19:31:45 +00:00
|
|
|
this.dateObject.setDate( day );
|
2014-01-09 14:48:43 +00:00
|
|
|
return this;
|
|
|
|
},
|
2015-04-30 15:38:01 +00:00
|
|
|
|
2014-01-09 14:48:43 +00:00
|
|
|
setFullDate: function( year, month, day ) {
|
|
|
|
this.dateObject = new Date( year, month, day );
|
|
|
|
return this;
|
|
|
|
},
|
2015-04-30 15:38:01 +00:00
|
|
|
|
2014-01-09 14:48:43 +00:00
|
|
|
adjust: function( period, offset ) {
|
|
|
|
var date = this.dateObject,
|
2015-08-25 21:59:36 +00:00
|
|
|
day = period === "D" ? date.getDate() + offset : date.getDate(),
|
|
|
|
month = period === "M" ? date.getMonth() + offset : date.getMonth(),
|
|
|
|
year = period === "Y" ? date.getFullYear() + offset : date.getFullYear();
|
2014-01-09 14:48:43 +00:00
|
|
|
|
|
|
|
// If not day, update the day to the new month and year
|
2015-08-25 21:59:36 +00:00
|
|
|
if ( period !== "D" ) {
|
2014-01-09 14:48:43 +00:00
|
|
|
day = Math.max( 1, Math.min( day, this.daysInMonth( year, month ) ) );
|
|
|
|
}
|
|
|
|
this.dateObject = new Date( year, month, day, date.getHours(),
|
|
|
|
date.getMinutes(), date.getSeconds() );
|
|
|
|
return this;
|
|
|
|
},
|
2015-04-30 15:38:01 +00:00
|
|
|
|
2014-01-09 14:48:43 +00:00
|
|
|
daysInMonth: function( year, month ) {
|
|
|
|
var date = this.dateObject;
|
|
|
|
year = year || date.getFullYear();
|
|
|
|
month = month || date.getMonth();
|
|
|
|
return 32 - new Date( year, month, 32 ).getDate();
|
|
|
|
},
|
2015-04-30 15:38:01 +00:00
|
|
|
|
2014-01-09 14:48:43 +00:00
|
|
|
monthName: function() {
|
2015-04-30 15:38:01 +00:00
|
|
|
return this.attributes.formatMonth( this.dateObject );
|
2014-01-09 14:48:43 +00:00
|
|
|
},
|
2015-04-30 15:38:01 +00:00
|
|
|
|
2014-01-09 14:48:43 +00:00
|
|
|
day: function() {
|
|
|
|
return this.dateObject.getDate();
|
|
|
|
},
|
2015-04-30 15:38:01 +00:00
|
|
|
|
2014-01-09 14:48:43 +00:00
|
|
|
month: function() {
|
|
|
|
return this.dateObject.getMonth();
|
|
|
|
},
|
2015-04-30 15:38:01 +00:00
|
|
|
|
2014-01-09 14:48:43 +00:00
|
|
|
year: function() {
|
|
|
|
return this.dateObject.getFullYear();
|
|
|
|
},
|
2015-04-30 15:38:01 +00:00
|
|
|
|
2014-01-09 14:48:43 +00:00
|
|
|
weekdays: function() {
|
2015-09-27 16:57:46 +00:00
|
|
|
var date, dow,
|
2015-04-30 15:38:01 +00:00
|
|
|
firstDay = this.firstDay,
|
2014-09-04 18:47:48 +00:00
|
|
|
result = [];
|
2015-04-30 15:38:01 +00:00
|
|
|
|
|
|
|
// date = firstDay
|
|
|
|
date = new Date( this.dateObject.getTime() );
|
|
|
|
date.setDate( date.getDate() + firstDay - 1 - date.getDay() );
|
|
|
|
|
2015-09-27 16:57:46 +00:00
|
|
|
for ( dow = 0; dow < 7; dow++ ) {
|
2015-04-30 15:38:01 +00:00
|
|
|
date.setTime( date.getTime() + 86400000 );
|
2015-09-27 16:57:46 +00:00
|
|
|
result.push( {
|
2015-04-30 15:38:01 +00:00
|
|
|
shortname: this.attributes.formatWeekdayShort( date ),
|
|
|
|
fullname: this.attributes.formatWeekdayFull( date )
|
2015-09-27 16:57:46 +00:00
|
|
|
} );
|
2014-01-09 14:48:43 +00:00
|
|
|
}
|
2015-04-30 15:38:01 +00:00
|
|
|
|
2014-01-09 14:48:43 +00:00
|
|
|
return result;
|
|
|
|
},
|
2015-04-30 15:38:01 +00:00
|
|
|
|
2014-01-09 14:48:43 +00:00
|
|
|
days: function() {
|
2015-09-27 16:57:46 +00:00
|
|
|
var row, week, dayx, day,
|
|
|
|
result = [],
|
2015-09-27 16:35:35 +00:00
|
|
|
today = new $.ui.date( new Date(), this.attributes ),
|
2014-01-09 14:48:43 +00:00
|
|
|
date = this.dateObject,
|
|
|
|
firstDayOfMonth = new Date( this.year(), date.getMonth(), 1 ).getDay(),
|
2015-04-30 15:38:01 +00:00
|
|
|
leadDays = ( firstDayOfMonth - this.firstDay + 7 ) % 7,
|
2014-01-09 14:48:43 +00:00
|
|
|
rows = Math.ceil( ( leadDays + this.daysInMonth() ) / 7 ),
|
|
|
|
printDate = new Date( this.year(), date.getMonth(), 1 - leadDays );
|
2015-09-27 16:57:46 +00:00
|
|
|
|
|
|
|
for ( row = 0; row < rows; row++ ) {
|
|
|
|
week = result[ result.length ] = {
|
2015-04-30 15:38:01 +00:00
|
|
|
number: this.attributes.formatWeekOfYear( printDate ),
|
2014-01-09 14:48:43 +00:00
|
|
|
days: []
|
|
|
|
};
|
2015-09-27 16:57:46 +00:00
|
|
|
for ( dayx = 0; dayx < 7; dayx++ ) {
|
|
|
|
day = week.days[ week.days.length ] = {
|
2015-04-30 15:38:01 +00:00
|
|
|
lead: printDate.getMonth() !== date.getMonth(),
|
2014-01-09 14:48:43 +00:00
|
|
|
date: printDate.getDate(),
|
2015-01-24 01:23:24 +00:00
|
|
|
month: printDate.getMonth(),
|
|
|
|
year: printDate.getFullYear(),
|
2014-01-09 14:48:43 +00:00
|
|
|
timestamp: printDate.getTime(),
|
|
|
|
today: today.equal( printDate )
|
2013-08-26 10:44:20 +00:00
|
|
|
};
|
2014-01-09 14:48:43 +00:00
|
|
|
day.render = day.selectable = !day.lead;
|
|
|
|
if ( this.eachDay ) {
|
|
|
|
this.eachDay( day );
|
2013-08-26 10:44:20 +00:00
|
|
|
}
|
2015-04-30 15:38:01 +00:00
|
|
|
|
2014-01-09 14:48:43 +00:00
|
|
|
printDate.setDate( printDate.getDate() + 1 );
|
2013-08-26 10:44:20 +00:00
|
|
|
}
|
2014-01-09 14:48:43 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
2015-04-30 15:38:01 +00:00
|
|
|
|
2014-01-09 14:48:43 +00:00
|
|
|
// specialized for multi-month template, could be used in general
|
|
|
|
months: function( add ) {
|
2015-09-27 16:57:46 +00:00
|
|
|
var clone, i,
|
2014-01-09 14:48:43 +00:00
|
|
|
result = [ this ];
|
2013-08-26 10:44:20 +00:00
|
|
|
|
2015-09-27 16:57:46 +00:00
|
|
|
for ( i = 0; i < add; i++ ) {
|
2014-01-09 14:48:43 +00:00
|
|
|
clone = this.clone();
|
|
|
|
clone.adjust( "M", i + 1 );
|
|
|
|
result.push( clone );
|
2013-08-26 10:44:20 +00:00
|
|
|
}
|
2014-01-09 14:48:43 +00:00
|
|
|
result[ 0 ].first = true;
|
|
|
|
result[ result.length - 1 ].last = true;
|
|
|
|
return result;
|
|
|
|
},
|
2015-04-30 15:38:01 +00:00
|
|
|
|
2014-01-09 14:48:43 +00:00
|
|
|
clone: function() {
|
|
|
|
var date = this.dateObject;
|
2015-09-27 16:35:35 +00:00
|
|
|
return new $.ui.date( new Date( date.getTime() ), this.attributes );
|
2014-01-09 14:48:43 +00:00
|
|
|
},
|
2015-04-30 15:38:01 +00:00
|
|
|
|
2014-01-09 14:48:43 +00:00
|
|
|
equal: function( other ) {
|
2015-04-30 15:38:01 +00:00
|
|
|
var format = function( date ) {
|
|
|
|
return "" + date.getFullYear() + date.getMonth() + date.getDate();
|
2015-08-25 21:59:36 +00:00
|
|
|
};
|
2014-01-09 14:48:43 +00:00
|
|
|
return format( this.dateObject ) === format( other );
|
|
|
|
},
|
2015-04-30 15:38:01 +00:00
|
|
|
|
2017-03-31 19:31:45 +00:00
|
|
|
timestamp: function() {
|
|
|
|
return this.dateObject.getTime();
|
|
|
|
},
|
|
|
|
|
2014-01-09 14:48:43 +00:00
|
|
|
date: function() {
|
|
|
|
return this.dateObject;
|
|
|
|
}
|
2015-09-27 16:57:46 +00:00
|
|
|
} );
|
2015-04-30 15:38:01 +00:00
|
|
|
|
2015-09-27 16:35:35 +00:00
|
|
|
return $.ui.date;
|
2013-08-26 10:44:20 +00:00
|
|
|
|
2015-07-15 13:40:38 +00:00
|
|
|
} ) );
|