/* =========================================================
* bootstrap-datetimepicker.js
* =========================================================
* Copyright 2012 Stefan Petre
* Improvements by Andrew Rowls
* Improvements by Sébastien Malot
* Improvements by Yun Lai
* Improvements by Kenneth Henderick
* Project URL : http://www.malot.fr/bootstrap-datetimepicker
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ========================================================= */
/*
* Improvement by CuGBabyBeaR @ 2013-09-12
*
* Make it work in bootstrap v3
*/
!function ($) {
function UTCDate() {
return new Date(Date.UTC.apply(Date, arguments));
}
function UTCToday() {
var today = new Date();
return UTCDate(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate(), today.getUTCHours(), today.getUTCMinutes(), today.getUTCSeconds(), 0);
}
// Picker object
var Datetimepicker = function (element, options) {
var that = this;
this.element = $(element);
// add container for single page application
// when page switch the datetimepicker div will be removed also.
this.container = options.container || 'body';
this.language = options.language || this.element.data('date-language') || "en";
this.language = this.language in dates ? this.language : "en";
this.isRTL = dates[this.language].rtl || false;
this.formatType = options.formatType || this.element.data('format-type') || 'standard';
this.format = DPGlobal.parseFormat(options.format || this.element.data('date-format') || dates[this.language].format || DPGlobal.getDefaultFormat(this.formatType, 'input'), this.formatType);
this.isInline = false;
this.isVisible = false;
this.isInput = this.element.is('input');
this.fontAwesome = options.fontAwesome || this.element.data('font-awesome') || false;
this.bootcssVer = options.bootcssVer || (this.isInput ? (this.element.is('.form-control') ? 3 : 2) : ( this.bootcssVer = this.element.is('.input-group') ? 3 : 2 ));
this.component = this.element.is('.date') ? ( this.bootcssVer == 3 ? this.element.find('.input-group-addon .glyphicon-th, .input-group-addon .glyphicon-time, .input-group-addon .glyphicon-calendar, .input-group-addon .glyphicon-calendar, .input-group-addon .fa-calendar, .input-group-addon .fa-clock-o').parent() : this.element.find('.add-on .icon-th, .add-on .icon-time, .add-on .icon-calendar .fa-calendar .fa-clock-o').parent()) : false;
this.componentReset = this.element.is('.date') ? ( this.bootcssVer == 3 ? this.element.find(".input-group-addon .glyphicon-remove, .input-group-addon .fa-times").parent():this.element.find(".add-on .icon-remove, .add-on .fa-times").parent()) : false;
this.hasInput = this.component && this.element.find('input').length;
if (this.component && this.component.length === 0) {
this.component = false;
}
this.linkField = options.linkField || this.element.data('link-field') || false;
this.linkFormat = DPGlobal.parseFormat(options.linkFormat || this.element.data('link-format') || DPGlobal.getDefaultFormat(this.formatType, 'link'), this.formatType);
this.minuteStep = options.minuteStep || this.element.data('minute-step') || 5;
this.pickerPosition = options.pickerPosition || this.element.data('picker-position') || 'bottom-right';
this.showMeridian = options.showMeridian || this.element.data('show-meridian') || false;
this.initialDate = options.initialDate || new Date();
this.zIndex = options.zIndex || this.element.data('z-index') || undefined;
this.icons = {
leftArrow: this.fontAwesome ? 'fa-arrow-left' : (this.bootcssVer === 3 ? 'glyphicon-arrow-left' : 'icon-arrow-left'),
rightArrow: this.fontAwesome ? 'fa-arrow-right' : (this.bootcssVer === 3 ? 'glyphicon-arrow-right' : 'icon-arrow-right')
};
this.icontype = this.fontAwesome ? 'fa' : 'glyphicon';
this._attachEvents();
this.formatViewType = "datetime";
if ('formatViewType' in options) {
this.formatViewType = options.formatViewType;
} else if ('formatViewType' in this.element.data()) {
this.formatViewType = this.element.data('formatViewType');
}
this.minView = 0;
if ('minView' in options) {
this.minView = options.minView;
} else if ('minView' in this.element.data()) {
this.minView = this.element.data('min-view');
}
this.minView = DPGlobal.convertViewMode(this.minView);
this.maxView = DPGlobal.modes.length - 1;
if ('maxView' in options) {
this.maxView = options.maxView;
} else if ('maxView' in this.element.data()) {
this.maxView = this.element.data('max-view');
}
this.maxView = DPGlobal.convertViewMode(this.maxView);
this.wheelViewModeNavigation = false;
if ('wheelViewModeNavigation' in options) {
this.wheelViewModeNavigation = options.wheelViewModeNavigation;
} else if ('wheelViewModeNavigation' in this.element.data()) {
this.wheelViewModeNavigation = this.element.data('view-mode-wheel-navigation');
}
this.wheelViewModeNavigationInverseDirection = false;
if ('wheelViewModeNavigationInverseDirection' in options) {
this.wheelViewModeNavigationInverseDirection = options.wheelViewModeNavigationInverseDirection;
} else if ('wheelViewModeNavigationInverseDirection' in this.element.data()) {
this.wheelViewModeNavigationInverseDirection = this.element.data('view-mode-wheel-navigation-inverse-dir');
}
this.wheelViewModeNavigationDelay = 100;
if ('wheelViewModeNavigationDelay' in options) {
this.wheelViewModeNavigationDelay = options.wheelViewModeNavigationDelay;
} else if ('wheelViewModeNavigationDelay' in this.element.data()) {
this.wheelViewModeNavigationDelay = this.element.data('view-mode-wheel-navigation-delay');
}
this.startViewMode = 2;
if ('startView' in options) {
this.startViewMode = options.startView;
} else if ('startView' in this.element.data()) {
this.startViewMode = this.element.data('start-view');
}
this.startViewMode = DPGlobal.convertViewMode(this.startViewMode);
this.viewMode = this.startViewMode;
this.viewSelect = this.minView;
if ('viewSelect' in options) {
this.viewSelect = options.viewSelect;
} else if ('viewSelect' in this.element.data()) {
this.viewSelect = this.element.data('view-select');
}
this.viewSelect = DPGlobal.convertViewMode(this.viewSelect);
this.forceParse = true;
if ('forceParse' in options) {
this.forceParse = options.forceParse;
} else if ('dateForceParse' in this.element.data()) {
this.forceParse = this.element.data('date-force-parse');
}
var template = this.bootcssVer === 3 ? DPGlobal.templateV3 : DPGlobal.template;
while (template.indexOf('{iconType}') !== -1) {
template = template.replace('{iconType}', this.icontype);
}
while (template.indexOf('{leftArrow}') !== -1) {
template = template.replace('{leftArrow}', this.icons.leftArrow);
}
while (template.indexOf('{rightArrow}') !== -1) {
template = template.replace('{rightArrow}', this.icons.rightArrow);
}
this.picker = $(template)
.appendTo(this.isInline ? this.element : this.container) // 'body')
.on({
click: $.proxy(this.click, this),
mousedown: $.proxy(this.mousedown, this)
});
if (this.wheelViewModeNavigation) {
if ($.fn.mousewheel) {
this.picker.on({mousewheel: $.proxy(this.mousewheel, this)});
} else {
console.log("Mouse Wheel event is not supported. Please include the jQuery Mouse Wheel plugin before enabling this option");
}
}
if (this.isInline) {
this.picker.addClass('datetimep