parent
c7724f7c90
commit
584f2871b0
File diff suppressed because one or more lines are too long
|
|
@ -2,15 +2,13 @@
|
|||
|
||||
/*!
|
||||
* Pikaday
|
||||
* Copyright © 2012 David Bushell | BSD & MIT license | http://dbushell.com/
|
||||
* Copyright © 2014 David Bushell | BSD & MIT license | http://dbushell.com/
|
||||
*/
|
||||
|
||||
.pika-single {
|
||||
z-index: 9999;
|
||||
display: block;
|
||||
position: relative;
|
||||
width: 240px;
|
||||
padding: 8px;
|
||||
color: #333;
|
||||
background: #fff;
|
||||
border: 1px solid #ccc;
|
||||
|
|
@ -18,6 +16,18 @@
|
|||
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
|
||||
}
|
||||
|
||||
/*
|
||||
clear child float (pika-lendar), using the famous micro clearfix hack
|
||||
http://nicolasgallagher.com/micro-clearfix-hack/
|
||||
*/
|
||||
.pika-single:before,
|
||||
.pika-single:after {
|
||||
content: " ";
|
||||
display: table;
|
||||
}
|
||||
.pika-single:after { clear: both }
|
||||
.pika-single { *zoom: 1 }
|
||||
|
||||
.pika-single.is-hidden {
|
||||
display: none;
|
||||
}
|
||||
|
|
@ -27,13 +37,15 @@
|
|||
box-shadow: 0 5px 15px -5px rgba(0,0,0,.5);
|
||||
}
|
||||
|
||||
.pika-title, .pika-footer {
|
||||
position: relative;
|
||||
text-align: center;
|
||||
.pika-lendar {
|
||||
float: left;
|
||||
width: 240px;
|
||||
margin: 8px;
|
||||
}
|
||||
|
||||
.pika-footer {
|
||||
margin: 5px auto 0;
|
||||
.pika-title {
|
||||
position: relative;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.pika-label {
|
||||
|
|
@ -49,8 +61,6 @@
|
|||
font-weight: bold;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.pika-footer select,
|
||||
.pika-title select {
|
||||
cursor: pointer;
|
||||
position: absolute;
|
||||
|
|
@ -72,13 +82,14 @@
|
|||
padding: 0;
|
||||
width: 20px;
|
||||
height: 30px;
|
||||
/* hide text using text-indent trick, using width value (it's enough) */
|
||||
text-indent: 20px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
background-color: transparent;
|
||||
background-position: center center;
|
||||
background-repeat: no-repeat;
|
||||
background-size: 75% 75%;
|
||||
white-space: nowrap;
|
||||
text-indent: 100%;
|
||||
overflow: hidden;
|
||||
opacity: .5;
|
||||
*position: absolute;
|
||||
*top: 0;
|
||||
|
|
@ -124,6 +135,7 @@
|
|||
.pika-table th,
|
||||
.pika-table td {
|
||||
width: 14.285714285714286%;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.pika-table th {
|
||||
|
|
@ -137,6 +149,8 @@
|
|||
.pika-button {
|
||||
cursor: pointer;
|
||||
display: block;
|
||||
box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
outline: none;
|
||||
border: 0;
|
||||
margin: 0;
|
||||
|
|
@ -149,6 +163,11 @@
|
|||
background: #f5f5f5;
|
||||
}
|
||||
|
||||
.pika-week {
|
||||
font-size: 11px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.is-today .pika-button {
|
||||
color: #33aaff;
|
||||
font-weight: bold;
|
||||
|
|
@ -162,6 +181,24 @@
|
|||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.is-inrange .pika-button {
|
||||
background: #D5E9F7;
|
||||
}
|
||||
|
||||
.is-startrange .pika-button {
|
||||
color: #fff;
|
||||
background: #6CB31D;
|
||||
box-shadow: none;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.is-endrange .pika-button {
|
||||
color: #fff;
|
||||
background: #33aaff;
|
||||
box-shadow: none;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.is-disabled .pika-button {
|
||||
pointer-events: none;
|
||||
cursor: default;
|
||||
|
|
@ -170,8 +207,15 @@
|
|||
}
|
||||
|
||||
.pika-button:hover {
|
||||
color: #fff !important;
|
||||
background: #ff8000 !important;
|
||||
box-shadow: none !important;
|
||||
border-radius: 3px !important;
|
||||
color: #fff;
|
||||
background: #ff8000;
|
||||
box-shadow: none;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
/* styling for abbr */
|
||||
.pika-table abbr {
|
||||
border-bottom: none;
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,6 +44,10 @@
|
|||
} else {
|
||||
if (typeof args[0] === 'string' && typeof plugin[args[0]] === 'function') {
|
||||
plugin[args[0]].apply(plugin, Array.prototype.slice.call(args,1));
|
||||
|
||||
if (args[0] === 'destroy') {
|
||||
self.removeData('pikaday');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*!
|
||||
* Pikaday
|
||||
*
|
||||
* Copyright © 2013 David Bushell | BSD & MIT license | https://github.com/dbushell/Pikaday
|
||||
* Copyright © 2014 David Bushell | BSD & MIT license | https://github.com/dbushell/Pikaday
|
||||
*/
|
||||
|
||||
(function (root, factory)
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
{
|
||||
// Load moment.js as an optional dependency
|
||||
var id = 'moment';
|
||||
moment = req.defined && req.defined(id) ? req(id) : undefined;
|
||||
try { moment = req(id); } catch (e) {}
|
||||
return factory(moment);
|
||||
});
|
||||
} else {
|
||||
|
|
@ -107,6 +107,12 @@
|
|||
return (/Date/).test(Object.prototype.toString.call(obj)) && !isNaN(obj.getTime());
|
||||
},
|
||||
|
||||
isWeekend = function(date)
|
||||
{
|
||||
var day = date.getDay();
|
||||
return day === 0 || day === 6;
|
||||
},
|
||||
|
||||
isLeapYear = function(year)
|
||||
{
|
||||
// solution by Matti Virkkunen: http://stackoverflow.com/a/4881951
|
||||
|
|
@ -125,12 +131,8 @@
|
|||
|
||||
compareDates = function(a,b)
|
||||
{
|
||||
// Copy so we don't change the dates being passed in
|
||||
var _a = new Date(a.getTime());
|
||||
var _b = new Date(b.getTime());
|
||||
setToStartOfDay(_a);
|
||||
setToStartOfDay(_b);
|
||||
return _a.getTime() === _b.getTime();
|
||||
// weak date comparison (use setToStartOfDay(date) to ensure correct result)
|
||||
return a.getTime() === b.getTime();
|
||||
},
|
||||
|
||||
extend = function(to, from, overwrite)
|
||||
|
|
@ -138,7 +140,7 @@
|
|||
var prop, hasProp;
|
||||
for (prop in from) {
|
||||
hasProp = to[prop] !== undefined;
|
||||
if (hasProp && typeof from[prop] === 'object' && from[prop].nodeName === undefined) {
|
||||
if (hasProp && typeof from[prop] === 'object' && from[prop] !== null && from[prop].nodeName === undefined) {
|
||||
if (isDate(from[prop])) {
|
||||
if (overwrite) {
|
||||
to[prop] = new Date(from[prop].getTime());
|
||||
|
|
@ -158,6 +160,17 @@
|
|||
return to;
|
||||
},
|
||||
|
||||
adjustCalendar = function(calendar) {
|
||||
if (calendar.month < 0) {
|
||||
calendar.year -= Math.ceil(Math.abs(calendar.month)/12);
|
||||
calendar.month += 12;
|
||||
}
|
||||
if (calendar.month > 11) {
|
||||
calendar.year += Math.floor(Math.abs(calendar.month)/12);
|
||||
calendar.month -= 12;
|
||||
}
|
||||
return calendar;
|
||||
},
|
||||
|
||||
/**
|
||||
* defaults and localisation
|
||||
|
|
@ -170,9 +183,15 @@
|
|||
// automatically show/hide the picker on `field` focus (default `true` if `field` is set)
|
||||
bound: undefined,
|
||||
|
||||
// position of the datepicker, relative to the field (default to bottom & left)
|
||||
// ('bottom' & 'left' keywords are not used, 'top' & 'right' are modifier on the bottom/left position)
|
||||
position: 'bottom left',
|
||||
|
||||
// automatically fit in the viewport even if it means repositioning from the position option
|
||||
reposition: true,
|
||||
|
||||
// the default output format for `.toString()` and `field` value
|
||||
// set in `config` based on if showTime is set
|
||||
format: null,
|
||||
format: 'YYYY-MM-DD',
|
||||
|
||||
// the initial date to view when first opened
|
||||
defaultDate: null,
|
||||
|
|
@ -191,12 +210,18 @@
|
|||
// number of years either side, or array of upper/lower range
|
||||
yearRange: 10,
|
||||
|
||||
// show week numbers at head of row
|
||||
showWeekNumber: false,
|
||||
|
||||
// used internally (don't config outside)
|
||||
minYear: 0,
|
||||
maxYear: 9999,
|
||||
minMonth: undefined,
|
||||
maxMonth: undefined,
|
||||
|
||||
startRange: null,
|
||||
endRange: null,
|
||||
|
||||
isRTL: false,
|
||||
|
||||
// Additional text to append to the year in the calendar title
|
||||
|
|
@ -205,13 +230,15 @@
|
|||
// Render the month after year in the calendar title
|
||||
showMonthAfterYear: false,
|
||||
|
||||
// how many months are visible (not implemented yet)
|
||||
// how many months are visible
|
||||
numberOfMonths: 1,
|
||||
|
||||
// time
|
||||
showTime: false,
|
||||
showSeconds: false,
|
||||
use24hour: false,
|
||||
// when numberOfMonths is used, this will help you to choose where the main calendar will be (default `left`, can be set to `right`)
|
||||
// only used for the first display or when a selected date is not visible
|
||||
mainCalendar: 'left',
|
||||
|
||||
// Specify a DOM element to render the calendar in
|
||||
container: undefined,
|
||||
|
||||
// internationalization
|
||||
i18n: {
|
||||
|
|
@ -222,6 +249,9 @@
|
|||
weekdaysShort : ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
|
||||
},
|
||||
|
||||
// Theme Classname
|
||||
theme: null,
|
||||
|
||||
// callback function
|
||||
onSelect: null,
|
||||
onOpen: null,
|
||||
|
|
@ -242,22 +272,43 @@
|
|||
return abbr ? opts.i18n.weekdaysShort[day] : opts.i18n.weekdays[day];
|
||||
},
|
||||
|
||||
renderDay = function(i, isSelected, isToday, isDisabled, isEmpty)
|
||||
renderDay = function(opts)
|
||||
{
|
||||
if (isEmpty) {
|
||||
if (opts.isEmpty) {
|
||||
return '<td class="is-empty"></td>';
|
||||
}
|
||||
var arr = [];
|
||||
if (isDisabled) {
|
||||
if (opts.isDisabled) {
|
||||
arr.push('is-disabled');
|
||||
}
|
||||
if (isToday) {
|
||||
if (opts.isToday) {
|
||||
arr.push('is-today');
|
||||
}
|
||||
if (isSelected) {
|
||||
if (opts.isSelected) {
|
||||
arr.push('is-selected');
|
||||
}
|
||||
return '<td data-day="' + i + '" class="' + arr.join(' ') + '"><button class="pika-button" type="button">' + i + '</button>' + '</td>';
|
||||
if (opts.isInRange) {
|
||||
arr.push('is-inrange');
|
||||
}
|
||||
if (opts.isStartRange) {
|
||||
arr.push('is-startrange');
|
||||
}
|
||||
if (opts.isEndRange) {
|
||||
arr.push('is-endrange');
|
||||
}
|
||||
return '<td data-day="' + opts.day + '" class="' + arr.join(' ') + '">' +
|
||||
'<button class="pika-button pika-day" type="button" ' +
|
||||
'data-pika-year="' + opts.year + '" data-pika-month="' + opts.month + '" data-pika-day="' + opts.day + '">' +
|
||||
opts.day +
|
||||
'</button>' +
|
||||
'</td>';
|
||||
},
|
||||
|
||||
renderWeek = function (d, m, y) {
|
||||
// Lifted from http://javascript.about.com/library/blweekyear.htm, lightly modified.
|
||||
var onejan = new Date(y, 0, 1),
|
||||
weekNum = Math.ceil((((new Date(y, m, d) - onejan) / 86400000) + onejan.getDay()+1)/7);
|
||||
return '<td class="pika-week">' + weekNum + '</td>';
|
||||
},
|
||||
|
||||
renderRow = function(days, isRTL)
|
||||
|
|
@ -273,18 +324,19 @@
|
|||
renderHead = function(opts)
|
||||
{
|
||||
var i, arr = [];
|
||||
if (opts.showWeekNumber) {
|
||||
arr.push('<th></th>');
|
||||
}
|
||||
for (i = 0; i < 7; i++) {
|
||||
arr.push('<th scope="col"><abbr title="' + renderDayName(opts, i) + '">' + renderDayName(opts, i, true) + '</abbr></th>');
|
||||
}
|
||||
return '<thead>' + (opts.isRTL ? arr.reverse() : arr).join('') + '</thead>';
|
||||
},
|
||||
|
||||
renderTitle = function(instance)
|
||||
renderTitle = function(instance, c, year, month, refYear)
|
||||
{
|
||||
var i, j, arr,
|
||||
opts = instance._o,
|
||||
month = instance._m,
|
||||
year = instance._y,
|
||||
isMinYear = year === opts.minYear,
|
||||
isMaxYear = year === opts.maxYear,
|
||||
html = '<div class="pika-title">',
|
||||
|
|
@ -294,12 +346,12 @@
|
|||
next = true;
|
||||
|
||||
for (arr = [], i = 0; i < 12; i++) {
|
||||
arr.push('<option value="' + i + '"' +
|
||||
arr.push('<option value="' + (year === refYear ? i - c : 12 + i - c) + '"' +
|
||||
(i === month ? ' selected': '') +
|
||||
((isMinYear && i < opts.minMonth) || (isMaxYear && i > opts.maxMonth) ? 'disabled' : '') + '>' +
|
||||
opts.i18n.months[i] + '</option>');
|
||||
}
|
||||
monthHtml = '<div class="pika-label">' + opts.i18n.months[month] + '<select class="pika-select pika-select-month">' + arr.join('') + '</select></div>';
|
||||
monthHtml = '<div class="pika-label">' + opts.i18n.months[month] + '<select class="pika-select pika-select-month" tabindex="-1">' + arr.join('') + '</select></div>';
|
||||
|
||||
if (isArray(opts.yearRange)) {
|
||||
i = opts.yearRange[0];
|
||||
|
|
@ -314,7 +366,7 @@
|
|||
arr.push('<option value="' + i + '"' + (i === year ? ' selected': '') + '>' + (i) + '</option>');
|
||||
}
|
||||
}
|
||||
yearHtml = '<div class="pika-label">' + year + opts.yearSuffix + '<select class="pika-select pika-select-year">' + arr.join('') + '</select></div>';
|
||||
yearHtml = '<div class="pika-label">' + year + opts.yearSuffix + '<select class="pika-select pika-select-year" tabindex="-1">' + arr.join('') + '</select></div>';
|
||||
|
||||
if (opts.showMonthAfterYear) {
|
||||
html += yearHtml + monthHtml;
|
||||
|
|
@ -330,8 +382,12 @@
|
|||
next = false;
|
||||
}
|
||||
|
||||
html += '<button class="pika-prev' + (prev ? '' : ' is-disabled') + '" type="button">' + opts.i18n.previousMonth + '</button>';
|
||||
html += '<button class="pika-next' + (next ? '' : ' is-disabled') + '" type="button">' + opts.i18n.nextMonth + '</button>';
|
||||
if (c === 0) {
|
||||
html += '<button class="pika-prev' + (prev ? '' : ' is-disabled') + '" type="button">' + opts.i18n.previousMonth + '</button>';
|
||||
}
|
||||
if (c === (instance._o.numberOfMonths - 1) ) {
|
||||
html += '<button class="pika-next' + (next ? '' : ' is-disabled') + '" type="button">' + opts.i18n.nextMonth + '</button>';
|
||||
}
|
||||
|
||||
return html += '</div>';
|
||||
},
|
||||
|
|
@ -341,41 +397,6 @@
|
|||
return '<table cellpadding="0" cellspacing="0" class="pika-table">' + renderHead(opts) + renderBody(data) + '</table>';
|
||||
},
|
||||
|
||||
renderFooter = function(hh, mm, ss, use24hour, showSeconds)
|
||||
{
|
||||
var to_return = '<div class="pika-footer">' +
|
||||
renderTime(24, hh, 'pika-select-hour', function(i) {
|
||||
if (use24hour) {
|
||||
return i;
|
||||
} else {
|
||||
var to_return = (i%12) + (i<12 ? ' AM' : ' PM');
|
||||
if (to_return == '0 AM') {
|
||||
return 'Midnight'
|
||||
} else if (to_return == '0 PM') {
|
||||
return 'Noon'
|
||||
} else {
|
||||
return to_return;
|
||||
}
|
||||
}
|
||||
}) +
|
||||
'<div class="pika-label pika-label-divider">:</div>' +
|
||||
renderTime(60, mm, 'pika-select-minute', function(i) { if (i < 10) return "0" + i; return i });
|
||||
|
||||
if (showSeconds) {
|
||||
to_return += '<div class="pika-label pika-label-divider">:</div>' +
|
||||
renderTime(60, ss, 'pika-select-second', function(i) { if (i < 10) return "0" + i; return i });
|
||||
}
|
||||
return to_return + '</div>';
|
||||
},
|
||||
|
||||
renderTime = function(num_options, selected_val, select_class, display_func) {
|
||||
var to_return = '<div class="pika-label"> '+ display_func(selected_val) +' <select class="pika-select '+select_class+'">';
|
||||
for (var i=0; i<num_options; i++) {
|
||||
to_return += '<option value="'+i+'" '+(i==selected_val ? 'selected' : '')+'>'+display_func(i)+'</option>'
|
||||
}
|
||||
to_return += '</select></div>';
|
||||
return to_return;
|
||||
},
|
||||
|
||||
/**
|
||||
* Pikaday constructor
|
||||
|
|
@ -398,13 +419,15 @@
|
|||
|
||||
if (!hasClass(target, 'is-disabled')) {
|
||||
if (hasClass(target, 'pika-button') && !hasClass(target, 'is-empty')) {
|
||||
self.setDate(new Date(self._y, self._m, parseInt(target.innerHTML, 10), self._hh, self._mm, self._ss));
|
||||
self.setDate(new Date(target.getAttribute('data-pika-year'), target.getAttribute('data-pika-month'), target.getAttribute('data-pika-day')));
|
||||
if (opts.bound) {
|
||||
sto(function() {
|
||||
self.hide();
|
||||
if (opts.field) {
|
||||
opts.field.blur();
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (hasClass(target, 'pika-prev')) {
|
||||
self.prevMonth();
|
||||
|
|
@ -414,6 +437,7 @@
|
|||
}
|
||||
}
|
||||
if (!hasClass(target, 'pika-select')) {
|
||||
// if this is touch event prevent mouse events emulation
|
||||
if (e.preventDefault) {
|
||||
e.preventDefault();
|
||||
} else {
|
||||
|
|
@ -438,18 +462,6 @@
|
|||
else if (hasClass(target, 'pika-select-year')) {
|
||||
self.gotoYear(target.value);
|
||||
}
|
||||
else if (hasClass(target, 'pika-select-hour')) {
|
||||
self._hh = target.value;
|
||||
self.setTime(self._hh, self._mm, self._ss);
|
||||
}
|
||||
else if (hasClass(target, 'pika-select-minute')) {
|
||||
self._mm = target.value;
|
||||
self.setTime(self._hh, self._mm, self._ss);
|
||||
}
|
||||
else if (hasClass(target, 'pika-select-second')) {
|
||||
self._ss = target.value;
|
||||
self.setTime(self._hh, self._mm, self._ss);
|
||||
}
|
||||
};
|
||||
|
||||
self._onInputChange = function(e)
|
||||
|
|
@ -466,7 +478,9 @@
|
|||
else {
|
||||
date = new Date(Date.parse(opts.field.value));
|
||||
}
|
||||
self.setDate(isDate(date) ? date : null);
|
||||
if (isDate(date)) {
|
||||
self.setDate(date);
|
||||
}
|
||||
if (!self._v) {
|
||||
self.show();
|
||||
}
|
||||
|
|
@ -484,6 +498,15 @@
|
|||
|
||||
self._onInputBlur = function()
|
||||
{
|
||||
// IE allows pika div to gain focus; catch blur the input field
|
||||
var pEl = document.activeElement;
|
||||
do {
|
||||
if (hasClass(pEl, 'pika-single')) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
while ((pEl = pEl.parentNode));
|
||||
|
||||
if (!self._c) {
|
||||
self._b = sto(function() {
|
||||
self.hide();
|
||||
|
|
@ -507,24 +530,27 @@
|
|||
}
|
||||
}
|
||||
do {
|
||||
if (hasClass(pEl, 'pika-single')) {
|
||||
if (hasClass(pEl, 'pika-single') || pEl === opts.trigger) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
while ((pEl = pEl.parentNode));
|
||||
if (self._v && target !== opts.trigger) {
|
||||
if (self._v && target !== opts.trigger && pEl !== opts.trigger) {
|
||||
self.hide();
|
||||
}
|
||||
};
|
||||
|
||||
self.el = document.createElement('div');
|
||||
self.el.className = 'pika-single' + (opts.isRTL ? ' is-rtl' : '');
|
||||
self.el.className = 'pika-single' + (opts.isRTL ? ' is-rtl' : '') + (opts.theme ? ' ' + opts.theme : '');
|
||||
|
||||
addEvent(self.el, 'mousedown', self._onMouseDown, true);
|
||||
addEvent(self.el, 'touchend', self._onMouseDown, true);
|
||||
addEvent(self.el, 'change', self._onChange);
|
||||
|
||||
if (opts.field) {
|
||||
if (opts.bound) {
|
||||
if (opts.container) {
|
||||
opts.container.appendChild(self.el);
|
||||
} else if (opts.bound) {
|
||||
document.body.appendChild(self.el);
|
||||
} else {
|
||||
opts.field.parentNode.insertBefore(self.el, opts.field.nextSibling);
|
||||
|
|
@ -562,7 +588,6 @@
|
|||
} else {
|
||||
this.show();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -587,10 +612,16 @@
|
|||
|
||||
opts.field = (opts.field && opts.field.nodeName) ? opts.field : null;
|
||||
|
||||
opts.theme = (typeof opts.theme) === 'string' && opts.theme ? opts.theme : null;
|
||||
|
||||
opts.bound = !!(opts.bound !== undefined ? opts.field && opts.bound : opts.field);
|
||||
|
||||
opts.trigger = (opts.trigger && opts.trigger.nodeName) ? opts.trigger : opts.field;
|
||||
|
||||
opts.disableWeekends = !!opts.disableWeekends;
|
||||
|
||||
opts.disableDayFn = (typeof opts.disableDayFn) === 'function' ? opts.disableDayFn : null;
|
||||
|
||||
var nom = parseInt(opts.numberOfMonths, 10) || 1;
|
||||
opts.numberOfMonths = nom > 4 ? 4 : nom;
|
||||
|
||||
|
|
@ -604,14 +635,10 @@
|
|||
opts.maxDate = opts.minDate = false;
|
||||
}
|
||||
if (opts.minDate) {
|
||||
if (!opts.showTime) setToStartOfDay(opts.minDate);
|
||||
opts.minYear = opts.minDate.getFullYear();
|
||||
opts.minMonth = opts.minDate.getMonth();
|
||||
this.setMinDate(opts.minDate);
|
||||
}
|
||||
if (opts.maxDate) {
|
||||
if (!opts.showTime) setToStartOfDay(opts.maxDate);
|
||||
opts.maxYear = opts.maxDate.getFullYear();
|
||||
opts.maxMonth = opts.maxDate.getMonth();
|
||||
this.setMaxDate(opts.maxDate);
|
||||
}
|
||||
|
||||
if (isArray(opts.yearRange)) {
|
||||
|
|
@ -625,14 +652,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
// If no format is given, set based on showTime
|
||||
if (opts.format === null) {
|
||||
opts.format = 'YYYY-MM-DD';
|
||||
if (opts.showTime) {
|
||||
opts.format += ' HH:mm:ss';
|
||||
}
|
||||
}
|
||||
|
||||
return opts;
|
||||
},
|
||||
|
||||
|
|
@ -641,7 +660,7 @@
|
|||
*/
|
||||
toString: function(format)
|
||||
{
|
||||
return !isDate(this._d) ? '' : hasMoment ? moment(this._d).format(format || this._o.format) : this._o.showTime ? this._d.toString() : this._d.toDateString();
|
||||
return !isDate(this._d) ? '' : hasMoment ? moment(this._d).format(format || this._o.format) : this._d.toDateString();
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -655,10 +674,10 @@
|
|||
/**
|
||||
* set the current selection from a Moment.js object (if available)
|
||||
*/
|
||||
setMoment: function(date)
|
||||
setMoment: function(date, preventOnSelect)
|
||||
{
|
||||
if (hasMoment && moment.isMoment(date)) {
|
||||
this.setDate(date.toDate());
|
||||
this.setDate(date.toDate(), preventOnSelect);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -670,16 +689,6 @@
|
|||
return isDate(this._d) ? new Date(this._d.getTime()) : null;
|
||||
},
|
||||
|
||||
/**
|
||||
* set the current time selection
|
||||
*/
|
||||
setTime: function(hours, minutes, seconds) {
|
||||
if (this._d) {
|
||||
this._d.setHours(this._hh, this._mm, this._ss);
|
||||
this.setDate(this._d);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* set the current selection
|
||||
*/
|
||||
|
|
@ -687,6 +696,12 @@
|
|||
{
|
||||
if (!date) {
|
||||
this._d = null;
|
||||
|
||||
if (this._o.field) {
|
||||
this._o.field.value = '';
|
||||
fireEvent(this._o.field, 'change', { firedBy: this });
|
||||
}
|
||||
|
||||
return this.draw();
|
||||
}
|
||||
if (typeof date === 'string') {
|
||||
|
|
@ -706,13 +721,7 @@
|
|||
}
|
||||
|
||||
this._d = new Date(date.getTime());
|
||||
|
||||
if (this._o.showTime && !this._o.showSeconds) {
|
||||
this._d.setSeconds(0);
|
||||
} else if (!this._o.showTime) {
|
||||
setToStartOfDay(this._d);
|
||||
}
|
||||
|
||||
setToStartOfDay(this._d);
|
||||
this.gotoDate(this._d);
|
||||
|
||||
if (this._o.field) {
|
||||
|
|
@ -729,14 +738,43 @@
|
|||
*/
|
||||
gotoDate: function(date)
|
||||
{
|
||||
var newCalendar = true;
|
||||
|
||||
if (!isDate(date)) {
|
||||
return;
|
||||
}
|
||||
this._y = date.getFullYear();
|
||||
this._m = date.getMonth();
|
||||
this._hh = date.getHours();
|
||||
this._mm = date.getMinutes();
|
||||
this._ss = date.getSeconds();
|
||||
|
||||
if (this.calendars) {
|
||||
var firstVisibleDate = new Date(this.calendars[0].year, this.calendars[0].month, 1),
|
||||
lastVisibleDate = new Date(this.calendars[this.calendars.length-1].year, this.calendars[this.calendars.length-1].month, 1),
|
||||
visibleDate = date.getTime();
|
||||
// get the end of the month
|
||||
lastVisibleDate.setMonth(lastVisibleDate.getMonth()+1);
|
||||
lastVisibleDate.setDate(lastVisibleDate.getDate()-1);
|
||||
newCalendar = (visibleDate < firstVisibleDate.getTime() || lastVisibleDate.getTime() < visibleDate);
|
||||
}
|
||||
|
||||
if (newCalendar) {
|
||||
this.calendars = [{
|
||||
month: date.getMonth(),
|
||||
year: date.getFullYear()
|
||||
}];
|
||||
if (this._o.mainCalendar === 'right') {
|
||||
this.calendars[0].month += 1 - this._o.numberOfMonths;
|
||||
}
|
||||
}
|
||||
|
||||
this.adjustCalendars();
|
||||
},
|
||||
|
||||
adjustCalendars: function() {
|
||||
this.calendars[0] = adjustCalendar(this.calendars[0]);
|
||||
for (var c = 1; c < this._o.numberOfMonths; c++) {
|
||||
this.calendars[c] = adjustCalendar({
|
||||
month: this.calendars[0].month + c,
|
||||
year: this.calendars[0].year
|
||||
});
|
||||
}
|
||||
this.draw();
|
||||
},
|
||||
|
||||
|
|
@ -750,28 +788,22 @@
|
|||
*/
|
||||
gotoMonth: function(month)
|
||||
{
|
||||
if (!isNaN( (month = parseInt(month, 10)) )) {
|
||||
this._m = month < 0 ? 0 : month > 11 ? 11 : month;
|
||||
this.draw();
|
||||
if (!isNaN(month)) {
|
||||
this.calendars[0].month = parseInt(month, 10);
|
||||
this.adjustCalendars();
|
||||
}
|
||||
},
|
||||
|
||||
nextMonth: function()
|
||||
{
|
||||
if (++this._m > 11) {
|
||||
this._m = 0;
|
||||
this._y++;
|
||||
}
|
||||
this.draw();
|
||||
this.calendars[0].month++;
|
||||
this.adjustCalendars();
|
||||
},
|
||||
|
||||
prevMonth: function()
|
||||
{
|
||||
if (--this._m < 0) {
|
||||
this._m = 11;
|
||||
this._y--;
|
||||
}
|
||||
this.draw();
|
||||
this.calendars[0].month--;
|
||||
this.adjustCalendars();
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -780,8 +812,8 @@
|
|||
gotoYear: function(year)
|
||||
{
|
||||
if (!isNaN(year)) {
|
||||
this._y = parseInt(year, 10);
|
||||
this.draw();
|
||||
this.calendars[0].year = parseInt(year, 10);
|
||||
this.adjustCalendars();
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -790,7 +822,11 @@
|
|||
*/
|
||||
setMinDate: function(value)
|
||||
{
|
||||
setToStartOfDay(value);
|
||||
this._o.minDate = value;
|
||||
this._o.minYear = value.getFullYear();
|
||||
this._o.minMonth = value.getMonth();
|
||||
this.draw();
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -798,7 +834,21 @@
|
|||
*/
|
||||
setMaxDate: function(value)
|
||||
{
|
||||
setToStartOfDay(value);
|
||||
this._o.maxDate = value;
|
||||
this._o.maxYear = value.getFullYear();
|
||||
this._o.maxMonth = value.getMonth();
|
||||
this.draw();
|
||||
},
|
||||
|
||||
setStartRange: function(value)
|
||||
{
|
||||
this._o.startRange = value;
|
||||
},
|
||||
|
||||
setEndRange: function(value)
|
||||
{
|
||||
this._o.endRange = value;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -813,7 +863,8 @@
|
|||
minYear = opts.minYear,
|
||||
maxYear = opts.maxYear,
|
||||
minMonth = opts.minMonth,
|
||||
maxMonth = opts.maxMonth;
|
||||
maxMonth = opts.maxMonth,
|
||||
html = '';
|
||||
|
||||
if (this._y <= minYear) {
|
||||
this._y = minYear;
|
||||
|
|
@ -828,11 +879,12 @@
|
|||
}
|
||||
}
|
||||
|
||||
this.el.innerHTML = renderTitle(this) + this.render(this._y, this._m);
|
||||
if (opts.showTime) {
|
||||
this.el.innerHTML += renderFooter(this._hh, this._mm, this._ss, this._o.use24hour, this._o.showSeconds);
|
||||
for (var c = 0; c < opts.numberOfMonths; c++) {
|
||||
html += '<div class="pika-lendar">' + renderTitle(this, c, this.calendars[c].year, this.calendars[c].month, this.calendars[0].year) + this.render(this.calendars[c].year, this.calendars[c].month) + '</div>';
|
||||
}
|
||||
|
||||
this.el.innerHTML = html;
|
||||
|
||||
if (opts.bound) {
|
||||
if(opts.field.type !== 'hidden') {
|
||||
sto(function() {
|
||||
|
|
@ -851,12 +903,19 @@
|
|||
|
||||
adjustPosition: function()
|
||||
{
|
||||
var field = this._o.trigger, pEl = field,
|
||||
width = this.el.offsetWidth, height = this.el.offsetHeight,
|
||||
viewportWidth = window.innerWidth || document.documentElement.clientWidth,
|
||||
viewportHeight = window.innerHeight || document.documentElement.clientHeight,
|
||||
scrollTop = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop,
|
||||
left, top, clientRect;
|
||||
var field, pEl, width, height, viewportWidth, viewportHeight, scrollTop, left, top, clientRect;
|
||||
|
||||
if (this._o.container) return;
|
||||
|
||||
this.el.style.position = 'absolute';
|
||||
|
||||
field = this._o.trigger;
|
||||
pEl = field;
|
||||
width = this.el.offsetWidth;
|
||||
height = this.el.offsetHeight;
|
||||
viewportWidth = window.innerWidth || document.documentElement.clientWidth;
|
||||
viewportHeight = window.innerHeight || document.documentElement.clientHeight;
|
||||
scrollTop = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
|
||||
|
||||
if (typeof field.getBoundingClientRect === 'function') {
|
||||
clientRect = field.getBoundingClientRect();
|
||||
|
|
@ -871,13 +930,26 @@
|
|||
}
|
||||
}
|
||||
|
||||
if (left + width > viewportWidth) {
|
||||
// default position is bottom & left
|
||||
if ((this._o.reposition && left + width > viewportWidth) ||
|
||||
(
|
||||
this._o.position.indexOf('right') > -1 &&
|
||||
left - width + field.offsetWidth > 0
|
||||
)
|
||||
) {
|
||||
left = left - width + field.offsetWidth;
|
||||
}
|
||||
if (top + height > viewportHeight + scrollTop) {
|
||||
if ((this._o.reposition && top + height > viewportHeight + scrollTop) ||
|
||||
(
|
||||
this._o.position.indexOf('top') > -1 &&
|
||||
top - height - field.offsetHeight > 0
|
||||
)
|
||||
) {
|
||||
top = top - height - field.offsetHeight;
|
||||
}
|
||||
this.el.style.cssText = 'position:absolute;left:' + left + 'px;top:' + top + 'px;';
|
||||
|
||||
this.el.style.left = left + 'px';
|
||||
this.el.style.top = top + 'px';
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -891,7 +963,7 @@
|
|||
before = new Date(year, month, 1).getDay(),
|
||||
data = [],
|
||||
row = [];
|
||||
if (!opts.showTime) setToStartOfDay(now);
|
||||
setToStartOfDay(now);
|
||||
if (opts.firstDay > 0) {
|
||||
before -= opts.firstDay;
|
||||
if (before < 0) {
|
||||
|
|
@ -907,14 +979,35 @@
|
|||
for (var i = 0, r = 0; i < cells; i++)
|
||||
{
|
||||
var day = new Date(year, month, 1 + (i - before)),
|
||||
isDisabled = (opts.minDate && day < opts.minDate) || (opts.maxDate && day > opts.maxDate),
|
||||
isSelected = isDate(this._d) ? compareDates(day, this._d) : false,
|
||||
isToday = compareDates(day, now),
|
||||
isEmpty = i < before || i >= (days + before);
|
||||
isEmpty = i < before || i >= (days + before),
|
||||
isStartRange = opts.startRange && compareDates(opts.startRange, day),
|
||||
isEndRange = opts.endRange && compareDates(opts.endRange, day),
|
||||
isInRange = opts.startRange && opts.endRange && opts.startRange < day && day < opts.endRange,
|
||||
isDisabled = (opts.minDate && day < opts.minDate) ||
|
||||
(opts.maxDate && day > opts.maxDate) ||
|
||||
(opts.disableWeekends && isWeekend(day)) ||
|
||||
(opts.disableDayFn && opts.disableDayFn(day)),
|
||||
dayConfig = {
|
||||
day: 1 + (i - before),
|
||||
month: month,
|
||||
year: year,
|
||||
isSelected: isSelected,
|
||||
isToday: isToday,
|
||||
isDisabled: isDisabled,
|
||||
isEmpty: isEmpty,
|
||||
isStartRange: isStartRange,
|
||||
isEndRange: isEndRange,
|
||||
isInRange: isInRange
|
||||
};
|
||||
|
||||
row.push(renderDay(1 + (i - before), isSelected, isToday, isDisabled, isEmpty));
|
||||
row.push(renderDay(dayConfig));
|
||||
|
||||
if (++r === 7) {
|
||||
if (opts.showWeekNumber) {
|
||||
row.unshift(renderWeek(i - before, month, year));
|
||||
}
|
||||
data.push(renderRow(row, opts.isRTL));
|
||||
row = [];
|
||||
r = 0;
|
||||
|
|
@ -951,7 +1044,9 @@
|
|||
if (this._o.bound) {
|
||||
removeEvent(document, 'click', this._onClick);
|
||||
}
|
||||
this.el.style.cssText = '';
|
||||
this.el.style.position = 'static'; // reset
|
||||
this.el.style.left = 'auto';
|
||||
this.el.style.top = 'auto';
|
||||
addClass(this.el, 'is-hidden');
|
||||
this._v = false;
|
||||
if (v !== undefined && typeof this._o.onClose === 'function') {
|
||||
|
|
@ -967,6 +1062,7 @@
|
|||
{
|
||||
this.hide();
|
||||
removeEvent(this.el, 'mousedown', this._onMouseDown, true);
|
||||
removeEvent(this.el, 'touchend', this._onMouseDown, true);
|
||||
removeEvent(this.el, 'change', this._onChange);
|
||||
if (this._o.field) {
|
||||
removeEvent(this._o.field, 'change', this._onInputChange);
|
||||
|
|
|
|||
Loading…
Reference in New Issue