');
}
if (moment().localedata()._week.dow === 0) { // starts on sunday
for (i = 0; i < 7; i++) {
html.append('
' + weekdaysmin[i] + '
');
}
} else {
for (i = 1; i < 8; i++) {
if (i === 7) {
html.append('
' + weekdaysmin[0] + '
');
} else {
html.append('
' + weekdaysmin[i] + '
');
}
}
}
picker.widget.find('.datepicker-days thead').append(html);
},
fillmonths = function () {
moment.locale(picker.options.language);
var html = '', i, monthsshort = moment.monthsshort();
for (i = 0; i < 12; i++) {
html += '' + monthsshort[i] + '';
}
picker.widget.find('.datepicker-months td').append(html);
},
filldate = function () {
if (!picker.options.pickdate) {
return;
}
moment.locale(picker.options.language);
var year = picker.viewdate.year(),
month = picker.viewdate.month(),
startyear = picker.options.mindate.year(),
startmonth = picker.options.mindate.month(),
endyear = picker.options.maxdate.year(),
endmonth = picker.options.maxdate.month(),
currentdate,
prevmonth, nextmonth, html = [], row, clsname, i, days, yearcont, currentyear, months = moment.months();
picker.widget.find('.datepicker-days').find('.disabled').removeclass('disabled');
picker.widget.find('.datepicker-months').find('.disabled').removeclass('disabled');
picker.widget.find('.datepicker-years').find('.disabled').removeclass('disabled');
picker.widget.find('.datepicker-days th:eq(1)').text(
months[month] + ' ' + year);
prevmonth = moment(picker.viewdate, picker.format, picker.options.usestrict).subtract(1, 'months');
days = prevmonth.daysinmonth();
prevmonth.date(days).startof('week');
if ((year === startyear && month <= startmonth) || year < startyear) {
picker.widget.find('.datepicker-days th:eq(0)').addclass('disabled');
}
if ((year === endyear && month >= endmonth) || year > endyear) {
picker.widget.find('.datepicker-days th:eq(2)').addclass('disabled');
}
nextmonth = moment(prevmonth).add(42, 'd');
while (prevmonth.isbefore(nextmonth)) {
if (prevmonth.weekday() === moment().startof('week').weekday()) {
row = $('
');
html.push(row);
if (picker.options.calendarweeks === true) {
row.append('
' + prevmonth.week() + '
');
}
}
clsname = '';
if (prevmonth.year() < year || (prevmonth.year() === year && prevmonth.month() < month)) {
clsname += ' old';
} else if (prevmonth.year() > year || (prevmonth.year() === year && prevmonth.month() > month)) {
clsname += ' new';
}
if (prevmonth.issame(moment({y: picker.date.year(), m: picker.date.month(), d: picker.date.date()}))) {
clsname += ' active';
}
if (isindisabledates(prevmonth, 'day') || !isinenabledates(prevmonth)) {
clsname += ' disabled';
}
if (picker.options.showtoday === true) {
if (prevmonth.issame(moment(), 'day')) {
clsname += ' today';
}
}
if (picker.options.daysofweekdisabled) {
for (i = 0; i < picker.options.daysofweekdisabled.length; i++) {
if (prevmonth.day() === picker.options.daysofweekdisabled[i]) {
clsname += ' disabled';
break;
}
}
}
row.append('
' + prevmonth.date() + '
');
currentdate = prevmonth.date();
prevmonth.add(1, 'd');
if (currentdate === prevmonth.date()) {
prevmonth.add(1, 'd');
}
}
picker.widget.find('.datepicker-days tbody').empty().append(html);
currentyear = picker.date.year();
months = picker.widget.find('.datepicker-months').find('th:eq(1)').text(year).end().find('span').removeclass('active');
if (currentyear === year) {
months.eq(picker.date.month()).addclass('active');
}
if (year - 1 < startyear) {
picker.widget.find('.datepicker-months th:eq(0)').addclass('disabled');
}
if (year + 1 > endyear) {
picker.widget.find('.datepicker-months th:eq(2)').addclass('disabled');
}
for (i = 0; i < 12; i++) {
if ((year === startyear && startmonth > i) || (year < startyear)) {
$(months[i]).addclass('disabled');
} else if ((year === endyear && endmonth < i) || (year > endyear)) {
$(months[i]).addclass('disabled');
}
}
html = '';
year = parseint(year / 10, 10) * 10;
yearcont = picker.widget.find('.datepicker-years').find(
'th:eq(1)').text(year + '-' + (year + 9)).parents('table').find('td');
picker.widget.find('.datepicker-years').find('th').removeclass('disabled');
if (startyear > year) {
picker.widget.find('.datepicker-years').find('th:eq(0)').addclass('disabled');
}
if (endyear < year + 9) {
picker.widget.find('.datepicker-years').find('th:eq(2)').addclass('disabled');
}
year -= 1;
for (i = -1; i < 11; i++) {
html += '' + year + '';
year += 1;
}
yearcont.html(html);
},
fillhours = function () {
moment.locale(picker.options.language);
var table = picker.widget.find('.timepicker .timepicker-hours table'), html = '', current, i, j;
table.parent().hide();
if (picker.use24hours) {
current = 0;
for (i = 0; i < 6; i += 1) {
html += '
';
for (j = 0; j < 4; j += 1) {
html += '
' + padleft(current.tostring()) + '
';
current++;
}
html += '
';
}
}
else {
current = 1;
for (i = 0; i < 3; i += 1) {
html += '
';
for (j = 0; j < 4; j += 1) {
html += '
' + padleft(current.tostring()) + '
';
current++;
}
html += '
';
}
}
table.html(html);
},
fillminutes = function () {
var table = picker.widget.find('.timepicker .timepicker-minutes table'), html = '', current = 0, i, j, step = picker.options.minutestepping;
table.parent().hide();
if (step === 1) {
step = 5;
}
for (i = 0; i < math.ceil(60 / step / 4) ; i++) {
html += '
';
for (j = 0; j < 4; j += 1) {
if (current < 60) {
html += '
' + padleft(current.tostring()) + '
';
current += step;
} else {
html += '
';
}
}
html += '
';
}
table.html(html);
},
fillseconds = function () {
var table = picker.widget.find('.timepicker .timepicker-seconds table'), html = '', current = 0, i, j;
table.parent().hide();
for (i = 0; i < 3; i++) {
html += '
';
for (j = 0; j < 4; j += 1) {
html += '
' + padleft(current.tostring()) + '
';
current += 5;
}
html += '
';
}
table.html(html);
},
filltime = function () {
if (!picker.date) {
return;
}
var timecomponents = picker.widget.find('.timepicker span[data-time-component]'),
hour = picker.date.hours(),
period = picker.date.format('a');
if (!picker.use24hours) {
if (hour === 0) {
hour = 12;
} else if (hour !== 12) {
hour = hour % 12;
}
picker.widget.find('.timepicker [data-action=toggleperiod]').text(period);
}
timecomponents.filter('[data-time-component=hours]').text(padleft(hour));
timecomponents.filter('[data-time-component=minutes]').text(padleft(picker.date.minutes()));
timecomponents.filter('[data-time-component=seconds]').text(padleft(picker.date.second()));
},
click = function (e) {
e.stoppropagation();
e.preventdefault();
picker.unset = false;
var target = $(e.target).closest('span, td, th'), month, year, step, day, olddate = moment(picker.date);
if (target.length === 1) {
if (!target.is('.disabled')) {
switch (target[0].nodename.tolowercase()) {
case 'th':
switch (target[0].classname) {
case 'picker-switch':
showmode(1);
break;
case 'prev':
case 'next':
step = dpglobal.modes[picker.viewmode].navstep;
if (target[0].classname === 'prev') {
step = step * -1;
}
picker.viewdate.add(step, dpglobal.modes[picker.viewmode].navfnc);
filldate();
break;
}
break;
case 'span':
if (target.is('.month')) {
month = target.parent().find('span').index(target);
picker.viewdate.month(month);
} else {
year = parseint(target.text(), 10) || 0;
picker.viewdate.year(year);
}
if (picker.viewmode === picker.minviewmode) {
picker.date = moment({
y: picker.viewdate.year(),
m: picker.viewdate.month(),
d: picker.viewdate.date(),
h: picker.date.hours(),
m: picker.date.minutes(),
s: picker.date.seconds()
});
set();
notifychange(olddate, e.type);
}
showmode(-1);
filldate();
break;
case 'td':
if (target.is('.day')) {
day = parseint(target.text(), 10) || 1;
month = picker.viewdate.month();
year = picker.viewdate.year();
if (target.is('.old')) {
if (month === 0) {
month = 11;
year -= 1;
} else {
month -= 1;
}
} else if (target.is('.new')) {
if (month === 11) {
month = 0;
year += 1;
} else {
month += 1;
}
}
picker.date = moment({
y: year,
m: month,
d: day,
h: picker.date.hours(),
m: picker.date.minutes(),
s: picker.date.seconds()
}
);
picker.viewdate = moment({
y: year, m: month, d: math.min(28, day)
});
filldate();
set();
notifychange(olddate, e.type);
}
break;
}
}
}
},
actions = {
incrementhours: function () {
checkdate('add', 'hours', 1);
},
incrementminutes: function () {
checkdate('add', 'minutes', picker.options.minutestepping);
},
incrementseconds: function () {
checkdate('add', 'seconds', 1);
},
decrementhours: function () {
checkdate('subtract', 'hours', 1);
},
decrementminutes: function () {
checkdate('subtract', 'minutes', picker.options.minutestepping);
},
decrementseconds: function () {
checkdate('subtract', 'seconds', 1);
},
toggleperiod: function () {
var hour = picker.date.hours();
if (hour >= 12) {
hour -= 12;
} else {
hour += 12;
}
picker.date.hours(hour);
},
showpicker: function () {
picker.widget.find('.timepicker > div:not(.timepicker-picker)').hide();
picker.widget.find('.timepicker .timepicker-picker').show();
},
showhours: function () {
picker.widget.find('.timepicker .timepicker-picker').hide();
picker.widget.find('.timepicker .timepicker-hours').show();
},
showminutes: function () {
picker.widget.find('.timepicker .timepicker-picker').hide();
picker.widget.find('.timepicker .timepicker-minutes').show();
},
showseconds: function () {
picker.widget.find('.timepicker .timepicker-picker').hide();
picker.widget.find('.timepicker .timepicker-seconds').show();
},
selecthour: function (e) {
var hour = parseint($(e.target).text(), 10);
if (!picker.use24hours) {
if (picker.date.hours() >= 12) {
if (hour !== 12) {
hour += 12;
}
} else {
if (hour === 12) {
hour = 0;
}
}
}
picker.date.hours(hour);
actions.showpicker.call(picker);
},
selectminute: function (e) {
picker.date.minutes(parseint($(e.target).text(), 10));
actions.showpicker.call(picker);
},
selectsecond: function (e) {
picker.date.seconds(parseint($(e.target).text(), 10));
actions.showpicker.call(picker);
}
},
doaction = function (e) {
var olddate = moment(picker.date),
action = $(e.currenttarget).data('action'),
rv = actions[action].apply(picker, arguments);
stopevent(e);
if (!picker.date) {
picker.date = moment({y: 1970});
}
set();
filltime();
notifychange(olddate, e.type);
return rv;
},
stopevent = function (e) {
e.stoppropagation();
e.preventdefault();
},
keydown = function (e) {
if (e.keycode === 27) { // allow escape to hide picker
picker.hide();
}
},
change = function (e) {
moment.locale(picker.options.language);
var input = $(e.target), olddate = moment(picker.date), newdate = moment(input.val(), picker.format, picker.options.usestrict);
if (newdate.isvalid() && !isindisabledates(newdate) && isinenabledates(newdate)) {
update();
picker.setvalue(newdate);
notifychange(olddate, e.type);
set();
}
else {
picker.viewdate = olddate;
picker.unset = true;
notifychange(olddate, e.type);
notifyerror(newdate);
}
},
showmode = function (dir) {
if (dir) {
picker.viewmode = math.max(picker.minviewmode, math.min(2, picker.viewmode + dir));
}
picker.widget.find('.datepicker > div').hide().filter('.datepicker-' + dpglobal.modes[picker.viewmode].clsname).show();
},
attachdatepickerevents = function () {
var $this, $parent, expanded, closed, collapsedata;
picker.widget.on('click', '.datepicker *', $.proxy(click, this)); // this handles date picker clicks
picker.widget.on('click', '[data-action]', $.proxy(doaction, this)); // this handles time picker clicks
picker.widget.on('mousedown', $.proxy(stopevent, this));
picker.element.on('keydown', $.proxy(keydown, this));
if (picker.options.pickdate && picker.options.picktime) {
picker.widget.on('click.togglepicker', '.accordion-toggle', function (e) {
e.stoppropagation();
$this = $(this);
$parent = $this.closest('ul');
expanded = $parent.find('.in');
closed = $parent.find('.collapse:not(.in)');
if (expanded && expanded.length) {
collapsedata = expanded.data('collapse');
if (collapsedata && collapsedata.transitioning) {
return;
}
expanded.collapse('hide');
closed.collapse('show');
$this.find('span').toggleclass(picker.options.icons.time + ' ' + picker.options.icons.date);
if (picker.component) {
picker.component.find('span').toggleclass(picker.options.icons.time + ' ' + picker.options.icons.date);
}
}
});
}
if (picker.isinput) {
picker.element.on({
'click': $.proxy(picker.show, this),
'focus': $.proxy(picker.show, this),
'change': $.proxy(change, this),
'blur': $.proxy(picker.hide, this)
});
} else {
picker.element.on({
'change': $.proxy(change, this)
}, 'input');
if (picker.component) {
picker.component.on('click', $.proxy(picker.show, this));
picker.component.on('mousedown', $.proxy(stopevent, this));
} else {
picker.element.on('click', $.proxy(picker.show, this));
}
}
},
attachdatepickerglobalevents = function () {
$(window).on(
'resize.datetimepicker' + picker.id, $.proxy(place, this));
if (!picker.isinput) {
$(document).on(
'mousedown.datetimepicker' + picker.id, $.proxy(picker.hide, this));
}
},
detachdatepickerevents = function () {
picker.widget.off('click', '.datepicker *', picker.click);
picker.widget.off('click', '[data-action]');
picker.widget.off('mousedown', picker.stopevent);
if (picker.options.pickdate && picker.options.picktime) {
picker.widget.off('click.togglepicker');
}
if (picker.isinput) {
picker.element.off({
'focus': picker.show,
'change': change,
'click': picker.show,
'blur' : picker.hide
});
} else {
picker.element.off({
'change': change
}, 'input');
if (picker.component) {
picker.component.off('click', picker.show);
picker.component.off('mousedown', picker.stopevent);
} else {
picker.element.off('click', picker.show);
}
}
},
detachdatepickerglobalevents = function () {
$(window).off('resize.datetimepicker' + picker.id);
if (!picker.isinput) {
$(document).off('mousedown.datetimepicker' + picker.id);
}
},
isinfixed = function () {
if (picker.element) {
var parents = picker.element.parents(), infixed = false, i;
for (i = 0; i < parents.length; i++) {
if ($(parents[i]).css('position') === 'fixed') {
infixed = true;
break;
}
}
return infixed;
} else {
return false;
}
},
set = function () {
moment.locale(picker.options.language);
var formatted = '';
if (!picker.unset) {
formatted = moment(picker.date).format(picker.format);
}
getpickerinput().val(formatted);
picker.element.data('date', formatted);
if (!picker.options.picktime) {
picker.hide();
}
},
checkdate = function (direction, unit, amount) {
moment.locale(picker.options.language);
var newdate;
if (direction === 'add') {
newdate = moment(picker.date);
if (newdate.hours() === 23) {
newdate.add(amount, unit);
}
newdate.add(amount, unit);
}
else {
newdate = moment(picker.date).subtract(amount, unit);
}
if (isindisabledates(moment(newdate.subtract(amount, unit))) || isindisabledates(newdate)) {
notifyerror(newdate.format(picker.format));
return;
}
if (direction === 'add') {
picker.date.add(amount, unit);
}
else {
picker.date.subtract(amount, unit);
}
picker.unset = false;
},
isindisabledates = function (date, timeunit) {
moment.locale(picker.options.language);
var maxdate = moment(picker.options.maxdate, picker.format, picker.options.usestrict),
mindate = moment(picker.options.mindate, picker.format, picker.options.usestrict);
if (timeunit) {
maxdate = maxdate.endof(timeunit);
mindate = mindate.startof(timeunit);
}
if (date.isafter(maxdate) || date.isbefore(mindate)) {
return true;
}
if (picker.options.disableddates === false) {
return false;
}
return picker.options.disableddates[date.format('yyyy-mm-dd')] === true;
},
isinenabledates = function (date) {
moment.locale(picker.options.language);
if (picker.options.enableddates === false) {
return true;
}
return picker.options.enableddates[date.format('yyyy-mm-dd')] === true;
},
indexgivendates = function (givendatesarray) {
// store given enableddates and disableddates as keys.
// this way we can check their existence in o(1) time instead of looping through whole array.
// (for example: picker.options.enableddates['2014-02-27'] === true)
var givendatesindexed = {}, givendatescount = 0, i;
for (i = 0; i < givendatesarray.length; i++) {
if (moment.ismoment(givendatesarray[i]) || givendatesarray[i] instanceof date) {
ddate = moment(givendatesarray[i]);
} else {
ddate = moment(givendatesarray[i], picker.format, picker.options.usestrict);
}
if (ddate.isvalid()) {
givendatesindexed[ddate.format('yyyy-mm-dd')] = true;
givendatescount++;
}
}
if (givendatescount > 0) {
return givendatesindexed;
}
return false;
},
padleft = function (string) {
string = string.tostring();
if (string.length >= 2) {
return string;
}
return '0' + string;
},
gettemplate = function () {
var
headtemplate =
'' +
'
' +
'
‹
›
' +
'
' +
'',
conttemplate =
'
',
template = '
' +
'
' + headtemplate + '
' +
'
' +
'
' +
'
' + headtemplate + conttemplate + '
' +
'
' +
'
' +
'
' + headtemplate + conttemplate + '
' +
'
',
ret = '';
if (picker.options.pickdate && picker.options.picktime) {
ret = '
';
if (picker.options.sidebyside) {
ret += '
' +
'
' + template + '
' +
'
' + tpglobal.gettemplate() + '
' +
'
';
} else {
ret += '
' +
'
' +
'
' + template + '
' +
'
' +
'
' +
'
' +
'
' + tpglobal.gettemplate() + '
' +
'
' +
'
';
}
ret += '
';
return ret;
}
if (picker.options.picktime) {
return (
'