vendor/assets/javascripts/bootstrap-datetimepicker.js in bootstrap3-datetimepicker-rails-4.15.35 vs vendor/assets/javascripts/bootstrap-datetimepicker.js in bootstrap3-datetimepicker-rails-4.17.37
- old
+ new
@@ -1,6 +1,6 @@
-/*! version : 4.15.35
+/*! version : 4.17.37
=========================================================
bootstrap-datetimejs
https://github.com/Eonasdan/bootstrap-datetimepicker
Copyright (c) 2015 Jonathan Peterson
=========================================================
@@ -56,12 +56,12 @@
throw new Error('bootstrap-datetimepicker requires Moment.js to be loaded first');
}
var dateTimePicker = function (element, options) {
var picker = {},
- date = moment().startOf('d'),
- viewDate = date.clone(),
+ date,
+ viewDate,
unset = true,
input,
component = false,
widget = false,
use24Hours,
@@ -130,10 +130,44 @@
/********************************************************************************
*
* Private functions
*
********************************************************************************/
+ getMoment = function (d) {
+ var tzEnabled = false,
+ returnMoment,
+ currentZoneOffset,
+ incomingZoneOffset,
+ timeZoneIndicator,
+ dateWithTimeZoneInfo;
+
+ if (moment.tz !== undefined && options.timeZone !== undefined && options.timeZone !== null && options.timeZone !== '') {
+ tzEnabled = true;
+ }
+ if (d === undefined || d === null) {
+ if (tzEnabled) {
+ returnMoment = moment().tz(options.timeZone).startOf('d');
+ } else {
+ returnMoment = moment().startOf('d');
+ }
+ } else {
+ if (tzEnabled) {
+ currentZoneOffset = moment().tz(options.timeZone).utcOffset();
+ incomingZoneOffset = moment(d, parseFormats, options.useStrict).utcOffset();
+ if (incomingZoneOffset !== currentZoneOffset) {
+ timeZoneIndicator = moment().tz(options.timeZone).format('Z');
+ dateWithTimeZoneInfo = moment(d, parseFormats, options.useStrict).format('YYYY-MM-DD[T]HH:mm:ss') + timeZoneIndicator;
+ returnMoment = moment(dateWithTimeZoneInfo, parseFormats, options.useStrict).tz(options.timeZone);
+ } else {
+ returnMoment = moment(d, parseFormats, options.useStrict).tz(options.timeZone);
+ }
+ } else {
+ returnMoment = moment(d, parseFormats, options.useStrict);
+ }
+ }
+ return returnMoment;
+ },
isEnabled = function (granularity) {
if (typeof granularity !== 'string' || granularity.length > 1) {
throw new TypeError('isEnabled expects a single character string parameter');
}
switch (granularity) {
@@ -207,53 +241,53 @@
middleRow = $('<tr>'),
bottomRow = $('<tr>');
if (isEnabled('h')) {
topRow.append($('<td>')
- .append($('<a>').attr({href: '#', tabindex: '-1', 'title':'Increment Hour'}).addClass('btn').attr('data-action', 'incrementHours')
+ .append($('<a>').attr({href: '#', tabindex: '-1', 'title': options.tooltips.incrementHour}).addClass('btn').attr('data-action', 'incrementHours')
.append($('<span>').addClass(options.icons.up))));
middleRow.append($('<td>')
- .append($('<span>').addClass('timepicker-hour').attr({'data-time-component':'hours', 'title':'Pick Hour'}).attr('data-action', 'showHours')));
+ .append($('<span>').addClass('timepicker-hour').attr({'data-time-component':'hours', 'title': options.tooltips.pickHour}).attr('data-action', 'showHours')));
bottomRow.append($('<td>')
- .append($('<a>').attr({href: '#', tabindex: '-1', 'title':'Decrement Hour'}).addClass('btn').attr('data-action', 'decrementHours')
+ .append($('<a>').attr({href: '#', tabindex: '-1', 'title': options.tooltips.decrementHour}).addClass('btn').attr('data-action', 'decrementHours')
.append($('<span>').addClass(options.icons.down))));
}
if (isEnabled('m')) {
if (isEnabled('h')) {
topRow.append($('<td>').addClass('separator'));
middleRow.append($('<td>').addClass('separator').html(':'));
bottomRow.append($('<td>').addClass('separator'));
}
topRow.append($('<td>')
- .append($('<a>').attr({href: '#', tabindex: '-1', 'title':'Increment Minute'}).addClass('btn').attr('data-action', 'incrementMinutes')
+ .append($('<a>').attr({href: '#', tabindex: '-1', 'title': options.tooltips.incrementMinute}).addClass('btn').attr('data-action', 'incrementMinutes')
.append($('<span>').addClass(options.icons.up))));
middleRow.append($('<td>')
- .append($('<span>').addClass('timepicker-minute').attr({'data-time-component': 'minutes', 'title':'Pick Minute'}).attr('data-action', 'showMinutes')));
+ .append($('<span>').addClass('timepicker-minute').attr({'data-time-component': 'minutes', 'title': options.tooltips.pickMinute}).attr('data-action', 'showMinutes')));
bottomRow.append($('<td>')
- .append($('<a>').attr({href: '#', tabindex: '-1', 'title':'Decrement Minute'}).addClass('btn').attr('data-action', 'decrementMinutes')
+ .append($('<a>').attr({href: '#', tabindex: '-1', 'title': options.tooltips.decrementMinute}).addClass('btn').attr('data-action', 'decrementMinutes')
.append($('<span>').addClass(options.icons.down))));
}
if (isEnabled('s')) {
if (isEnabled('m')) {
topRow.append($('<td>').addClass('separator'));
middleRow.append($('<td>').addClass('separator').html(':'));
bottomRow.append($('<td>').addClass('separator'));
}
topRow.append($('<td>')
- .append($('<a>').attr({href: '#', tabindex: '-1', 'title':'Increment Second'}).addClass('btn').attr('data-action', 'incrementSeconds')
+ .append($('<a>').attr({href: '#', tabindex: '-1', 'title': options.tooltips.incrementSecond}).addClass('btn').attr('data-action', 'incrementSeconds')
.append($('<span>').addClass(options.icons.up))));
middleRow.append($('<td>')
- .append($('<span>').addClass('timepicker-second').attr({'data-time-component': 'seconds', 'title':'Pick Second'}).attr('data-action', 'showSeconds')));
+ .append($('<span>').addClass('timepicker-second').attr({'data-time-component': 'seconds', 'title': options.tooltips.pickSecond}).attr('data-action', 'showSeconds')));
bottomRow.append($('<td>')
- .append($('<a>').attr({href: '#', tabindex: '-1', 'title':'Decrement Second'}).addClass('btn').attr('data-action', 'decrementSeconds')
+ .append($('<a>').attr({href: '#', tabindex: '-1', 'title': options.tooltips.decrementSecond}).addClass('btn').attr('data-action', 'decrementSeconds')
.append($('<span>').addClass(options.icons.down))));
}
if (!use24Hours) {
topRow.append($('<td>').addClass('separator'));
middleRow.append($('<td>')
- .append($('<button>').addClass('btn btn-primary').attr({'data-action': 'togglePeriod', tabindex: '-1', 'title':'Toggle Period'})));
+ .append($('<button>').addClass('btn btn-primary').attr({'data-action': 'togglePeriod', tabindex: '-1', 'title': options.tooltips.togglePeriod})));
bottomRow.append($('<td>').addClass('separator'));
}
return $('<div>').addClass('timepicker-picker')
.append($('<table>').addClass('table-condensed')
@@ -286,11 +320,11 @@
var row = [];
if (options.showTodayButton) {
row.push($('<td>').append($('<a>').attr({'data-action':'today', 'title': options.tooltips.today}).append($('<span>').addClass(options.icons.today))));
}
if (!options.sideBySide && hasDate() && hasTime()) {
- row.push($('<td>').append($('<a>').attr({'data-action':'togglePicker', 'title':'Select Time'}).append($('<span>').addClass(options.icons.time))));
+ row.push($('<td>').append($('<a>').attr({'data-action':'togglePicker', 'title': options.tooltips.selectTime}).append($('<span>').addClass(options.icons.time))));
}
if (options.showClear) {
row.push($('<td>').append($('<a>').attr({'data-action':'clear', 'title': options.tooltips.clear}).append($('<span>').addClass(options.icons.clear))));
}
if (options.showClose) {
@@ -591,13 +625,13 @@
yearsViewHeader = yearsView.find('th'),
startYear = viewDate.clone().subtract(5, 'y'),
endYear = viewDate.clone().add(6, 'y'),
html = '';
- yearsViewHeader.eq(0).find('span').attr('title', options.tooltips.nextDecade);
+ yearsViewHeader.eq(0).find('span').attr('title', options.tooltips.prevDecade);
yearsViewHeader.eq(1).attr('title', options.tooltips.selectDecade);
- yearsViewHeader.eq(2).find('span').attr('title', options.tooltips.prevDecade);
+ yearsViewHeader.eq(2).find('span').attr('title', options.tooltips.nextDecade);
yearsView.find('.disabled').removeClass('disabled');
if (options.minDate && options.minDate.isAfter(startYear, 'y')) {
yearsViewHeader.eq(0).addClass('disabled');
@@ -618,12 +652,13 @@
},
updateDecades = function () {
var decadesView = widget.find('.datepicker-decades'),
decadesViewHeader = decadesView.find('th'),
- startDecade = viewDate.isBefore(moment({y: 1999})) ? moment({y: 1899}) : moment({y: 1999}),
+ startDecade = moment({y: viewDate.year() - (viewDate.year() % 100) - 1}),
endDecade = startDecade.clone().add(100, 'y'),
+ startedAt = startDecade.clone(),
html = '';
decadesViewHeader.eq(0).find('span').attr('title', options.tooltips.prevCentury);
decadesViewHeader.eq(2).find('span').attr('title', options.tooltips.nextCentury);
@@ -645,10 +680,11 @@
startDecade.add(12, 'y');
}
html += '<span></span><span></span><span></span>'; //push the dangling block over, at least this way it's even
decadesView.find('td').html(html);
+ decadesViewHeader.eq(1).text((startedAt.year() + 1) + '-' + (startDecade.year()));
},
fillDate = function () {
var daysView = widget.find('.datepicker-days'),
daysViewHeader = daysView.find('th'),
@@ -697,11 +733,11 @@
clsName += ' active';
}
if (!isValid(currentDate, 'd')) {
clsName += ' disabled';
}
- if (currentDate.isSame(moment(), 'd')) {
+ if (currentDate.isSame(getMoment(), 'd')) {
clsName += ' today';
}
if (currentDate.day() === 0 || currentDate.day() === 6) {
clsName += ' weekend';
}
@@ -1106,12 +1142,13 @@
},
clear: clear,
today: function () {
- if (isValid(moment(), 'd')) {
- setValue(moment());
+ var todaysDate = getMoment();
+ if (isValid(todaysDate, 'd')) {
+ setValue(todaysDate);
}
},
close: hide
},
@@ -1149,11 +1186,11 @@
return picker;
}
if (input.val() !== undefined && input.val().trim().length !== 0) {
setValue(parseInputDate(input.val().trim()));
} else if (options.useCurrent && unset && ((input.is('input') && input.val().trim().length === 0) || options.inline)) {
- currentMoment = moment();
+ currentMoment = getMoment();
if (typeof options.useCurrent === 'string') {
currentMoment = useCurrentGranularity[options.useCurrent](currentMoment);
}
setValue(currentMoment);
}
@@ -1198,11 +1235,11 @@
parseInputDate = function (inputDate) {
if (options.parseInputDate === undefined) {
if (moment.isMoment(inputDate) || inputDate instanceof Date) {
inputDate = moment(inputDate);
} else {
- inputDate = moment(inputDate, parseFormats, options.useStrict);
+ inputDate = getMoment(inputDate);
}
} else {
inputDate = options.parseInputDate(inputDate);
}
inputDate.locale(options.locale);
@@ -1484,10 +1521,20 @@
initFormatting(); // reinit formatting
}
return picker;
};
+ picker.timeZone = function (newZone) {
+ if (arguments.length === 0) {
+ return options.timeZone;
+ }
+
+ options.timeZone = newZone;
+
+ return picker;
+ };
+
picker.dayViewHeaderFormat = function (newFormat) {
if (arguments.length === 0) {
return options.dayViewHeaderFormat;
}
@@ -1620,11 +1667,11 @@
return picker;
}
if (typeof maxDate === 'string') {
if (maxDate === 'now' || maxDate === 'moment') {
- maxDate = moment();
+ maxDate = getMoment();
}
}
var parsedDate = parseInputDate(maxDate);
@@ -1656,11 +1703,11 @@
return picker;
}
if (typeof minDate === 'string') {
if (minDate === 'now' || minDate === 'moment') {
- minDate = moment();
+ minDate = getMoment();
}
}
var parsedDate = parseInputDate(minDate);
@@ -1698,11 +1745,11 @@
return picker;
}
if (typeof defaultDate === 'string') {
if (defaultDate === 'now' || defaultDate === 'moment') {
- defaultDate = moment();
+ defaultDate = getMoment();
}
}
var parsedDate = parseInputDate(defaultDate);
if (!parsedDate.isValid()) {
@@ -1712,11 +1759,11 @@
throw new TypeError('defaultDate() date passed is invalid according to component setup validations');
}
options.defaultDate = parsedDate;
- if (options.defaultDate && options.inline || (input.val().trim() === '' && input.attr('placeholder') === undefined)) {
+ if ((options.defaultDate && options.inline) || input.val().trim() === '') {
setValue(options.defaultDate);
}
return picker;
};
@@ -2039,10 +2086,14 @@
picker.keyBinds = function (keyBinds) {
options.keyBinds = keyBinds;
return picker;
};
+ picker.getMoment = function (d) {
+ return getMoment(d);
+ };
+
picker.debug = function (debug) {
if (typeof debug !== 'boolean') {
throw new TypeError('debug() expects a boolean parameter');
}
@@ -2269,10 +2320,14 @@
if (!options.inline && !input.is('input')) {
throw new Error('Could not initialize DateTimePicker without an input element');
}
+ // Set defaults for date here now instead of in var declaration
+ date = getMoment();
+ viewDate = date.clone();
+
$.extend(true, options, dataToOptions());
picker.options(options);
initFormatting();
@@ -2310,10 +2365,11 @@
}
});
};
$.fn.datetimepicker.defaults = {
+ timeZone: 'Etc/UTC',
format: false,
dayViewHeaderFormat: 'MMMM YYYY',
extraFormats: false,
stepping: 1,
minDate: false,
@@ -2347,11 +2403,22 @@
nextYear: 'Next Year',
selectDecade: 'Select Decade',
prevDecade: 'Previous Decade',
nextDecade: 'Next Decade',
prevCentury: 'Previous Century',
- nextCentury: 'Next Century'
+ nextCentury: 'Next Century',
+ pickHour: 'Pick Hour',
+ incrementHour: 'Increment Hour',
+ decrementHour: 'Decrement Hour',
+ pickMinute: 'Pick Minute',
+ incrementMinute: 'Increment Minute',
+ decrementMinute: 'Decrement Minute',
+ pickSecond: 'Pick Second',
+ incrementSecond: 'Increment Second',
+ decrementSecond: 'Decrement Second',
+ togglePeriod: 'Toggle Period',
+ selectTime: 'Select Time'
},
useStrict: false,
sideBySide: false,
daysOfWeekDisabled: false,
calendarWeeks: false,
@@ -2374,11 +2441,11 @@
keyBinds: {
up: function (widget) {
if (!widget) {
return;
}
- var d = this.date() || moment();
+ var d = this.date() || this.getMoment();
if (widget.find('.datepicker').is(':visible')) {
this.date(d.clone().subtract(7, 'd'));
} else {
this.date(d.clone().add(this.stepping(), 'm'));
}
@@ -2386,71 +2453,71 @@
down: function (widget) {
if (!widget) {
this.show();
return;
}
- var d = this.date() || moment();
+ var d = this.date() || this.getMoment();
if (widget.find('.datepicker').is(':visible')) {
this.date(d.clone().add(7, 'd'));
} else {
this.date(d.clone().subtract(this.stepping(), 'm'));
}
},
'control up': function (widget) {
if (!widget) {
return;
}
- var d = this.date() || moment();
+ var d = this.date() || this.getMoment();
if (widget.find('.datepicker').is(':visible')) {
this.date(d.clone().subtract(1, 'y'));
} else {
this.date(d.clone().add(1, 'h'));
}
},
'control down': function (widget) {
if (!widget) {
return;
}
- var d = this.date() || moment();
+ var d = this.date() || this.getMoment();
if (widget.find('.datepicker').is(':visible')) {
this.date(d.clone().add(1, 'y'));
} else {
this.date(d.clone().subtract(1, 'h'));
}
},
left: function (widget) {
if (!widget) {
return;
}
- var d = this.date() || moment();
+ var d = this.date() || this.getMoment();
if (widget.find('.datepicker').is(':visible')) {
this.date(d.clone().subtract(1, 'd'));
}
},
right: function (widget) {
if (!widget) {
return;
}
- var d = this.date() || moment();
+ var d = this.date() || this.getMoment();
if (widget.find('.datepicker').is(':visible')) {
this.date(d.clone().add(1, 'd'));
}
},
pageUp: function (widget) {
if (!widget) {
return;
}
- var d = this.date() || moment();
+ var d = this.date() || this.getMoment();
if (widget.find('.datepicker').is(':visible')) {
this.date(d.clone().subtract(1, 'M'));
}
},
pageDown: function (widget) {
if (!widget) {
return;
}
- var d = this.date() || moment();
+ var d = this.date() || this.getMoment();
if (widget.find('.datepicker').is(':visible')) {
this.date(d.clone().add(1, 'M'));
}
},
enter: function () {
@@ -2467,10 +2534,10 @@
if (widget.find('.timepicker').is(':visible')) {
widget.find('.btn[data-action="togglePeriod"]').click();
}
},
t: function () {
- this.date(moment());
+ this.date(this.getMoment());
},
'delete': function () {
this.clear();
}
},