/* =========================================================
* bootstrap-datetimepicker.js
* =========================================================
* Copyright 2012 Stefan Petre
*
* Improvements by Andrew Rowls
* Improvements by Sébastien Malot
* Improvements by Yun Lai
* Improvements by Kenneth Henderick
* Improvements by CuGBabyBeaR
* Improvements by Christian Vaas
*
* 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.
* ========================================================= */
!function ($) {
// Add ECMA262-5 Array methods if not supported natively (IE8)
if (!('indexOf' in Array.prototype)) {
Array.prototype.indexOf = function (find, i) {
if (i === undefined) i = 0;
if (i < 0) i += this.length;
if (i < 0) i = 0;
for (var n = this.length; i < n; i++) {
if (i in this && this[i] === find) {
return i;
}
}
return -1;
}
}
function elementOrParentIsFixed (element) {
var $element = $(element);
var $checkElements = $element.add($element.parents());
var isFixed = false;
$checkElements.each(function(){
if ($(this).css('position') === 'fixed') {
isFixed = true;
return false;
}
});
return isFixed;
}
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 : this.language.split('-')[0]; // fr-CA fallback to fr
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.clickedOutside = function (e) {
// Clicked outside the datetimepicker, hide it
if ($(e.target).closest('.datetimepicker').length === 0) {
that.hide();
}
}
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