/* ========================================================= * 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(factory){ if (typeof define === 'function' && define.amd) define(['jquery'], factory); else if (typeof exports === 'object') factory(require('jquery')); else factory(jquery); }(function($, undefined){ // 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; } } // add timezone abbreviation support for ie6+, chrome, firefox function timezoneabbreviation() { var abbreviation, date, formattedstr, i, len, matchedstrings, ref, str; date = (new date()).tostring(); formattedstr = ((ref = date.split('(')[1]) != null ? ref.slice(0, -1) : 0) || date.split(' '); if (formattedstr instanceof array) { matchedstrings = []; for (var i = 0, len = formattedstr.length; i < len; i++) { str = formattedstr[i]; if ((abbreviation = (ref = str.match(/\b[a-z]+\b/)) !== null) ? ref[0] : 0) { matchedstrings.push(abbreviation); } } formattedstr = matchedstrings.pop(); } return formattedstr; } function utcdate() { return new date(date.utc.apply(date, arguments)); } // 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-remove, .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, .add-on .fa-calendar, .add-on .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.title = typeof options.title === 'undefined' ? false : options.title; this.timezone = options.timezone || timezoneabbreviation(); 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.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('datetimepicker-inline'); } else { this.picker.addclass('datetimepicker-dropdown-' + this.pickerposition + ' dropdown-menu'); } if (this.isrtl) { this.picker.addclass('datetimepicker-rtl'); var selector = this.bootcssver === 3 ? '.prev span, .next span' : '.prev i, .next i'; this.picker.find(selector).toggleclass(this.icons.leftarrow + ' ' + this.icons.rightarrow); } $(document).on('mousedown touchend', this.clickedoutside); this.autoclose = false; if ('autoclose' in options) { this.autoclose = options.autoclose; } else if ('dateautoclose' in this.element.data()) { this.autoclose = this.element.data('date-autoclose'); } this.keyboardnavigation = true; if ('keyboardnavigation' in options) { this.keyboardnavigation = options.keyboardnavigation; } else if ('datekeyboardnavigation' in this.element.data()) { this.keyboardnavigation = this.element.data('date-keyboard-navigation'); } this.todaybtn = (options.todaybtn || this.element.data('date-today-btn') || false); this.clearbtn = (options.clearbtn || this.element.data('date-clear-btn') || false); this.todayhighlight = (options.todayhighlight || this.element.data('date-today-highlight') || false); this.weekstart = 0; if (typeof options.weekstart !== 'undefined') { this.weekstart = options.weekstart; } else if (typeof this.element.data('date-weekstart') !== 'undefined') { this.weekstart = this.element.data('date-weekstart'); } else if (typeof dates[this.language].weekstart !== 'undefined') { this.weekstart = dates[this.language].weekstart; } this.weekstart = this.weekstart % 7; this.weekend = ((this.weekstart + 6) % 7); this.onrenderday = function (date) { var render = (options.onrenderday || function () { return []; })(date); if (typeof render === 'string') { render = [render]; } var res = ['day']; return res.concat((render ? render : [])); }; this.onrenderhour = function (date) { var render = (options.onrenderhour || function () { return []; })(date); var res = ['hour']; if (typeof render === 'string') { render = [render]; } return res.concat((render ? render : [])); }; this.onrenderminute = function (date) { var render = (options.onrenderminute || function () { return []; })(date); var res = ['minute']; if (typeof render === 'string') { render = [render]; } if (date < this.startdate || date > this.enddate) { res.push('disabled'); } else if (math.floor(this.date.getutcminutes() / this.minutestep) === math.floor(date.getutcminutes() / this.minutestep)) { res.push('active'); } return res.concat((render ? render : [])); }; this.onrenderyear = function (date) { var render = (options.onrenderyear || function () { return []; })(date); var res = ['year']; if (typeof render === 'string') { render = [render]; } if (this.date.getutcfullyear() === date.getutcfullyear()) { res.push('active'); } var currentyear = date.getutcfullyear(); var endyear = this.enddate.getutcfullyear(); if (date < this.startdate || currentyear > endyear) { res.push('disabled'); } return res.concat((render ? render : [])); } this.onrendermonth = function (date) { var render = (options.onrendermonth || function () { return []; })(date); var res = ['month']; if (typeof render === 'string') { render = [render]; } return res.concat((render ? render : [])); } this.startdate = new date(-8639968443048000); this.enddate = new date(8639968443048000); this.datesdisabled = []; this.daysofweekdisabled = []; this.setstartdate(options.startdate || this.element.data('date-startdate')); this.setenddate(options.enddate || this.element.data('date-enddate')); this.setdatesdisabled(options.datesdisabled || this.element.data('date-dates-disabled')); this.setdaysofweekdisabled(options.daysofweekdisabled || this.element.data('date-days-of-week-disabled')); this.setminutesdisabled(options.minutesdisabled || this.element.data('date-minute-disabled')); this.sethoursdisabled(options.hoursdisabled || this.element.data('date-hour-disabled')); this.filldow(); this.fillmonths(); this.update(); this.showmode(); if (this.isinline) { this.show(); } }; datetimepicker.prototype = { constructor: datetimepicker, _events: [], _attachevents: function () { this._detachevents(); if (this.isinput) { // single input this._events = [ [this.element, { focus: $.proxy(this.show, this), keyup: $.proxy(this.update, this), keydown: $.proxy(this.keydown, this) }] ]; } else if (this.component && this.hasinput) { // component: input + button this._events = [ // for components that are not readonly, allow keyboard nav [this.element.find('input'), { focus: $.proxy(this.show, this), keyup: $.proxy(this.update, this), keydown: $.proxy(this.keydown, this) }], [this.component, { click: $.proxy(this.show, this) }] ]; if (this.componentreset) { this._events.push([ this.componentreset, {click: $.proxy(this.reset, this)} ]); } } else if (this.element.is('div')) { // inline datetimepicker this.isinline = true; } else { this._events = [ [this.element, { click: $.proxy(this.show, this) }] ]; } for (var i = 0, el, ev; i < this._events.length; i++) { el = this._events[i][0]; ev = this._events[i][1]; el.on(ev); } }, _detachevents: function () { for (var i = 0, el, ev; i < this._events.length; i++) { el = this._events[i][0]; ev = this._events[i][1]; el.off(ev); } this._events = []; }, show: function (e) { this.picker.show(); this.height = this.component ? this.component.outerheight() : this.element.outerheight(); if (this.forceparse) { this.update(); } this.place(); $(window).on('resize', $.proxy(this.place, this)); if (e) { e.stoppropagation(); e.preventdefault(); } this.isvisible = true; this.element.trigger({ type: 'show', date: this.date }); }, hide: function () { if (!this.isvisible) return; if (this.isinline) return; this.picker.hide(); $(window).off('resize', this.place); this.viewmode = this.startviewmode; this.showmode(); if (!this.isinput) { $(document).off('mousedown', this.hide); } if ( this.forceparse && ( this.isinput && this.element.val() || this.hasinput && this.element.find('input').val() ) ) this.setvalue(); this.isvisible = false; this.element.trigger({ type: 'hide', date: this.date }); }, remove: function () { this._detachevents(); $(document).off('mousedown', this.clickedoutside); this.picker.remove(); delete this.picker; delete this.element.data().datetimepicker; }, getdate: function () { var d = this.getutcdate(); if (d === null) { return null; } return new date(d.gettime() + (d.gettimezoneoffset() * 60000)); }, getutcdate: function () { return this.date; }, getinitialdate: function () { return this.initialdate }, setinitialdate: function (initialdate) { this.initialdate = initialdate; }, setdate: function (d) { this.setutcdate(new date(d.gettime() - (d.gettimezoneoffset() * 60000))); }, setutcdate: function (d) { if (d >= this.startdate && d <= this.enddate) { this.date = d; this.setvalue(); this.viewdate = this.date; this.fill(); } else { this.element.trigger({ type: 'outofrange', date: d, startdate: this.startdate, enddate: this.enddate }); } }, setformat: function (format) { this.format = dpglobal.parseformat(format, this.formattype); var element; if (this.isinput) { element = this.element; } else if (this.component) { element = this.element.find('input'); } if (element && element.val()) { this.setvalue(); } }, setvalue: function () { var formatted = this.getformatteddate(); if (!this.isinput) { if (this.component) { this.element.find('input').val(formatted); } this.element.data('date', formatted); } else { this.element.val(formatted); } if (this.linkfield) { $('#' + this.linkfield).val(this.getformatteddate(this.linkformat)); } }, getformatteddate: function (format) { format = format || this.format; return dpglobal.formatdate(this.date, format, this.language, this.formattype, this.timezone); }, setstartdate: function (startdate) { this.startdate = startdate || this.startdate; if (this.startdate.valueof() !== 8639968443048000) { this.startdate = dpglobal.parsedate(this.startdate, this.format, this.language, this.formattype, this.timezone); } this.update(); this.updatenavarrows(); }, setenddate: function (enddate) { this.enddate = enddate || this.enddate; if (this.enddate.valueof() !== 8639968443048000) { this.enddate = dpglobal.parsedate(this.enddate, this.format, this.language, this.formattype, this.timezone); } this.update(); this.updatenavarrows(); }, setdatesdisabled: function (datesdisabled) { this.datesdisabled = datesdisabled || []; if (!$.isarray(this.datesdisabled)) { this.datesdisabled = this.datesdisabled.split(/,\s*/); } var mthis = this; this.datesdisabled = $.map(this.datesdisabled, function (d) { return dpglobal.parsedate(d, mthis.format, mthis.language, mthis.formattype, mthis.timezone).todatestring(); }); this.update(); this.updatenavarrows(); }, settitle: function (selector, value) { return this.picker.find(selector) .find('th:eq(1)') .text(this.title === false ? value : this.title); }, setdaysofweekdisabled: function (daysofweekdisabled) { this.daysofweekdisabled = daysofweekdisabled || []; if (!$.isarray(this.daysofweekdisabled)) { this.daysofweekdisabled = this.daysofweekdisabled.split(/,\s*/); } this.daysofweekdisabled = $.map(this.daysofweekdisabled, function (d) { return parseint(d, 10); }); this.update(); this.updatenavarrows(); }, setminutesdisabled: function (minutesdisabled) { this.minutesdisabled = minutesdisabled || []; if (!$.isarray(this.minutesdisabled)) { this.minutesdisabled = this.minutesdisabled.split(/,\s*/); } this.minutesdisabled = $.map(this.minutesdisabled, function (d) { return parseint(d, 10); }); this.update(); this.updatenavarrows(); }, sethoursdisabled: function (hoursdisabled) { this.hoursdisabled = hoursdisabled || []; if (!$.isarray(this.hoursdisabled)) { this.hoursdisabled = this.hoursdisabled.split(/,\s*/); } this.hoursdisabled = $.map(this.hoursdisabled, function (d) { return parseint(d, 10); }); this.update(); this.updatenavarrows(); }, place: function () { if (this.isinline) return; if (!this.zindex) { var index_highest = 0; $('div').each(function () { var index_current = parseint($(this).css('zindex'), 10); if (index_current > index_highest) { index_highest = index_current; } }); this.zindex = index_highest + 10; } var offset, top, left, containeroffset; if (this.container instanceof $) { containeroffset = this.container.offset(); } else { containeroffset = $(this.container).offset(); } if (this.component) { offset = this.component.offset(); left = offset.left; if (this.pickerposition === 'bottom-left' || this.pickerposition === 'top-left') { left += this.component.outerwidth() - this.picker.outerwidth(); } } else { offset = this.element.offset(); left = offset.left; if (this.pickerposition === 'bottom-left' || this.pickerposition === 'top-left') { left += this.element.outerwidth() - this.picker.outerwidth(); } } var bodywidth = document.body.clientwidth || window.innerwidth; if (left + 220 > bodywidth) { left = bodywidth - 220; } if (this.pickerposition === 'top-left' || this.pickerposition === 'top-right') { top = offset.top - this.picker.outerheight(); } else { top = offset.top + this.height; } top = top - containeroffset.top; left = left - containeroffset.left; this.picker.css({ top: top, left: left, zindex: this.zindex }); }, hour_minute: "^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]", update: function () { var date, fromargs = false; if (arguments && arguments.length && (typeof arguments[0] === 'string' || arguments[0] instanceof date)) { date = arguments[0]; fromargs = true; } else { date = (this.isinput ? this.element.val() : this.element.find('input').val()) || this.element.data('date') || this.initialdate; if (typeof date === 'string') { date = date.replace(/^\s+|\s+$/g,''); } } if (!date) { date = new date(); fromargs = false; } if (typeof date === "string") { if (new regexp(this.hour_minute).test(date) || new regexp(this.hour_minute + ":[0-5][0-9]").test(date)) { date = this.getdate() } } this.date = dpglobal.parsedate(date, this.format, this.language, this.formattype, this.timezone); if (fromargs) this.setvalue(); if (this.date < this.startdate) { this.viewdate = new date(this.startdate); } else if (this.date > this.enddate) { this.viewdate = new date(this.enddate); } else { this.viewdate = new date(this.date); } this.fill(); }, filldow: function () { var dowcnt = this.weekstart, html = ''; while (dowcnt < this.weekstart + 7) { html += '' + dates[this.language].daysmin[(dowcnt++) % 7] + ''; } html += ''; this.picker.find('.datetimepicker-days thead').append(html); }, fillmonths: function () { var html = ''; var d = new date(this.viewdate); for (var i = 0; i < 12; i++) { d.setutcmonth(i); var classes = this.onrendermonth(d); html += '' + dates[this.language].monthsshort[i] + ''; } this.picker.find('.datetimepicker-months td').html(html); }, fill: function () { if (!this.date || !this.viewdate) { return; } var d = new date(this.viewdate), year = d.getutcfullyear(), month = d.getutcmonth(), daymonth = d.getutcdate(), hours = d.getutchours(), startyear = this.startdate.getutcfullyear(), startmonth = this.startdate.getutcmonth(), endyear = this.enddate.getutcfullyear(), endmonth = this.enddate.getutcmonth() + 1, currentdate = (new utcdate(this.date.getutcfullyear(), this.date.getutcmonth(), this.date.getutcdate())).valueof(), today = new date(); this.settitle('.datetimepicker-days', dates[this.language].months[month] + ' ' + year) if (this.formatviewtype === 'time') { var formatted = this.getformatteddate(); this.settitle('.datetimepicker-hours', formatted); this.settitle('.datetimepicker-minutes', formatted); } else { this.settitle('.datetimepicker-hours', daymonth + ' ' + dates[this.language].months[month] + ' ' + year); this.settitle('.datetimepicker-minutes', daymonth + ' ' + dates[this.language].months[month] + ' ' + year); } this.picker.find('tfoot th.today') .text(dates[this.language].today || dates['en'].today) .toggle(this.todaybtn !== false); this.picker.find('tfoot th.clear') .text(dates[this.language].clear || dates['en'].clear) .toggle(this.clearbtn !== false); this.updatenavarrows(); this.fillmonths(); var prevmonth = utcdate(year, month - 1, 28, 0, 0, 0, 0), day = dpglobal.getdaysinmonth(prevmonth.getutcfullyear(), prevmonth.getutcmonth()); prevmonth.setutcdate(day); prevmonth.setutcdate(day - (prevmonth.getutcday() - this.weekstart + 7) % 7); var nextmonth = new date(prevmonth); nextmonth.setutcdate(nextmonth.getutcdate() + 42); nextmonth = nextmonth.valueof(); var html = []; var classes; while (prevmonth.valueof() < nextmonth) { if (prevmonth.getutcday() === this.weekstart) { html.push(''); } classes = this.onrenderday(prevmonth); if (prevmonth.getutcfullyear() < year || (prevmonth.getutcfullyear() === year && prevmonth.getutcmonth() < month)) { classes.push('old'); } else if (prevmonth.getutcfullyear() > year || (prevmonth.getutcfullyear() === year && prevmonth.getutcmonth() > month)) { classes.push('new'); } // compare internal utc date with local today, not utc today if (this.todayhighlight && prevmonth.getutcfullyear() === today.getfullyear() && prevmonth.getutcmonth() === today.getmonth() && prevmonth.getutcdate() === today.getdate()) { classes.push('today'); } if (prevmonth.valueof() === currentdate) { classes.push('active'); } if ((prevmonth.valueof() + 86400000) <= this.startdate || prevmonth.valueof() > this.enddate || $.inarray(prevmonth.getutcday(), this.daysofweekdisabled) !== -1 || $.inarray(prevmonth.todatestring(), this.datesdisabled) !== -1) { classes.push('disabled'); } html.push('' + prevmonth.getutcdate() + ''); if (prevmonth.getutcday() === this.weekend) { html.push(''); } prevmonth.setutcdate(prevmonth.getutcdate() + 1); } this.picker.find('.datetimepicker-days tbody').empty().append(html.join('')); html = []; var txt = '', meridian = '', meridianold = ''; var hoursdisabled = this.hoursdisabled || []; d = new date(this.viewdate) for (var i = 0; i < 24; i++) { d.setutchours(i); classes = this.onrenderhour(d); if (hoursdisabled.indexof(i) !== -1) { classes.push('disabled'); } var actual = utcdate(year, month, daymonth, i); // we want the previous hour for the startdate if ((actual.valueof() + 3600000) <= this.startdate || actual.valueof() > this.enddate) { classes.push('disabled'); } else if (hours === i) { classes.push('active'); } if (this.showmeridian && dates[this.language].meridiem.length === 2) { meridian = (i < 12 ? dates[this.language].meridiem[0] : dates[this.language].meridiem[1]); if (meridian !== meridianold) { if (meridianold !== '') { html.push(''); } html.push('
' + meridian.touppercase() + ''); } meridianold = meridian; txt = (i % 12 ? i % 12 : 12); if (i < 12) { classes.push('hour_am'); } else { classes.push('hour_pm'); } html.push('' + txt + ''); if (i === 23) { html.push('
'); } } else { txt = i + ':00'; html.push('' + txt + ''); } } this.picker.find('.datetimepicker-hours td').html(html.join('')); html = []; txt = ''; meridian = ''; meridianold = ''; var minutesdisabled = this.minutesdisabled || []; d = new date(this.viewdate); for (var i = 0; i < 60; i += this.minutestep) { if (minutesdisabled.indexof(i) !== -1) continue; d.setutcminutes(i); d.setutcseconds(0); classes = this.onrenderminute(d); if (this.showmeridian && dates[this.language].meridiem.length === 2) { meridian = (hours < 12 ? dates[this.language].meridiem[0] : dates[this.language].meridiem[1]); if (meridian !== meridianold) { if (meridianold !== '') { html.push(''); } html.push('
' + meridian.touppercase() + ''); } meridianold = meridian; txt = (hours % 12 ? hours % 12 : 12); html.push('' + txt + ':' + (i < 10 ? '0' + i : i) + ''); if (i === 59) { html.push('
'); } } else { txt = i + ':00'; html.push('' + hours + ':' + (i < 10 ? '0' + i : i) + ''); } } this.picker.find('.datetimepicker-minutes td').html(html.join('')); var currentyear = this.date.getutcfullyear(); var months = this.settitle('.datetimepicker-months', year) .end() .find('.month').removeclass('active'); if (currentyear === year) { // getutcmonths() returns 0 based, and we need to select the next one // to cater bootstrap 2 we don't need to select the next one months.eq(this.date.getutcmonth()).addclass('active'); } if (year < startyear || year > endyear) { months.addclass('disabled'); } if (year === startyear) { months.slice(0, startmonth).addclass('disabled'); } if (year === endyear) { months.slice(endmonth).addclass('disabled'); } html = ''; year = parseint(year / 10, 10) * 10; var yearcont = this.settitle('.datetimepicker-years', year + '-' + (year + 9)) .end() .find('td'); year -= 1; d = new date(this.viewdate); for (var i = -1; i < 11; i++) { d.setutcfullyear(year); classes = this.onrenderyear(d); if (i === -1 || i === 10) { classes.push(old); } html += '' + year + ''; year += 1; } yearcont.html(html); this.place(); }, updatenavarrows: function () { var d = new date(this.viewdate), year = d.getutcfullyear(), month = d.getutcmonth(), day = d.getutcdate(), hour = d.getutchours(); switch (this.viewmode) { case 0: if (year <= this.startdate.getutcfullyear() && month <= this.startdate.getutcmonth() && day <= this.startdate.getutcdate() && hour <= this.startdate.getutchours()) { this.picker.find('.prev').css({visibility: 'hidden'}); } else { this.picker.find('.prev').css({visibility: 'visible'}); } if (year >= this.enddate.getutcfullyear() && month >= this.enddate.getutcmonth() && day >= this.enddate.getutcdate() && hour >= this.enddate.getutchours()) { this.picker.find('.next').css({visibility: 'hidden'}); } else { this.picker.find('.next').css({visibility: 'visible'}); } break; case 1: if (year <= this.startdate.getutcfullyear() && month <= this.startdate.getutcmonth() && day <= this.startdate.getutcdate()) { this.picker.find('.prev').css({visibility: 'hidden'}); } else { this.picker.find('.prev').css({visibility: 'visible'}); } if (year >= this.enddate.getutcfullyear() && month >= this.enddate.getutcmonth() && day >= this.enddate.getutcdate()) { this.picker.find('.next').css({visibility: 'hidden'}); } else { this.picker.find('.next').css({visibility: 'visible'}); } break; case 2: if (year <= this.startdate.getutcfullyear() && month <= this.startdate.getutcmonth()) { this.picker.find('.prev').css({visibility: 'hidden'}); } else { this.picker.find('.prev').css({visibility: 'visible'}); } if (year >= this.enddate.getutcfullyear() && month >= this.enddate.getutcmonth()) { this.picker.find('.next').css({visibility: 'hidden'}); } else { this.picker.find('.next').css({visibility: 'visible'}); } break; case 3: case 4: if (year <= this.startdate.getutcfullyear()) { this.picker.find('.prev').css({visibility: 'hidden'}); } else { this.picker.find('.prev').css({visibility: 'visible'}); } if (year >= this.enddate.getutcfullyear()) { this.picker.find('.next').css({visibility: 'hidden'}); } else { this.picker.find('.next').css({visibility: 'visible'}); } break; } }, mousewheel: function (e) { e.preventdefault(); e.stoppropagation(); if (this.wheelpause) { return; } this.wheelpause = true; var originalevent = e.originalevent; var delta = originalevent.wheeldelta; var mode = delta > 0 ? 1 : (delta === 0) ? 0 : -1; if (this.wheelviewmodenavigationinversedirection) { mode = -mode; } this.showmode(mode); settimeout($.proxy(function () { this.wheelpause = false }, this), this.wheelviewmodenavigationdelay); }, click: function (e) { e.stoppropagation(); e.preventdefault(); var target = $(e.target).closest('span, td, th, legend'); if (target.is('.' + this.icontype)) { target = $(target).parent().closest('span, td, th, legend'); } if (target.length === 1) { if (target.is('.disabled')) { this.element.trigger({ type: 'outofrange', date: this.viewdate, startdate: this.startdate, enddate: this.enddate }); return; } switch (target[0].nodename.tolowercase()) { case 'th': switch (target[0].classname) { case 'switch': this.showmode(1); break; case 'prev': case 'next': var dir = dpglobal.modes[this.viewmode].navstep * (target[0].classname === 'prev' ? -1 : 1); switch (this.viewmode) { case 0: this.viewdate = this.movehour(this.viewdate, dir); break; case 1: this.viewdate = this.movedate(this.viewdate, dir); break; case 2: this.viewdate = this.movemonth(this.viewdate, dir); break; case 3: case 4: this.viewdate = this.moveyear(this.viewdate, dir); break; } this.fill(); this.element.trigger({ type: target[0].classname + ':' + this.convertviewmodetext(this.viewmode), date: this.viewdate, startdate: this.startdate, enddate: this.enddate }); break; case 'clear': this.reset(); if (this.autoclose) { this.hide(); } break; case 'today': var date = new date(); date = utcdate(date.getfullyear(), date.getmonth(), date.getdate(), date.gethours(), date.getminutes(), date.getseconds(), 0); // respect startdate and enddate. if (date < this.startdate) date = this.startdate; else if (date > this.enddate) date = this.enddate; this.viewmode = this.startviewmode; this.showmode(0); this._setdate(date); this.fill(); if (this.autoclose) { this.hide(); } break; } break; case 'span': if (!target.is('.disabled')) { var year = this.viewdate.getutcfullyear(), month = this.viewdate.getutcmonth(), day = this.viewdate.getutcdate(), hours = this.viewdate.getutchours(), minutes = this.viewdate.getutcminutes(), seconds = this.viewdate.getutcseconds(); if (target.is('.month')) { this.viewdate.setutcdate(1); month = target.parent().find('span').index(target); day = this.viewdate.getutcdate(); this.viewdate.setutcmonth(month); this.element.trigger({ type: 'changemonth', date: this.viewdate }); if (this.viewselect >= 3) { this._setdate(utcdate(year, month, day, hours, minutes, seconds, 0)); } } else if (target.is('.year')) { this.viewdate.setutcdate(1); year = parseint(target.text(), 10) || 0; this.viewdate.setutcfullyear(year); this.element.trigger({ type: 'changeyear', date: this.viewdate }); if (this.viewselect >= 4) { this._setdate(utcdate(year, month, day, hours, minutes, seconds, 0)); } } else if (target.is('.hour')) { hours = parseint(target.text(), 10) || 0; if (target.hasclass('hour_am') || target.hasclass('hour_pm')) { if (hours === 12 && target.hasclass('hour_am')) { hours = 0; } else if (hours !== 12 && target.hasclass('hour_pm')) { hours += 12; } } this.viewdate.setutchours(hours); this.element.trigger({ type: 'changehour', date: this.viewdate }); if (this.viewselect >= 1) { this._setdate(utcdate(year, month, day, hours, minutes, seconds, 0)); } } else if (target.is('.minute')) { minutes = parseint(target.text().substr(target.text().indexof(':') + 1), 10) || 0; this.viewdate.setutcminutes(minutes); this.element.trigger({ type: 'changeminute', date: this.viewdate }); if (this.viewselect >= 0) { this._setdate(utcdate(year, month, day, hours, minutes, seconds, 0)); } } if (this.viewmode !== 0) { var oldviewmode = this.viewmode; this.showmode(-1); this.fill(); if (oldviewmode === this.viewmode && this.autoclose) { this.hide(); } } else { this.fill(); if (this.autoclose) { this.hide(); } } } break; case 'td': if (target.is('.day') && !target.is('.disabled')) { var day = parseint(target.text(), 10) || 1; var year = this.viewdate.getutcfullyear(), month = this.viewdate.getutcmonth(), hours = this.viewdate.getutchours(), minutes = this.viewdate.getutcminutes(), seconds = this.viewdate.getutcseconds(); 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; } } this.viewdate.setutcfullyear(year); this.viewdate.setutcmonth(month, day); this.element.trigger({ type: 'changeday', date: this.viewdate }); if (this.viewselect >= 2) { this._setdate(utcdate(year, month, day, hours, minutes, seconds, 0)); } } var oldviewmode = this.viewmode; this.showmode(-1); this.fill(); if (oldviewmode === this.viewmode && this.autoclose) { this.hide(); } break; } } }, _setdate: function (date, which) { if (!which || which === 'date') this.date = date; if (!which || which === 'view') this.viewdate = date; this.fill(); this.setvalue(); var element; if (this.isinput) { element = this.element; } else if (this.component) { element = this.element.find('input'); } if (element) { element.change(); } this.element.trigger({ type: 'changedate', date: this.getdate() }); if(date === null) this.date = this.viewdate; }, moveminute: function (date, dir) { if (!dir) return date; var new_date = new date(date.valueof()); //dir = dir > 0 ? 1 : -1; new_date.setutcminutes(new_date.getutcminutes() + (dir * this.minutestep)); return new_date; }, movehour: function (date, dir) { if (!dir) return date; var new_date = new date(date.valueof()); //dir = dir > 0 ? 1 : -1; new_date.setutchours(new_date.getutchours() + dir); return new_date; }, movedate: function (date, dir) { if (!dir) return date; var new_date = new date(date.valueof()); //dir = dir > 0 ? 1 : -1; new_date.setutcdate(new_date.getutcdate() + dir); return new_date; }, movemonth: function (date, dir) { if (!dir) return date; var new_date = new date(date.valueof()), day = new_date.getutcdate(), month = new_date.getutcmonth(), mag = math.abs(dir), new_month, test; dir = dir > 0 ? 1 : -1; if (mag === 1) { test = dir === -1 // if going back one month, make sure month is not current month // (eg, mar 31 -> feb 31 === feb 28, not mar 02) ? function () { return new_date.getutcmonth() === month; } // if going forward one month, make sure month is as expected // (eg, jan 31 -> feb 31 === feb 28, not mar 02) : function () { return new_date.getutcmonth() !== new_month; }; new_month = month + dir; new_date.setutcmonth(new_month); // dec -> jan (12) or jan -> dec (-1) -- limit expected date to 0-11 if (new_month < 0 || new_month > 11) new_month = (new_month + 12) % 12; } else { // for magnitudes >1, move one month at a time... for (var i = 0; i < mag; i++) // ...which might decrease the day (eg, jan 31 to feb 28, etc)... new_date = this.movemonth(new_date, dir); // ...then reset the day, keeping it in the new month new_month = new_date.getutcmonth(); new_date.setutcdate(day); test = function () { return new_month !== new_date.getutcmonth(); }; } // common date-resetting loop -- if date is beyond end of month, make it // end of month while (test()) { new_date.setutcdate(--day); new_date.setutcmonth(new_month); } return new_date; }, moveyear: function (date, dir) { return this.movemonth(date, dir * 12); }, datewithinrange: function (date) { return date >= this.startdate && date <= this.enddate; }, keydown: function (e) { if (this.picker.is(':not(:visible)')) { if (e.keycode === 27) // allow escape to hide and re-show picker this.show(); return; } var datechanged = false, dir, newdate, newviewdate; switch (e.keycode) { case 27: // escape this.hide(); e.preventdefault(); break; case 37: // left case 39: // right if (!this.keyboardnavigation) break; dir = e.keycode === 37 ? -1 : 1; var viewmode = this.viewmode; if (e.ctrlkey) { viewmode += 2; } else if (e.shiftkey) { viewmode += 1; } if (viewmode === 4) { newdate = this.moveyear(this.date, dir); newviewdate = this.moveyear(this.viewdate, dir); } else if (viewmode === 3) { newdate = this.movemonth(this.date, dir); newviewdate = this.movemonth(this.viewdate, dir); } else if (viewmode === 2) { newdate = this.movedate(this.date, dir); newviewdate = this.movedate(this.viewdate, dir); } else if (viewmode === 1) { newdate = this.movehour(this.date, dir); newviewdate = this.movehour(this.viewdate, dir); } else if (viewmode === 0) { newdate = this.moveminute(this.date, dir); newviewdate = this.moveminute(this.viewdate, dir); } if (this.datewithinrange(newdate)) { this.date = newdate; this.viewdate = newviewdate; this.setvalue(); this.update(); e.preventdefault(); datechanged = true; } break; case 38: // up case 40: // down if (!this.keyboardnavigation) break; dir = e.keycode === 38 ? -1 : 1; viewmode = this.viewmode; if (e.ctrlkey) { viewmode += 2; } else if (e.shiftkey) { viewmode += 1; } if (viewmode === 4) { newdate = this.moveyear(this.date, dir); newviewdate = this.moveyear(this.viewdate, dir); } else if (viewmode === 3) { newdate = this.movemonth(this.date, dir); newviewdate = this.movemonth(this.viewdate, dir); } else if (viewmode === 2) { newdate = this.movedate(this.date, dir * 7); newviewdate = this.movedate(this.viewdate, dir * 7); } else if (viewmode === 1) { if (this.showmeridian) { newdate = this.movehour(this.date, dir * 6); newviewdate = this.movehour(this.viewdate, dir * 6); } else { newdate = this.movehour(this.date, dir * 4); newviewdate = this.movehour(this.viewdate, dir * 4); } } else if (viewmode === 0) { newdate = this.moveminute(this.date, dir * 4); newviewdate = this.moveminute(this.viewdate, dir * 4); } if (this.datewithinrange(newdate)) { this.date = newdate; this.viewdate = newviewdate; this.setvalue(); this.update(); e.preventdefault(); datechanged = true; } break; case 13: // enter if (this.viewmode !== 0) { var oldviewmode = this.viewmode; this.showmode(-1); this.fill(); if (oldviewmode === this.viewmode && this.autoclose) { this.hide(); } } else { this.fill(); if (this.autoclose) { this.hide(); } } e.preventdefault(); break; case 9: // tab this.hide(); break; } if (datechanged) { var element; if (this.isinput) { element = this.element; } else if (this.component) { element = this.element.find('input'); } if (element) { element.change(); } this.element.trigger({ type: 'changedate', date: this.getdate() }); } }, showmode: function (dir) { if (dir) { var newviewmode = math.max(0, math.min(dpglobal.modes.length - 1, this.viewmode + dir)); if (newviewmode >= this.minview && newviewmode <= this.maxview) { this.element.trigger({ type: 'changemode', date: this.viewdate, oldviewmode: this.viewmode, newviewmode: newviewmode }); this.viewmode = newviewmode; } } /* vitalets: fixing bug of very special conditions: jquery 1.7.1 + webkit + show inline datetimepicker in bootstrap popover. method show() does not set display css correctly and datetimepicker is not shown. changed to .css('display', 'block') solve the problem. see https://github.com/vitalets/x-editable/issues/37 in jquery 1.7.2+ everything works fine. */ //this.picker.find('>div').hide().filter('.datetimepicker-'+dpglobal.modes[this.viewmode].clsname).show(); this.picker.find('>div').hide().filter('.datetimepicker-' + dpglobal.modes[this.viewmode].clsname).css('display', 'block'); this.updatenavarrows(); }, reset: function () { this._setdate(null, 'date'); }, convertviewmodetext: function (viewmode) { switch (viewmode) { case 4: return 'decade'; case 3: return 'year'; case 2: return 'month'; case 1: return 'day'; case 0: return 'hour'; } } }; var old = $.fn.datetimepicker; $.fn.datetimepicker = function (option) { var args = array.apply(null, arguments); args.shift(); var internal_return; this.each(function () { var $this = $(this), data = $this.data('datetimepicker'), options = typeof option === 'object' && option; if (!data) { $this.data('datetimepicker', (data = new datetimepicker(this, $.extend({}, $.fn.datetimepicker.defaults, options)))); } if (typeof option === 'string' && typeof data[option] === 'function') { internal_return = data[option].apply(data, args); if (internal_return !== undefined) { return false; } } }); if (internal_return !== undefined) return internal_return; else return this; }; $.fn.datetimepicker.defaults = { }; $.fn.datetimepicker.constructor = datetimepicker; var dates = $.fn.datetimepicker.dates = { en: { days: ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'], daysshort: ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'], daysmin: ['su', 'mo', 'tu', 'we', 'th', 'fr', 'sa', 'su'], months: ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'], monthsshort: ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'], meridiem: ['am', 'pm'], suffix: ['st', 'nd', 'rd', 'th'], today: 'today', clear: 'clear' } }; var dpglobal = { modes: [ { clsname: 'minutes', navfnc: 'hours', navstep: 1 }, { clsname: 'hours', navfnc: 'date', navstep: 1 }, { clsname: 'days', navfnc: 'month', navstep: 1 }, { clsname: 'months', navfnc: 'fullyear', navstep: 1 }, { clsname: 'years', navfnc: 'fullyear', navstep: 10 } ], isleapyear: function (year) { return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0)) }, getdaysinmonth: function (year, month) { return [31, (dpglobal.isleapyear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month] }, getdefaultformat: function (type, field) { if (type === 'standard') { if (field === 'input') return 'yyyy-mm-dd hh:ii'; else return 'yyyy-mm-dd hh:ii:ss'; } else if (type === 'php') { if (field === 'input') return 'y-m-d h:i'; else return 'y-m-d h:i:s'; } else { throw new error('invalid format type.'); } }, validparts: function (type) { if (type === 'standard') { return /t|hh?|hh?|p|p|z|z|ii?|ss?|dd?|dd?|mm?|mm?|yy(?:yy)?/g; } else if (type === 'php') { return /[ddjlnwzfmmnstyyaabgghhis]/g; } else { throw new error('invalid format type.'); } }, nonpunctuation: /[^ -\/:-@\[-`{-~\t\n\rtz]+/g, parseformat: function (format, type) { // ie treats \0 as a string end in inputs (truncating the value), // so it's a bad format delimiter, anyway var separators = format.replace(this.validparts(type), '\0').split('\0'), parts = format.match(this.validparts(type)); if (!separators || !separators.length || !parts || parts.length === 0) { throw new error('invalid date format.'); } return {separators: separators, parts: parts}; }, parsedate: function (date, format, language, type, timezone) { if (date instanceof date) { var dateutc = new date(date.valueof() - date.gettimezoneoffset() * 60000); dateutc.setmilliseconds(0); return dateutc; } if (/^\d{4}\-\d{1,2}\-\d{1,2}$/.test(date)) { format = this.parseformat('yyyy-mm-dd', type); } if (/^\d{4}\-\d{1,2}\-\d{1,2}[t ]\d{1,2}\:\d{1,2}$/.test(date)) { format = this.parseformat('yyyy-mm-dd hh:ii', type); } if (/^\d{4}\-\d{1,2}\-\d{1,2}[t ]\d{1,2}\:\d{1,2}\:\d{1,2}[z]{0,1}$/.test(date)) { format = this.parseformat('yyyy-mm-dd hh:ii:ss', type); } if (/^[-+]\d+[dmwy]([\s,]+[-+]\d+[dmwy])*$/.test(date)) { var part_re = /([-+]\d+)([dmwy])/, parts = date.match(/([-+]\d+)([dmwy])/g), part, dir; date = new date(); for (var i = 0; i < parts.length; i++) { part = part_re.exec(parts[i]); dir = parseint(part[1]); switch (part[2]) { case 'd': date.setutcdate(date.getutcdate() + dir); break; case 'm': date = datetimepicker.prototype.movemonth.call(datetimepicker.prototype, date, dir); break; case 'w': date.setutcdate(date.getutcdate() + dir * 7); break; case 'y': date = datetimepicker.prototype.moveyear.call(datetimepicker.prototype, date, dir); break; } } return utcdate(date.getutcfullyear(), date.getutcmonth(), date.getutcdate(), date.getutchours(), date.getutcminutes(), date.getutcseconds(), 0); } var parts = date && date.tostring().match(this.nonpunctuation) || [], date = new date(0, 0, 0, 0, 0, 0, 0), parsed = {}, setters_order = ['hh', 'h', 'ii', 'i', 'ss', 's', 'yyyy', 'yy', 'm', 'mm', 'm', 'mm', 'd', 'dd', 'd', 'dd', 'h', 'hh', 'p', 'p', 'z', 'z'], setters_map = { hh: function (d, v) { return d.setutchours(v); }, h: function (d, v) { return d.setutchours(v); }, hh: function (d, v) { return d.setutchours(v === 12 ? 0 : v); }, h: function (d, v) { return d.setutchours(v === 12 ? 0 : v); }, ii: function (d, v) { return d.setutcminutes(v); }, i: function (d, v) { return d.setutcminutes(v); }, ss: function (d, v) { return d.setutcseconds(v); }, s: function (d, v) { return d.setutcseconds(v); }, yyyy: function (d, v) { return d.setutcfullyear(v); }, yy: function (d, v) { return d.setutcfullyear(2000 + v); }, m: function (d, v) { v -= 1; while (v < 0) v += 12; v %= 12; d.setutcmonth(v); while (d.getutcmonth() !== v) if (isnan(d.getutcmonth())) return d; else d.setutcdate(d.getutcdate() - 1); return d; }, d: function (d, v) { return d.setutcdate(v); }, p: function (d, v) { return d.setutchours(v === 1 ? d.getutchours() + 12 : d.getutchours()); }, z: function () { return timezone } }, val, filtered, part; setters_map['m'] = setters_map['mm'] = setters_map['mm'] = setters_map['m']; setters_map['dd'] = setters_map['d']; setters_map['p'] = setters_map['p']; setters_map['z'] = setters_map['z']; date = utcdate(date.getfullyear(), date.getmonth(), date.getdate(), date.gethours(), date.getminutes(), date.getseconds()); if (parts.length === format.parts.length) { for (var i = 0, cnt = format.parts.length; i < cnt; i++) { val = parseint(parts[i], 10); part = format.parts[i]; if (isnan(val)) { switch (part) { case 'mm': filtered = $(dates[language].months).filter(function () { var m = this.slice(0, parts[i].length), p = parts[i].slice(0, m.length); return m === p; }); val = $.inarray(filtered[0], dates[language].months) + 1; break; case 'm': filtered = $(dates[language].monthsshort).filter(function () { var m = this.slice(0, parts[i].length), p = parts[i].slice(0, m.length); return m.tolowercase() === p.tolowercase(); }); val = $.inarray(filtered[0], dates[language].monthsshort) + 1; break; case 'p': case 'p': val = $.inarray(parts[i].tolowercase(), dates[language].meridiem); break; case 'z': case 'z': timezone; break; } } parsed[part] = val; } for (var i = 0, s; i < setters_order.length; i++) { s = setters_order[i]; if (s in parsed && !isnan(parsed[s])) setters_map[s](date, parsed[s]) } } return date; }, formatdate: function (date, format, language, type, timezone) { if (date === null) { return ''; } var val; if (type === 'standard') { val = { t: date.gettime(), // year yy: date.getutcfullyear().tostring().substring(2), yyyy: date.getutcfullyear(), // month m: date.getutcmonth() + 1, m: dates[language].monthsshort[date.getutcmonth()], mm: dates[language].months[date.getutcmonth()], // day d: date.getutcdate(), d: dates[language].daysshort[date.getutcday()], dd: dates[language].days[date.getutcday()], p: (dates[language].meridiem.length === 2 ? dates[language].meridiem[date.getutchours() < 12 ? 0 : 1] : ''), // hour h: date.getutchours(), // minute i: date.getutcminutes(), // second s: date.getutcseconds(), // timezone z: timezone }; if (dates[language].meridiem.length === 2) { val.h = (val.h % 12 === 0 ? 12 : val.h % 12); } else { val.h = val.h; } val.hh = (val.h < 10 ? '0' : '') + val.h; val.p = val.p.touppercase(); val.z = val.z; val.hh = (val.h < 10 ? '0' : '') + val.h; val.ii = (val.i < 10 ? '0' : '') + val.i; val.ss = (val.s < 10 ? '0' : '') + val.s; val.dd = (val.d < 10 ? '0' : '') + val.d; val.mm = (val.m < 10 ? '0' : '') + val.m; } else if (type === 'php') { // php format val = { // year y: date.getutcfullyear().tostring().substring(2), y: date.getutcfullyear(), // month f: dates[language].months[date.getutcmonth()], m: dates[language].monthsshort[date.getutcmonth()], n: date.getutcmonth() + 1, t: dpglobal.getdaysinmonth(date.getutcfullyear(), date.getutcmonth()), // day j: date.getutcdate(), l: dates[language].days[date.getutcday()], d: dates[language].daysshort[date.getutcday()], w: date.getutcday(), // 0 -> 6 n: (date.getutcday() === 0 ? 7 : date.getutcday()), // 1 -> 7 s: (date.getutcdate() % 10 <= dates[language].suffix.length ? dates[language].suffix[date.getutcdate() % 10 - 1] : ''), // hour a: (dates[language].meridiem.length === 2 ? dates[language].meridiem[date.getutchours() < 12 ? 0 : 1] : ''), g: (date.getutchours() % 12 === 0 ? 12 : date.getutchours() % 12), g: date.getutchours(), // minute i: date.getutcminutes(), // second s: date.getutcseconds() }; val.m = (val.n < 10 ? '0' : '') + val.n; val.d = (val.j < 10 ? '0' : '') + val.j; val.a = val.a.tostring().touppercase(); val.h = (val.g < 10 ? '0' : '') + val.g; val.h = (val.g < 10 ? '0' : '') + val.g; val.i = (val.i < 10 ? '0' : '') + val.i; val.s = (val.s < 10 ? '0' : '') + val.s; } else { throw new error('invalid format type.'); } var date = [], seps = $.extend([], format.separators); for (var i = 0, cnt = format.parts.length; i < cnt; i++) { if (seps.length) { date.push(seps.shift()); } date.push(val[format.parts[i]]); } if (seps.length) { date.push(seps.shift()); } return date.join(''); }, convertviewmode: function (viewmode) { switch (viewmode) { case 4: case 'decade': viewmode = 4; break; case 3: case 'year': viewmode = 3; break; case 2: case 'month': viewmode = 2; break; case 1: case 'day': viewmode = 1; break; case 0: case 'hour': viewmode = 0; break; } return viewmode; }, headtemplate: '' + '' + '' + '' + '' + '' + '', headtemplatev3: '' + '' + ' ' + '' + ' ' + '' + '', conttemplate: '', foottemplate: '' + '' + '' + '' }; dpglobal.template = '
' + '
' + '' + dpglobal.headtemplate + dpglobal.conttemplate + dpglobal.foottemplate + '
' + '
' + '
' + '' + dpglobal.headtemplate + dpglobal.conttemplate + dpglobal.foottemplate + '
' + '
' + '
' + '' + dpglobal.headtemplate + '' + dpglobal.foottemplate + '
' + '
' + '
' + '' + dpglobal.headtemplate + dpglobal.conttemplate + dpglobal.foottemplate + '
' + '
' + '
' + '' + dpglobal.headtemplate + dpglobal.conttemplate + dpglobal.foottemplate + '
' + '
' + '
'; dpglobal.templatev3 = '
' + '
' + '' + dpglobal.headtemplatev3 + dpglobal.conttemplate + dpglobal.foottemplate + '
' + '
' + '
' + '' + dpglobal.headtemplatev3 + dpglobal.conttemplate + dpglobal.foottemplate + '
' + '
' + '
' + '' + dpglobal.headtemplatev3 + '' + dpglobal.foottemplate + '
' + '
' + '
' + '' + dpglobal.headtemplatev3 + dpglobal.conttemplate + dpglobal.foottemplate + '
' + '
' + '
' + '' + dpglobal.headtemplatev3 + dpglobal.conttemplate + dpglobal.foottemplate + '
' + '
' + '
'; $.fn.datetimepicker.dpglobal = dpglobal; /* datetimepicker no conflict * =================== */ $.fn.datetimepicker.noconflict = function () { $.fn.datetimepicker = old; return this; }; /* datetimepicker data-api * ================== */ $(document).on( 'focus.datetimepicker.data-api click.datetimepicker.data-api', '[data-provide="datetimepicker"]', function (e) { var $this = $(this); if ($this.data('datetimepicker')) return; e.preventdefault(); // component click requires us to explicitly show it $this.datetimepicker('show'); } ); $(function () { $('[data-provide="datetimepicker-inline"]').datetimepicker(); }); }));