Cognito.ready('libraryScripts', function($) { var jQuery = $; ;(function() { if (Cognito.config.scripts.indexOf('cognito-datepicker') >= 0) return; else Cognito.config.scripts.push('cognito-datepicker');/* ========================================================= * bootstrap-datepicker.js * http://www.eyecon.ro/bootstrap-datepicker * ========================================================= * Copyright 2012 Stefan Petre * Improvements by Andrew Rowls * * 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. * ========================================================= */ /* ========================================================= * Source (?): https://github.com/uxsolutions/bootstrap-datepicker * Version (approximately?): * Revision: 511c1b0241eb9804892df6f9388e0afd00107253 * Author: Andrew Rowls * Date: 8/18/2013 2:46:30 AM * Message: Merge pull request #223 from alexquast/master * ========================================================= */ (function ($) { var $window = $(window); function UTCDate() { return new Date(Date.UTC.apply(Date, arguments)); } function UTCToday() { var today = new Date(); return UTCDate(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate()); } // Picker object var Datepicker = function (element, options) { var that = this; this._process_options(options); this.element = $(element); this.isInline = false; //this.isInput = this.element.is('input'); this.isInput = true; this.component = this.element.parent().parent().find(".c-editor-date-icon:first"); this.hasInput = false; if (this.component && this.component.length === 0) this.component = false; this.picker = $(DPGlobal.template); this._buildEvents(); this._attachEvents(); if (this.isInline) { this.picker.addClass('cognito-datepicker-inline').appendTo(this.element); } else { this.picker.addClass('cognito-datepicker-dropdown cognito-dropdown-menu'); } if (this.o.rtl) { this.picker.addClass('cognito-datepicker-rtl'); this.picker.find('.prev i, .next i') .toggleClass('icon-arrow-left icon-arrow-right'); } this.viewMode = this.o.startView; if (this.o.calendarWeeks) this.picker.find('tfoot th.today') .attr('colspan', function (i, val) { return parseInt(val) + 1; }); this._allow_update = false; this.setStartDate(this._o.startDate); this.setEndDate(this._o.endDate); this.setDaysOfWeekDisabled(this.o.daysOfWeekDisabled); this.fillDow(); this.fillMonths(); this._allow_update = true; this.update(); this.showMode(); if (this.isInline) { this.show(); } }; Datepicker.prototype = { constructor: Datepicker, _process_options: function (opts) { // Store raw options for reference this._o = $.extend({}, this._o, opts); // Processed options var o = this.o = $.extend({}, this._o); // override the dates variable if (opts.dates) $.extend(dates, opts.dates); // Check if "de-DE" style date is available, if not language should // fallback to 2 letter code eg "de" var lang = o.language; if (!dates[lang]) { lang = lang.split('-')[0]; if (!dates[lang]) lang = defaults.language; } o.language = lang; switch (o.startView) { case 2: case 'decade': o.startView = 2; break; case 1: case 'year': o.startView = 1; break; default: o.startView = 0; } switch (o.minViewMode) { case 1: case 'months': o.minViewMode = 1; break; case 2: case 'years': o.minViewMode = 2; break; default: o.minViewMode = 0; } o.startView = Math.max(o.startView, o.minViewMode); o.weekStart %= 7; o.weekEnd = ((o.weekStart + 6) % 7); var format = DPGlobal.parseFormat(o.format); if (o.startDate !== -Infinity) { if (!!o.startDate) { if (o.startDate instanceof Date) o.startDate = this._local_to_utc(this._zero_time(o.startDate)); else o.startDate = DPGlobal.parseDate(o.startDate, format, o.language); } else { o.startDate = -Infinity; } } if (o.endDate !== Infinity) { if (!!o.endDate) { if (o.endDate instanceof Date) o.endDate = this._local_to_utc(this._zero_time(o.endDate)); else o.endDate = DPGlobal.parseDate(o.endDate, format, o.language); } else { o.endDate = Infinity; } } o.daysOfWeekDisabled = o.daysOfWeekDisabled || []; if (!$.isArray(o.daysOfWeekDisabled)) o.daysOfWeekDisabled = o.daysOfWeekDisabled.split(/[,\s]*/); o.daysOfWeekDisabled = $.map(o.daysOfWeekDisabled, function (d) { return parseInt(d, 10); }); var plc = String(o.orientation).toLowerCase().split(/\s+/g), _plc = o.orientation.toLowerCase(); plc = $.grep(plc, function (word) { return (/^auto|left|right|top|bottom$/).test(word); }); o.orientation = { x: 'auto', y: 'auto' }; if (!_plc || _plc === 'auto') ; // no action else if (plc.length === 1) { switch (plc[0]) { case 'top': case 'bottom': o.orientation.y = plc[0]; break; case 'left': case 'right': o.orientation.x = plc[0]; break; } } else { _plc = $.grep(plc, function (word) { return (/^left|right$/).test(word); }); o.orientation.x = _plc[0] || 'auto'; _plc = $.grep(plc, function (word) { return (/^top|bottom$/).test(word); }); o.orientation.y = _plc[0] || 'auto'; } }, _events: [], _secondaryEvents: [], _applyEvents: function (evs) { for (var i = 0, el, ev; i < evs.length; i++) { el = evs[i][0]; ev = evs[i][1]; el.on(ev); } }, _unapplyEvents: function (evs) { for (var i = 0, el, ev; i < evs.length; i++) { el = evs[i][0]; ev = evs[i][1]; el.off(ev); } }, //Toggles the widget open and close toggleWidget: function (e) { if ($(this.picker).is(":visible")) this.hide(); else { this.show(); } }, _buildEvents: function () { if (this.isInput) { // single input this._events = [ [this.element, { focus: $.proxy(function (e) { if (!this.element.is(".icon-picker-only, .suppress-picker")) this.show(e); }, this), keyup: $.proxy(this.update, this), keydown: $.proxy(this.keydown, this) }], [this.element.parent().parent().find('.c-editor-date-icon'), { click: $.proxy(this.toggleWidget, this) }] ]; } else if (this.element.is('div')) { // inline datepicker this.isInline = true; } else { this._events = [ [this.element, { click: $.proxy(this.show, this) }] ]; } this._secondaryEvents = [ [this.picker, { click: $.proxy(this.click, this) }], [$(window), { resize: $.proxy(this.place, this) }], [$(document), { mousedown: $.proxy(function (e) { //If the target is not the picker or the date field's widget, icon, or input field, then hide the widget if (!( this.element.is(e.target) || this.picker.is(e.target) || this.picker.find(e.target).length ) && ( //the user is not clicking the editor or icon that belongs to this field !(e.target.className.indexOf("c-editor-date") > -1 || e.target.className.indexOf("icon-calendar") > -1 || e.target.className.indexOf("date-icon") > -1 || this.picker.is(e.target)) || $(e.target).parents(".c-date-date")[0] !== $(this.element).parents(".c-date-date")[0] ) ) { this.hide(); } }, this) }] ]; }, _attachEvents: function () { this._detachEvents(); this._applyEvents(this._events); }, _detachEvents: function () { this._unapplyEvents(this._events); }, _attachSecondaryEvents: function () { this._detachSecondaryEvents(); this._applyEvents(this._secondaryEvents); }, _detachSecondaryEvents: function () { this._unapplyEvents(this._secondaryEvents); }, _trigger: function (event, altdate) { var date = altdate || this.date, local_date = this._utc_to_local(date); this.element.trigger({ type: event, date: local_date, format: $.proxy(function (altformat) { var format = altformat || this.o.format; return DPGlobal.formatDate(date, format, this.o.language); }, this) }); }, show: function (e) { if ($(this.picker).is(":visible")) return; if (!this.isInline) this.picker.appendTo("body"); this.picker.show(); this.height = this.component ? this.component.outerHeight() : this.element.outerHeight(); this.place(); this._attachSecondaryEvents(); if (e) { e.preventDefault(); } if (this.element.val() !== "") { this.date = new Date(this.element.val()); this.update(); } this._trigger('show'); }, hide: function (e) { if (this.isInline) return; if (!this.picker.is(':visible')) return; this.picker.hide().detach(); this._detachSecondaryEvents(); this.viewMode = this.o.startView; this.showMode(); this._trigger('hide'); }, remove: function () { this.hide(); this._detachEvents(); this._detachSecondaryEvents(); this.picker.remove(); delete this.element.data().datepicker; if (!this.isInput) { delete this.element.data().date; } }, _utc_to_local: function (utc) { return new Date(utc.getTime() + (utc.getTimezoneOffset() * 60000)); }, _local_to_utc: function (local) { return new Date(local.getTime() - (local.getTimezoneOffset() * 60000)); }, _zero_time: function (local) { return new Date(local.getFullYear(), local.getMonth(), local.getDate()); }, _zero_utc_time: function (utc) { return new Date(Date.UTC(utc.getUTCFullYear(), utc.getUTCMonth(), utc.getUTCDate())); }, getDate: function () { return this._utc_to_local(this.getUTCDate()); }, getUTCDate: function () { return this.date; }, setDate: function (d) { this.setUTCDate(this._local_to_utc(d)); }, setUTCDate: function (d) { this.date = d; this.setValue(); }, setValue: function () { var formatted = this.getFormattedDate(); if (!this.isInput) { if (this.component) { this.element.find('input').val(formatted).change(); } } else { this.element.val(formatted).change(); } }, getFormattedDate: function (format) { if (format === undefined) format = this.o.format; return DPGlobal.formatDate(this.date, format, this.o.language); }, setStartDate: function (startDate) { this._process_options({ startDate: startDate }); this.update(); this.updateNavArrows(); }, setEndDate: function (endDate) { this._process_options({ endDate: endDate }); this.update(); this.updateNavArrows(); }, setDaysOfWeekDisabled: function (daysOfWeekDisabled) { this._process_options({ daysOfWeekDisabled: daysOfWeekDisabled }); this.update(); this.updateNavArrows(); }, place: function () { if (this.isInline) return; var calendarWidth = this.picker.outerWidth(), calendarHeight = this.picker.outerHeight(), visualPadding = 10, windowWidth = $window.width(), windowHeight = $window.height(), scrollTop = $window.scrollTop(); var zIndex = parseInt(this.element.parents().filter(function () { return $(this).css('z-index') != 'auto'; }).first().css('z-index')) + 10; var offset = this.element.offset(); var height = this.component ? this.component.outerHeight(true) : this.element.outerHeight(false); var width = this.component ? this.component.outerWidth(true) : this.element.outerWidth(false); var left = offset.left, top = offset.top; this.picker.removeClass( 'cognito-datepicker-orient-top cognito-datepicker-orient-bottom ' + 'cognito-datepicker-orient-right cognito-datepicker-orient-left ' + 'cognito-datepicker-center-arrow' ); if (this.o.orientation.x !== 'auto') { this.picker.addClass('cognito-datepicker-orient-' + this.o.orientation.x); if (this.o.orientation.x === 'right') left -= calendarWidth - width; } // auto x orientation is best-placement: if it crosses a window // edge, fudge it sideways else { // Default to left this.picker.addClass('cognito-datepicker-orient-left'); if (offset.left < 0) left -= offset.left - visualPadding; else if (offset.left + calendarWidth > windowWidth) left = windowWidth - calendarWidth - visualPadding; } if (left + calendarWidth + visualPadding >= windowWidth) this.picker.addClass('cognito-datepicker-center-arrow'); // auto y orientation is best-situation: top or bottom, no fudging, // decision based on which shows more of the calendar var yorient = this.o.orientation.y, top_overflow, bottom_overflow; if (yorient === 'auto') { top_overflow = -scrollTop + offset.top - calendarHeight; bottom_overflow = scrollTop + windowHeight - (offset.top + height + calendarHeight); if (Math.max(top_overflow, bottom_overflow) === bottom_overflow) yorient = 'top'; else yorient = 'bottom'; } this.picker.addClass('cognito-datepicker-orient-' + yorient); if (yorient === 'top') top += height + 6; else top -= calendarHeight + parseInt(this.picker.css('padding-top')); this.picker.css({ top: top, left: left, zIndex: zIndex }); }, _allow_update: true, update: function () { if (!this._allow_update) return; var oldDate = new Date(this.date), date, fromArgs = false; if (arguments && arguments.length && (typeof arguments[0] === 'string' || arguments[0] instanceof Date)) { date = arguments[0]; if (date instanceof Date) date = this._local_to_utc(date); fromArgs = true; } else { date = this.isInput ? this.element.val() : this.element.data('date') || this.element.find('input').val(); delete this.element.data().date; } this.date = DPGlobal.parseDate(date, this.o.format, this.o.language); // setting date by clicking? if (fromArgs) this.setValue(); if (this.date < this.o.startDate) { this.viewDate = new Date(this.o.startDate); this.date = new Date(this.o.startDate); } else if (this.date > this.o.endDate) { this.viewDate = new Date(this.o.endDate); this.date = new Date(this.o.endDate); } else { this.viewDate = new Date(this.date); this.date = new Date(this.date); } this.fill(); var keys = [ "37", // left "38", // up "39", // right "40" // down ]; if (arguments && arguments.length && keys.indexOf(arguments[0].keyCode) !== -1) arguments[0].stopPropagation(); }, fillDow: function () { var dowCnt = this.o.weekStart, html = ''; if (this.o.calendarWeeks) { var cell = ' '; html += cell; this.picker.find('.cognito-datepicker-days thead tr:first-child').prepend(cell); } while (dowCnt < this.o.weekStart + 7) { html += '' + dates[this.o.language].daysMin[(dowCnt++) % 7] + ''; } html += ''; this.picker.find('.cognito-datepicker-days thead').append(html); }, fillMonths: function () { var html = '', i = 0; while (i < 12) { html += '' + dates[this.o.language].monthsShort[i++] + ''; } this.picker.find('.cognito-datepicker-months td').html(html); }, setRange: function (range) { if (!range || !range.length) delete this.range; else this.range = $.map(range, function (d) { return d.valueOf(); }); this.fill(); }, getClassNames: function (date) { var cls = [], year = this.viewDate.getUTCFullYear(), month = this.viewDate.getUTCMonth(), currentDate = this.date.valueOf(), today = new Date(); if (date.getUTCFullYear() < year || (date.getUTCFullYear() == year && date.getUTCMonth() < month)) { cls.push('old'); } else if (date.getUTCFullYear() > year || (date.getUTCFullYear() == year && date.getUTCMonth() > month)) { cls.push('new'); } // Compare internal UTC date with local today, not UTC today if (this.o.todayHighlight && date.getUTCFullYear() == today.getFullYear() && date.getUTCMonth() == today.getMonth() && date.getUTCDate() == today.getDate()) { cls.push('today'); } if (currentDate && date.valueOf() == currentDate) { cls.push('active'); } if (date.valueOf() < this.o.startDate || date.valueOf() > this.o.endDate || $.inArray(date.getUTCDay(), this.o.daysOfWeekDisabled) !== -1) { cls.push('disabled'); } if (this.range) { if (date > this.range[0] && date < this.range[this.range.length - 1]) { cls.push('range'); } if ($.inArray(date.valueOf(), this.range) != -1) { cls.push('selected'); } } return cls; }, fill: function () { var d = new Date(this.viewDate), year = d.getUTCFullYear(), month = d.getUTCMonth(), startYear = this.o.startDate !== -Infinity ? this.o.startDate.getUTCFullYear() : -Infinity, startMonth = this.o.startDate !== -Infinity ? this.o.startDate.getUTCMonth() : -Infinity, endYear = this.o.endDate !== Infinity ? this.o.endDate.getUTCFullYear() : Infinity, endMonth = this.o.endDate !== Infinity ? this.o.endDate.getUTCMonth() : Infinity, currentDate = this.date && this.date.valueOf(), tooltip; this.picker.find('.cognito-datepicker-days thead th.datepicker-switch') .text(dates[this.o.language].months[month] + ' ' + year); this.picker.find('tfoot th.today') .text(dates[this.o.language].today) .toggle(this.o.todayBtn !== false); this.picker.find('tfoot th.clear') .text(dates[this.o.language].clear) .toggle(this.o.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.o.weekStart + 7) % 7); var nextMonth = new Date(prevMonth); nextMonth.setUTCDate(nextMonth.getUTCDate() + 42); nextMonth = nextMonth.valueOf(); var html = []; var clsName; while (prevMonth.valueOf() < nextMonth) { if (prevMonth.getUTCDay() == this.o.weekStart) { html.push(''); if (this.o.calendarWeeks) { // ISO 8601: First week contains first thursday. // ISO also states week starts on Monday, but we can be more abstract here. var // Start of current week: based on weekstart/current date ws = new Date(+prevMonth + (this.o.weekStart - prevMonth.getUTCDay() - 7) % 7 * 864e5), // Thursday of this week th = new Date(+ws + (7 + 4 - ws.getUTCDay()) % 7 * 864e5), // First Thursday of year, year from thursday yth = new Date(+(yth = UTCDate(th.getUTCFullYear(), 0, 1)) + (7 + 4 - yth.getUTCDay()) % 7 * 864e5), // Calendar week: ms between thursdays, div ms per day, div 7 days calWeek = (th - yth) / 864e5 / 7 + 1; html.push('' + calWeek + ''); } } clsName = this.getClassNames(prevMonth); clsName.push('day'); if (this.o.beforeShowDay !== $.noop) { var before = this.o.beforeShowDay(this._utc_to_local(prevMonth)); if (before === undefined) before = {}; else if (typeof (before) === 'boolean') before = { enabled: before }; else if (typeof (before) === 'string') before = { classes: before }; if (before.enabled === false) clsName.push('disabled'); if (before.classes) clsName = clsName.concat(before.classes.split(/\s+/)); if (before.tooltip) tooltip = before.tooltip; } clsName = $.unique(clsName); html.push('' + prevMonth.getUTCDate() + ''); if (prevMonth.getUTCDay() == this.o.weekEnd) { html.push(''); } prevMonth.setUTCDate(prevMonth.getUTCDate() + 1); } this.picker.find('.cognito-datepicker-days tbody').empty().append(html.join('')); var currentYear = this.date && this.date.getUTCFullYear(); var months = this.picker.find('.cognito-datepicker-months') .find('th:eq(1)') .text(year) .end() .find('span').removeClass('active'); if (currentYear && currentYear == year) { 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 + 1).addClass('disabled'); } html = ''; year = parseInt(year / 10, 10) * 10; var yearCont = this.picker.find('.cognito-datepicker-years') .find('th:eq(1)') .text(year + '-' + (year + 9)) .end() .find('td'); year -= 1; for (var i = -1; i < 11; i++) { html += '' + year + ''; year += 1; } yearCont.html(html); }, updateNavArrows: function () { if (!this._allow_update) return; var d = new Date(this.viewDate), year = d.getUTCFullYear(), month = d.getUTCMonth(); switch (this.viewMode) { case 0: if (this.o.startDate !== -Infinity && year <= this.o.startDate.getUTCFullYear() && month <= this.o.startDate.getUTCMonth()) { this.picker.find('.prev').css({ visibility: 'hidden' }); } else { this.picker.find('.prev').css({ visibility: 'visible' }); } if (this.o.endDate !== Infinity && year >= this.o.endDate.getUTCFullYear() && month >= this.o.endDate.getUTCMonth()) { this.picker.find('.next').css({ visibility: 'hidden' }); } else { this.picker.find('.next').css({ visibility: 'visible' }); } break; case 1: case 2: if (this.o.startDate !== -Infinity && year <= this.o.startDate.getUTCFullYear()) { this.picker.find('.prev').css({ visibility: 'hidden' }); } else { this.picker.find('.prev').css({ visibility: 'visible' }); } if (this.o.endDate !== Infinity && year >= this.o.endDate.getUTCFullYear()) { this.picker.find('.next').css({ visibility: 'hidden' }); } else { this.picker.find('.next').css({ visibility: 'visible' }); } break; } }, click: function (e) { e.preventDefault(); var target = $(e.target).closest('span, td, th'); if (target.length == 1) { switch (target[0].nodeName.toLowerCase()) { case 'th': switch (target[0].className) { case 'datepicker-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.moveMonth(this.viewDate, dir); this._trigger('changeMonth', this.viewDate); break; case 1: case 2: this.viewDate = this.moveYear(this.viewDate, dir); if (this.viewMode === 1) this._trigger('changeYear', this.viewDate); break; } this.fill(); break; case 'today': var date = new Date(); date = UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0); this.showMode(-2); var which = this.o.todayBtn == 'linked' ? null : 'view'; this._setDate(date, which); break; case 'clear': var element; if (this.isInput) element = this.element; else if (this.component) element = this.element.find('input'); if (element) element.val("").change(); this._trigger('changeDate'); this.update(); if (this.o.autoclose) this.hide(); break; } break; case 'span': if (!target.is('.disabled')) { this.viewDate.setUTCDate(1); if (target.is('.month')) { var day = 1; var month = target.parent().find('span').index(target); var year = this.viewDate.getUTCFullYear(); this.viewDate.setUTCMonth(month); this._trigger('changeMonth', this.viewDate); if (this.o.minViewMode === 1) { this._setDate(UTCDate(year, month, day, 0, 0, 0, 0)); } } else { var year = parseInt(target.text(), 10) || 0; var day = 1; var month = 0; this.viewDate.setUTCFullYear(year); this._trigger('changeYear', this.viewDate); if (this.o.minViewMode === 2) { this._setDate(UTCDate(year, month, day, 0, 0, 0, 0)); } } this.showMode(-1); this.fill(); } 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(); 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._setDate(UTCDate(year, month, day, 0, 0, 0, 0)); } break; } } }, _setDate: function (date, which) { if (!which || which == 'date') this.date = new Date(date); if (!which || which == 'view') this.viewDate = new Date(date); this.fill(); this.setValue(); this._trigger('changeDate'); var element; if (this.isInput) { element = this.element; } else if (this.component) { element = this.element.find('input'); } if (element) { element.change(); } if (this.o.autoclose && (!which || which == 'date')) { this.hide(); } }, 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.o.startDate && date <= this.o.endDate; }, keydown: function (e) { if (this.picker.is(':not(:visible)')) { // allow escape/alt+down to hide and re-show picker if (e.keyCode == 27 || (e.altKey && e.keyCode === 40)) { this.show(e); e.stopPropagation(); } return; } else if (e.altKey && e.keyCode === 38) { e.preventDefault(); e.stopPropagation(); this.hide(); return; } var dateChanged = false, dir, day, month, newDate, newViewDate; switch (e.keyCode) { case 27: // escape this.hide(); e.preventDefault(); break; case 37: // left case 39: // right if (!this.o.keyboardNavigation) break; dir = e.keyCode == 37 ? -1 : 1; if (e.ctrlKey) { newDate = this.moveYear(this.date, dir); newViewDate = this.moveYear(this.viewDate, dir); this._trigger('changeYear', this.viewDate); } else if (e.shiftKey) { newDate = this.moveMonth(this.date, dir); newViewDate = this.moveMonth(this.viewDate, dir); this._trigger('changeMonth', this.viewDate); } else { newDate = new Date(this.date); newDate.setUTCDate(this.date.getUTCDate() + dir); newViewDate = new Date(this.viewDate); newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir); } if (this.dateWithinRange(newDate)) { this.date = newDate; this.viewDate = newViewDate; this.setValue(); this.update(); e.preventDefault(); dateChanged = true; } e.stopPropagation(); break; case 38: // up case 40: // down if (!this.o.keyboardNavigation) break; dir = e.keyCode == 38 ? -1 : 1; if (e.ctrlKey) { newDate = this.moveYear(this.date, dir); newViewDate = this.moveYear(this.viewDate, dir); this._trigger('changeYear', this.viewDate); } else if (e.shiftKey) { newDate = this.moveMonth(this.date, dir); newViewDate = this.moveMonth(this.viewDate, dir); this._trigger('changeMonth', this.viewDate); } else { newDate = new Date(this.date); newDate.setUTCDate(this.date.getUTCDate() + dir * 7); newViewDate = new Date(this.viewDate); newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7); } if (this.dateWithinRange(newDate)) { this.date = newDate; this.viewDate = newViewDate; this.setValue(); this.update(); e.preventDefault(); dateChanged = true; } e.stopPropagation(); break; case 13: // enter // Capture value before setting to see if the date changed var originalElementValue = this.element.val(); this.setValue(); // Update the dateChanged variable so that "changeDate" event is raised appropriately var newElementValue = this.element.val(); if (newElementValue && newElementValue !== originalElementValue) { dateChanged = true; } this.hide(); e.preventDefault(); e.stopPropagation(); break; case 9: // tab this.hide(); break; } if (dateChanged) { this._trigger('changeDate'); var element; if (this.isInput) { element = this.element; } else if (this.component) { element = this.element.find('input'); } if (element) { element.change(); } } }, showMode: function (dir) { if (dir) { this.viewMode = Math.max(this.o.minViewMode, Math.min(2, this.viewMode + dir)); } /* vitalets: fixing bug of very special conditions: jquery 1.7.1 + webkit + show inline datepicker in bootstrap popover. Method show() does not set display css correctly and datepicker 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('.datepicker-'+DPGlobal.modes[this.viewMode].clsName).show(); this.picker.find('>div').hide().filter('.cognito-datepicker-' + DPGlobal.modes[this.viewMode].clsName).css('display', 'block'); this.updateNavArrows(); } }; var DateRangePicker = function (element, options) { this.element = $(element); this.inputs = $.map(options.inputs, function (i) { return i.jquery ? i[0] : i; }); delete options.inputs; $(this.inputs) .datepicker(options) .bind('changeDate', $.proxy(this.dateUpdated, this)); this.pickers = $.map(this.inputs, function (i) { return $(i).data('datepicker'); }); this.updateDates(); }; DateRangePicker.prototype = { updateDates: function () { this.dates = $.map(this.pickers, function (i) { return i.date; }); this.updateRanges(); }, updateRanges: function () { var range = $.map(this.dates, function (d) { return d.valueOf(); }); $.each(this.pickers, function (i, p) { p.setRange(range); }); }, dateUpdated: function (e) { var dp = $(e.target).data('datepicker'), new_date = dp.getUTCDate(), i = $.inArray(e.target, this.inputs), l = this.inputs.length; if (i == -1) return; if (new_date < this.dates[i]) { // Date being moved earlier/left while (i >= 0 && new_date < this.dates[i]) { this.pickers[i--].setUTCDate(new_date); } } else if (new_date > this.dates[i]) { // Date being moved later/right while (i < l && new_date > this.dates[i]) { this.pickers[i++].setUTCDate(new_date); } } this.updateDates(); }, remove: function () { $.map(this.pickers, function (p) { p.remove(); }); delete this.element.data().datepicker; } }; function opts_from_el(el, prefix) { // Derive options from element data-attrs var data = $(el).data(), out = {}, inkey, replace = new RegExp('^' + prefix.toLowerCase() + '([A-Z])'), prefix = new RegExp('^' + prefix.toLowerCase()); for (var key in data) if (prefix.test(key)) { inkey = key.replace(replace, function (_, a) { return a.toLowerCase(); }); out[inkey] = data[key]; } return out; } function opts_from_locale(lang) { // Derive options from locale plugins var out = {}; // Check if "de-DE" style date is available, if not language should // fallback to 2 letter code eg "de" if (!dates[lang]) { lang = lang.split('-')[0] if (!dates[lang]) return; } var d = dates[lang]; $.each(locale_opts, function (i, k) { if (k in d) out[k] = d[k]; }); return out; } var old = $.fn.datepicker; $.fn.datepicker = function (option) { var args = Array.apply(null, arguments); args.shift(); var internal_return, this_return; this.each(function () { var $this = $(this), data = $this.data('datepicker'), options = typeof option == 'object' && option; if (!data) { var elopts = opts_from_el(this, 'date'), // Preliminary otions xopts = $.extend({}, defaults, elopts, options), locopts = opts_from_locale(xopts.language), // Options priority: js args, data-attrs, locales, defaults opts = $.extend({}, defaults, locopts, options, elopts); if ($this.is('.input-daterange') || opts.inputs) { var ropts = { inputs: opts.inputs || $this.find('input').toArray() }; $this.data('datepicker', (data = new DateRangePicker(this, $.extend(opts, ropts)))); } else { $this.data('datepicker', (data = new Datepicker(this, opts))); } } 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; }; var defaults = $.fn.datepicker.defaults = { autoclose: true, beforeShowDay: $.noop, calendarWeeks: false, clearBtn: false, daysOfWeekDisabled: [], endDate: Infinity, forceParse: true, format: 'mm/dd/yyyy', keyboardNavigation: true, language: 'en', minViewMode: 0, orientation: "auto", rtl: false, startDate: -Infinity, startView: 0, todayBtn: false, todayHighlight: false, weekStart: 0 }; var locale_opts = $.fn.datepicker.locale_opts = [ 'format', 'rtl', 'weekStart' ]; $.fn.datepicker.Constructor = Datepicker; var dates = $.fn.datepicker.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"], today: "Today", clear: "Clear" } }; var DPGlobal = { modes: [ { 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]; }, validParts: /dd?|DD?|mmm|mm?|MM?|yy(?:yy)?/g, nonpunctuation: /[^ -\/:-@\[\u3400-\u9fff-`{-~\t\n\r]+/g, parseFormat: function (format) { // 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, '\0').split('\0'), parts = format.match(this.validParts); if (!separators || !separators.length || !parts || parts.length === 0) { throw new Error("Invalid date format."); } return { separators: separators, parts: parts }; }, parseDate: function (date, format, language) { if (date instanceof Date) return date; if (typeof format === 'string') format = DPGlobal.parseFormat(format); 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 = Datepicker.prototype.moveMonth.call(Datepicker.prototype, date, dir); break; case 'w': date.setUTCDate(date.getUTCDate() + dir * 7); break; case 'y': date = Datepicker.prototype.moveYear.call(Datepicker.prototype, date, dir); break; } } return UTCDate(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), 0, 0, 0); } var parts = date && date.match(this.nonpunctuation) || [], date = new Date(), parsed = {}, setters_order = ['yyyy', 'yy', 'M', 'MM', 'm', 'mm', 'd', 'dd'], setters_map = { yyyy: function (d, v) { return d.setUTCFullYear(v); }, yy: function (d, v) { return d.setUTCFullYear(2000 + v); }, m: function (d, v) { if (isNaN(d)) return d; v -= 1; while (v < 0) v += 12; v %= 12; d.setUTCMonth(v); while (d.getUTCMonth() != v) d.setUTCDate(d.getUTCDate() - 1); return d; }, d: function (d, v) { return d.setUTCDate(v); } }, val, filtered, part; setters_map['M'] = setters_map['MM'] = setters_map['mm'] = setters_map['m']; setters_map['dd'] = setters_map['d']; date = UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0); var fparts = format.parts.slice(); // Remove noop parts if (parts.length != fparts.length) { fparts = $(fparts).filter(function (i, p) { return $.inArray(p, setters_order) !== -1; }).toArray(); } // Process remainder if (parts.length == fparts.length) { for (var i = 0, cnt = fparts.length; i < cnt; i++) { val = parseInt(parts[i], 10); part = fparts[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 == p; }); val = $.inArray(filtered[0], dates[language].monthsShort) + 1; break; } } parsed[part] = val; } for (var i = 0, _date, s; i < setters_order.length; i++) { s = setters_order[i]; if (s in parsed && !isNaN(parsed[s])) { _date = new Date(date); setters_map[s](_date, parsed[s]); if (!isNaN(_date)) date = _date; } } } return date; }, formatDate: function (date, format, language) { if (typeof format === 'string') format = DPGlobal.parseFormat(format); var val = { d: date.getUTCDate(), D: dates[language].daysShort[date.getUTCDay()], DD: dates[language].days[date.getUTCDay()], m: date.getUTCMonth() + 1, mmm: dates[language].monthsShort[date.getUTCMonth()], M: dates[language].monthsShort[date.getUTCMonth()], MM: dates[language].months[date.getUTCMonth()], yy: date.getUTCFullYear().toString().substring(2), yyyy: date.getUTCFullYear() }; val.dd = (val.d < 10 ? '0' : '') + val.d; val.mm = (val.m < 10 ? '0' : '') + val.m; 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]]); } return date.join(''); }, headTemplate: '' + '' + '«' + '' + '»' + '' + '', contTemplate: '', footTemplate: '' }; DPGlobal.template = '
' + '
' + '' + DPGlobal.headTemplate + '' + DPGlobal.footTemplate + '
' + '
' + '
' + '' + DPGlobal.headTemplate + DPGlobal.contTemplate + DPGlobal.footTemplate + '
' + '
' + '
' + '' + DPGlobal.headTemplate + DPGlobal.contTemplate + DPGlobal.footTemplate + '
' + '
' + '
'; $.fn.datepicker.DPGlobal = DPGlobal; /* DATEPICKER NO CONFLICT * =================== */ $.fn.datepicker.noConflict = function () { $.fn.datepicker = old; return this; }; /* DATEPICKER DATA-API * ================== */ $(document).on( 'focus.datepicker.data-api click.datepicker.data-api', '[data-provide="datepicker"]', function (e) { var $this = $(this); if ($this.data('datepicker')) return; e.preventDefault(); // component click requires us to explicitly show it $this.datepicker('show'); } ); $(function () { $('[data-provide="datepicker-inline"]').datepicker(); }); }(jQuery)); })(); ;(function() { if (Cognito.config.scripts.indexOf('cognito-timepicker') >= 0) return; else Cognito.config.scripts.push('cognito-timepicker');/*! * Timepicker Component for Twitter Bootstrap * * Copyright 2013 Joris de Wit * * Contributors https://github.com/jdewit/bootstrap-timepicker/graphs/contributors * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ (function ($, window, document, undefined) { 'use strict'; // TIMEPICKER PUBLIC CLASS DEFINITION var Timepicker = function (element, options) { this.widget = ''; this.$element = $(element); this.defaultTime = options.defaultTime; this.disableFocus = options.disableFocus; this.isOpen = options.isOpen; this.minuteStep = options.minuteStep; this.modalBackdrop = options.modalBackdrop; this.secondStep = options.secondStep; this.showInputs = options.showInputs; this.showMeridian = options.showMeridian; this.timeSeparator = options.timeSeparator; if (this.showMeridian) { this.AMDesignator = options.AMDesignator; this.PMDesignator = options.PMDesignator; } this.showSeconds = options.showSeconds; this.template = options.template; this.appendWidgetTo = options.appendWidgetTo; this.twoDigitHourFormat = options.twoDigitHourFormat; this._init(); }; Timepicker.prototype = { constructor: Timepicker, _init: function () { var self = this; if (this.$element.parent().hasClass('c-editor-time')) { this.$element.parent('.c-editor-time').parent().find('.c-editor-time-icon').on({ 'click.timepicker': $.proxy(this.toggleWidget, this) }); this.$element.on({ 'focus.timepicker': $.proxy(function (e) { if (!this.$element.is(".icon-picker-only, .suppress-picker")) this.showOrHighlight(e); }, this), 'click.timepicker': $.proxy(function (e) { if (!this.$element.is(".icon-picker-only")) this.showOrHighlight(e); }, this), 'keydown.timepicker': $.proxy(this.elementKeydown, this), 'blur.timepicker': $.proxy(this.blurElement, this) }); } else { if (this.template) { this.$element.on({ 'focus.timepicker': $.proxy(this.toggleWidget, this), 'click.timepicker': $.proxy(this.toggleWidget, this), 'blur.timepicker': $.proxy(this.blurElement, this) }); } else { this.$element.on({ 'focus.timepicker': $.proxy(this.showOrHighlight, this), 'click.timepicker': $.proxy(this.showOrHighlight, this), 'keydown.timepicker': $.proxy(this.elementKeydown, this), 'blur.timepicker': $.proxy(this.blurElement, this) }); } } if (this.template !== false) { //this.$widget = $(this.getTemplate()).prependTo(this.$element.parents(this.appendWidgetTo)).on('click', $.proxy(this.widgetClick, this)); this.$widget = $(this.getTemplate()).appendTo('body').on('click', $.proxy(this.widgetClick, this)); } else { this.$widget = false; } if (this.showInputs && this.$widget !== false) { this.$widget.find('input').each(function () { $(this).on({ 'click.timepicker': function () { $(this).select(); }, 'keydown.timepicker': $.proxy(self.widgetKeydown, self) }); }); } this.setDefaultTime(this.defaultTime); }, blurElement: function () { this.highlightedUnit = undefined; this.updateFromElementVal(); }, decrementHour: function () { if (this.showMeridian) { if (this.hour === 1) { this.hour = 12; } else if (this.hour === 12) { this.hour--; return this.toggleMeridian(); } else if (this.hour === 0) { this.hour = 11; return this.toggleMeridian(); } else { this.hour--; } } else { if (this.hour === 0) { this.hour = 23; } else { this.hour--; } } this.update(); }, decrementMinute: function (step) { var newVal; if (step) { newVal = this.minute - step; } else { newVal = this.minute - this.minuteStep; } if (newVal < 0) { this.decrementHour(); this.minute = newVal + 60; } else { this.minute = newVal; } this.update(); }, decrementSecond: function () { var newVal = this.second - this.secondStep; if (newVal < 0) { this.decrementMinute(true); this.second = newVal + 60; } else { this.second = newVal; } this.update(); }, elementKeydown: function (e) { switch (e.keyCode) { case 9: //tab this.updateFromElementVal(); if (!this.$element.val()) { this.hideWidget(); } else if (e.shiftKey) { if (this.highlightedUnit === "hour") this.hideWidget(); else { e.preventDefault(); this.highlightPrevUnit(); } } else { switch (this.highlightedUnit) { case 'hour': e.preventDefault(); this.highlightNextUnit(); break; case 'minute': if (this.showMeridian || this.showSeconds) { e.preventDefault(); this.highlightNextUnit(); } else this.hideWidget(); break; case 'second': if (this.showMeridian) { e.preventDefault(); this.highlightNextUnit(); } else this.hideWidget(); break; default: //By default, hide the widget if it is tabbed out of this.hideWidget(); } } break; case 13: // enter key e.preventDefault(); this.update(); if (this.isOpen) { e.stopPropagation(); this.hideWidget(); } break; case 27: // escape this.updateFromElementVal(); this.hideWidget(); break; case 37: // left arrow e.preventDefault(); if (this.isOpen) e.stopPropagation(); if (!this.$element.val()) break; if (this.highlightedUnit) { this.highlightPrevUnit(); this.updateFromElementVal(); } else { // highlight the unit so the parts can be modified this.highlightUnit(); } break; case 38: // up arrow e.preventDefault(); if (this.isOpen) { e.stopPropagation(); if (e.altKey) return this.hideWidget(); } else break; switch (this.highlightedUnit) { case 'hour': this.incrementHour(); this.highlightHour(); break; case 'minute': this.incrementMinute(); this.highlightMinute(); break; case 'second': this.incrementSecond(); this.highlightSecond(); break; case 'meridian': this.toggleMeridian(); this.highlightMeridian(); break; } break; case 39: // right arrow e.preventDefault(); if (this.isOpen) e.stopPropagation(); if (!this.$element.val()) break; if (this.highlightedUnit) { this.updateFromElementVal(); this.highlightNextUnit(); } else { // highlight the unit so the parts can be modified this.highlightUnit(); } break; case 40: // down arrow e.preventDefault(); if (!this.isOpen && e.altKey) { this.showWidget(); e.stopPropagation(); break; } if (this.isOpen) e.stopPropagation(); else break; switch (this.highlightedUnit) { case 'hour': this.decrementHour(); this.highlightHour(); break; case 'minute': this.decrementMinute(); this.highlightMinute(); break; case 'second': this.decrementSecond(); this.highlightSecond(); break; case 'meridian': this.toggleMeridian(); this.highlightMeridian(); break; } break; } }, formatTime: function (hour, minute, second, meridian) { hour = this.twoDigitHourFormat & hour < 10 ? '0' + hour: hour; minute = minute < 10 ? '0' + minute : minute; second = second < 10 ? '0' + second : second; return hour + this.timeSeparator + minute + (this.showSeconds ? this.timeSeparator + second : '') + (this.showMeridian ? ' ' + meridian : ''); }, getCursorPosition: function () { var input = this.$element.get(0); if ('selectionStart' in input) {// Standard-compliant browsers return input.selectionStart; } else if (document.selection) {// IE fix input.focus(); var sel = document.selection.createRange(), selLen = document.selection.createRange().text.length; sel.moveStart('character', -input.value.length); return sel.text.length - selLen; } }, getTemplate: function () { var template, hourTemplate, minuteTemplate, secondTemplate, meridianTemplate, templateContent; if (this.showInputs) { hourTemplate = ''; minuteTemplate = ''; secondTemplate = ''; meridianTemplate = ''; } else { hourTemplate = ''; minuteTemplate = ''; secondTemplate = ''; meridianTemplate = ''; } templateContent = '' + '' + '' + '' + '' + (this.showSeconds ? '' + '' : '') + (this.showMeridian ? '' + '' : '') + '' + '' + ' ' + '' + ' ' + (this.showSeconds ? '' + '' : '') + (this.showMeridian ? '' + '' : '') + '' + '' + '' + '' + '' + (this.showSeconds ? '' + '' : '') + (this.showMeridian ? '' + '' : '') + '' + '
   
' + hourTemplate + '' + this.timeSeparator + '' + minuteTemplate + '' + this.timeSeparator + '' + secondTemplate + ' ' + meridianTemplate + '
  
'; switch (this.template) { case 'modal': template = ''; break; case 'dropdown': template = '
' + templateContent + '
'; break; } return template; }, getTime: function () { return this.formatTime(this.hour, this.minute, this.second, this.meridian); }, hideWidget: function () { if (this.isOpen === false) { return; } if (this.showInputs) { this.updateFromWidgetInputs(); } this.$element.trigger({ 'type': 'hide.timepicker', 'time': { 'value': this.getTime(), 'hours': this.hour, 'minutes': this.minute, 'seconds': this.second, 'meridian': this.meridian } }); if (this.template === 'modal' && this.$widget.modal) { this.$widget.modal('hide'); } else { this.$widget.removeClass('open'); } $(document).off('mousedown.timepicker'); $(document).off('resize.timepicker'); this.isOpen = false; }, showOrHighlight: function () { if (!this.isOpen) { this.showWidget(); } this.highlightUnit(); }, highlightUnit: function () { this.position = this.getCursorPosition(); if (this.position >= 0 && this.position <= 2) { this.highlightHour(); } else if (this.position >= 3 && this.position <= 5) { this.highlightMinute(); } else if (this.position >= 6 && this.position <= 8) { if (this.showSeconds) { this.highlightSecond(); } else { this.highlightMeridian(); } } else if (this.position >= 9 && this.position <= 11) { this.highlightMeridian(); } }, highlightNextUnit: function () { switch (this.highlightedUnit) { case 'hour': this.highlightMinute(); break; case 'minute': if (this.showSeconds) { this.highlightSecond(); } else if (this.showMeridian) { this.highlightMeridian(); } break; case 'second': if (this.showMeridian) { this.highlightMeridian(); } break; //case 'meridian': // this.highlightHour(); // break; } }, highlightPrevUnit: function () { switch (this.highlightedUnit) { //case 'hour': // this.highlightMeridian(); // break; case 'minute': this.highlightHour(); break; case 'second': this.highlightMinute(); break; case 'meridian': if (this.showSeconds) { this.highlightSecond(); } else { this.highlightMinute(); } break; } }, //Universal function for executing the highlighting on select units highlightElement: function (startIndex, endIndex) { var $element = this.$element.get(0); var mod = !this.twoDigitHourFormat && this.hour < 10 ? -1 : 0; startIndex = startIndex + mod < 0 ? 0 : startIndex + mod; endIndex = endIndex + mod > $($element).val().length ? $($element).val().length : endIndex + mod; if ($element.setSelectionRange) { setTimeout(function () { $element.setSelectionRange(startIndex, endIndex); }, 0); } }, highlightHour: function () { this.highlightedUnit = "hour"; this.highlightElement(0, 2); }, highlightMinute: function () { this.highlightedUnit = 'minute'; this.highlightElement(3, 5); }, highlightSecond: function () { this.highlightedUnit = 'second'; this.highlightElement(6, 8); }, highlightMeridian: function () { this.highlightedUnit = 'meridian'; if (this.showSeconds) { this.highlightElement(9, 11); } else { this.highlightElement(6, 8); } }, incrementHour: function () { if (this.showMeridian) { if (this.hour === 11) { this.hour++; return this.toggleMeridian(); } else if (this.hour === 12) { this.hour = 0; } } if (this.hour === 23) { this.hour = 0; } else { this.hour++; } this.update(); }, incrementMinute: function (step) { var newVal; if (step) { newVal = this.minute + step; } else { newVal = this.minute + this.minuteStep - (this.minute % this.minuteStep); } if (newVal > 59) { this.incrementHour(); this.minute = newVal - 60; } else { this.minute = newVal; } this.update(); }, incrementSecond: function () { var newVal = this.second + this.secondStep - (this.second % this.secondStep); if (newVal > 59) { this.incrementMinute(true); this.second = newVal - 60; } else { this.second = newVal; } this.update(); }, remove: function () { $('document').off('.timepicker'); if (this.$widget) { this.$widget.remove(); } delete this.$element.data().timepicker; }, setDefaultTime: function (defaultTime) { if (!this.$element.val()) { if (defaultTime === 'current') { var dTime = new Date(), hours = dTime.getHours(), minutes = Math.floor(dTime.getMinutes() / this.minuteStep) * this.minuteStep, seconds = Math.floor(dTime.getSeconds() / this.secondStep) * this.secondStep, meridian = this.AMDesignator; if (this.showMeridian) { if (hours === 0) { hours = 12; } else if (hours >= 12) { if (hours > 12) { hours = hours - 12; } meridian = this.PMDesignator; } else { meridian = this.AMDesignator; } } this.hour = hours; this.minute = minutes; this.second = seconds; this.meridian = meridian; } else if (defaultTime === false) { this.hour = 0; this.minute = 0; this.second = 0; this.meridian = this.AMDesignator; } else { this.setTime(defaultTime); } } else { this.updateFromElementVal(); } }, setTime: function (time) { var arr, timeArray; if (this.showMeridian) { arr = time.split(' '); timeArray = arr[0].split(this.timeSeparator); this.meridian = time.substr(time.indexOf(' ') + 1); } else { timeArray = time.split(this.timeSeparator); } this.hour = parseInt(timeArray[0], 10); this.minute = parseInt(timeArray[1], 10); this.second = parseInt(timeArray[2], 10); if (isNaN(this.hour)) { this.hour = 0; } if (isNaN(this.minute)) { this.minute = 0; } if (this.showMeridian) { if (this.hour > 12) { this.hour = 12; } else if (this.hour < 1) { this.hour = 12; } if (this.meridian.toUpperCase() !== this.AMDesignator.toUpperCase() && this.meridian.toUpperCase() !== this.PMDesignator.toUpperCase()) { this.meridian = this.AMDesignator; } } else { if (this.hour >= 24) { this.hour = 23; } else if (this.hour < 0) { this.hour = 0; } } if (this.minute < 0) { this.minute = 0; } else if (this.minute >= 60) { this.minute = 59; } if (this.showSeconds) { if (isNaN(this.second)) { this.second = 0; } else if (this.second < 0) { this.second = 0; } else if (this.second >= 60) { this.second = 59; } } this.update(); }, place: function () { var scrollTop = $(window).scrollTop(); var widgetWidth = this.$widget.width(); var widgetHeight = this.$widget.height(); var windowWidth = $(window).width(); var windowHeight = $(window).height(); var offset = this.$element.offset(); var height = this.$element.outerHeight(false); var width = this.$element.outerWidth(false); var top = offset.top; var left = offset.left; this.$widget.removeClass('cognito-timepicker-orient-top cognito-timepicker-orient-bottom'); var yorient; var topOverflow = -scrollTop + offset.top - widgetHeight; var bottomOverflow = scrollTop + windowHeight - (offset.top + height + widgetHeight); if (Math.max(topOverflow, bottomOverflow) === bottomOverflow) yorient = 'top'; else yorient = 'bottom'; this.$widget.addClass('cognito-timepicker-orient-' + yorient); if (yorient === 'top') top += height + 6; else top -= widgetHeight + parseInt(this.$widget.css('padding-top')) + 8; this.$widget.css({ top: top, left: left }); }, //Toggles the widget open and close toggleWidget: function () { if (this.isOpen === true) { this.hideWidget(); } else { this.showWidget(); } }, showWidget: function () { if (this.isOpen) { return; } if (this.$element.is(':disabled')) { return; } //If the time has not been set when the widget is opened, set it to it's default time if (this.getTime() == '0' + this.timeSeparator + '00 ' + this.AMDesignator) this.setDefaultTime(this.defaultTime); this.updateWidget(); this.place(); var self = this; $(document).on('mousedown.timepicker', function (e) { //If there is an open time picker widget and the target is not the time picker, it's icon, or it's field, then close the widget if ( $(e.target).closest('.cognito-timepicker-widget').length === 0 && ( //the user is not clicking the editor or icon that belongs to this field !(self.$element.is(e.target) || e.target.className.indexOf("c-editor-time") > -1 || e.target.className.indexOf("icon-time") > -1 || e.target.className.indexOf("time-icon") > -1) || $(e.target).parents(".c-date-time")[0] !== $(self.$element).parents(".c-date-time")[0] ) ) { self.hideWidget(); } }); //Replace on document resize $(document).on('resize.timepicker', function (e) { self.place(); }); this.$element.trigger({ 'type': 'show.timepicker', 'time': { 'value': this.getTime(), 'hours': this.hour, 'minutes': this.minute, 'seconds': this.second, 'meridian': this.meridian } }); if (this.disableFocus) { this.$element.blur(); } this.updateFromElementVal(); if (this.template === 'modal' && this.$widget.modal) { this.$widget.modal('show').on('hidden', $.proxy(this.hideWidget, this)); } else { if (this.isOpen === false) { this.$widget.addClass('open'); } } this.isOpen = true; }, toggleMeridian: function () { this.meridian = this.meridian === this.AMDesignator ? this.PMDesignator : this.AMDesignator; this.update(); }, update: function () { this.updateElement(); this.$element.trigger({ 'type': 'changeTime.timepicker', 'time': { 'value': this.getTime(), 'hours': this.hour, 'minutes': this.minute, 'seconds': this.second, 'meridian': this.meridian } }); this.updateWidget(); }, updateElement: function () { this.$element.val(this.getTime()).change(); }, updateFromElementVal: function () { var val = this.$element.val(); if (val) { this.setTime(val); } }, updateWidget: function () { if (this.$widget === false) { return; } var hour = this.hour < 10 ? '0' + this.hour : this.hour, minute = this.minute < 10 ? '0' + this.minute : this.minute, second = this.second < 10 ? '0' + this.second : this.second; if (this.showInputs) { this.$widget.find('input.cognito-timepicker-hour').val(hour); this.$widget.find('input.cognito-timepicker-minute').val(minute); if (this.showSeconds) { this.$widget.find('input.cognito-timepicker-second').val(second); } if (this.showMeridian) { this.$widget.find('input.cognito-timepicker-meridian').val(this.meridian); } } else { this.$widget.find('span.cognito-timepicker-hour').text(hour); this.$widget.find('span.cognito-timepicker-minute').text(minute); if (this.showSeconds) { this.$widget.find('span.cognito-timepicker-second').text(second); } if (this.showMeridian) { this.$widget.find('span.cognito-timepicker-meridian').text(this.meridian); } } }, updateFromWidgetInputs: function () { if (this.$widget === false || this.$element.val() === "") { return; } var time = $('input.cognito-timepicker-hour', this.$widget).val() + this.timeSeparator + $('input.cognito-timepicker-minute', this.$widget).val() + (this.showSeconds ? this.timeSeparator + $('input.cognito-timepicker-second', this.$widget).val() : '') + (this.showMeridian ? ' ' + $('input.cognito-timepicker-meridian', this.$widget).val() : ''); this.setTime(time); }, widgetClick: function (e) { e.stopPropagation(); e.preventDefault(); var action = $(e.target).closest('a').data('action'); if (action) { this[action](); } }, widgetKeydown: function (e) { var $input = $(e.target).closest('input'), name = $input.attr('name'); switch (e.keyCode) { case 9: //tab if (this.showMeridian) { if (name === 'meridian') { return this.hideWidget(); } } else { if (this.showSeconds) { if (name === 'second') { return this.hideWidget(); } } else { if (name === 'minute') { return this.hideWidget(); } } } this.updateFromWidgetInputs(); break; case 27: // escape this.hideWidget(); break; case 38: // up arrow e.preventDefault(); switch (name) { case 'hour': this.incrementHour(); break; case 'minute': this.incrementMinute(); break; case 'second': this.incrementSecond(); break; case 'meridian': this.toggleMeridian(); break; } break; case 40: // down arrow e.preventDefault(); switch (name) { case 'hour': this.decrementHour(); break; case 'minute': this.decrementMinute(); break; case 'second': this.decrementSecond(); break; case 'meridian': this.toggleMeridian(); break; } break; } } }; //TIMEPICKER PLUGIN DEFINITION $.fn.timepicker = function (option) { var args = Array.apply(null, arguments); args.shift(); return this.each(function () { var $this = $(this), data = $this.data('timepicker'), options = typeof option === 'object' && option; if (!data) { $this.data('timepicker', (data = new Timepicker(this, $.extend({}, $.fn.timepicker.defaults, options, $(this).data())))); } if (typeof option === 'string') { data[option].apply(data, args); } }); }; $.fn.timepicker.defaults = { defaultTime: 'current', disableFocus: false, isOpen: false, minuteStep: 15, modalBackdrop: false, secondStep: 15, showSeconds: false, showInputs: true, showMeridian: true, template: 'dropdown', appendWidgetTo: '.cognito-timepicker', timeSeparator: ':', AMDesignator: "AM", PMDesignator: "PM", twoDigitHourFormat: false }; $.fn.timepicker.Constructor = Timepicker; })(jQuery, window, document); })(); ;(function() { if (Cognito.config.scripts.indexOf('cognito-typeahead') >= 0) return; else Cognito.config.scripts.push('cognito-typeahead');/** * bootstrap-typeahead.js * Copyright 2013 Twitter, Inc. * http://www.apache.org/licenses/LICENSE-2.0.txt */ /* ============================================================= * bootstrap-typeahead.js v2.3.2 * http://getbootstrap.com/2.3.2/javascript.html#typeahead * ============================================================= * Copyright 2013 Twitter, Inc. * * 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 ($) { "use strict"; // jshint ;_; /* TYPEAHEAD PUBLIC CLASS DEFINITION * ================================= */ var Typeahead = function (element, options) { this.$element = $(element) this.options = $.extend({}, $.fn.typeahead.defaults, options) this.matcher = this.options.matcher || this.matcher this.sorter = this.options.sorter || this.sorter this.highlighter = this.options.highlighter || this.highlighter this.updater = this.options.updater || this.updater this.source = this.options.source || $.map(this.$element[0].__msajaxbindings[0]._source.get_options(), function (val, i) { return val.get_displayValue(); }), this.$menu = $(this.options.menu) this.shown = false this.listen() } Typeahead.prototype = { constructor: Typeahead , select: function () { var val = this.$menu.find('.active').attr('data-value') this.$element .val(this.updater(val)) .change() $simulateMutationEvent(this.$element.get(0), "change", false, true) return this.hide() } , updater: function (item) { return item } , show: function () { var pos = $.extend({}, this.$element.position(), { height: this.$element[0].offsetHeight }) this.$menu .insertAfter(this.$element) .css({ top: pos.top + pos.height , left: pos.left }) .show() var $pageContainer = this.$element.closest('.c-forms-pages') if ($pageContainer.length) { var currentHeight = this.$menu.get(0).offsetHeight var maxHeight = $pageContainer.get(0).offsetHeight - (pos.top + pos.height); if (currentHeight > maxHeight) { this.$menu.css({ height: maxHeight , overflow: 'auto' }) } } this.shown = true return this } , hide: function () { this.$menu.hide() this.shown = false return this } , lookup: function (event) { var items this.query = this.$element.val() if (!this.query || this.query.length < this.options.minLength) { return this.shown ? this.hide() : this } items = $.isFunction(this.source) ? this.source(this.query, $.proxy(this.process, this)) : this.source return items ? this.process(items) : this } , process: function (items) { var that = this items = $.grep(items, function (item) { return that.matcher(item) }) items = this.sorter(items) if (!items.length) { return this.shown ? this.hide() : this } return this.render(items.slice(0, this.options.items)).show() } , matcher: function (item) { return ~item.toLowerCase().indexOf(this.query.toLowerCase()) } , sorter: function (items) { var beginswith = [] , caseSensitive = [] , caseInsensitive = [] , item while (item = items.shift()) { if (!item.toLowerCase().indexOf(this.query.toLowerCase())) beginswith.push(item) else if (~item.indexOf(this.query)) caseSensitive.push(item) else caseInsensitive.push(item) } return beginswith.concat(caseSensitive, caseInsensitive) } , highlighter: function (item) { var query = this.query.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&') return item.replace(new RegExp('(' + query + ')', 'ig'), function ($1, match) { return '' + match + '' }) } , render: function (items) { var that = this items = $(items).map(function (i, item) { i = $(that.options.item).attr('data-value', item) i.find('a').html(that.highlighter(item)) return i[0] }) items.first().addClass('active') this.$menu.html(items) return this } , next: function (event) { var active = this.$menu.find('.active').removeClass('active') , next = active.next() if (!next.length) { next = $(this.$menu.find('li')[0]) } next.addClass('active') var index = parseInt(next.attr('data-index')); var liPos = (index + 1) * 26; if (index == 0) this.$menu.scrollTop(0); else if (liPos > this.$menu.height()+this.$menu.scrollTop()) this.$menu.scrollTop(liPos - this.$menu.height()); } , prev: function (event) { var active = this.$menu.find('.active').removeClass('active') , prev = active.prev() var isLast = false; if (!prev.length) { prev = this.$menu.find('li').last() isLast = true; } prev.addClass('active') var index = parseInt(prev.attr('data-index')); var liPos = index * 26; if (isLast) this.$menu.scrollTop(liPos); else if (liPos < this.$menu.scrollTop()) this.$menu.scrollTop(liPos); } , listen: function () { this.$element .on('focus', $.proxy(this.focus, this)) .on('blur', $.proxy(this.blur, this)) .on('keyup', $.proxy(this.keyup, this)) if (this.eventSupported('keydown')) { this.$element.on('keydown', $.proxy(this.keydown, this)) } this.$menu .on('click', $.proxy(this.click, this)) .on('mouseenter', 'li', $.proxy(this.mouseenter, this)) .on('mouseleave', 'li', $.proxy(this.mouseleave, this)) .on('mouseenter', $.proxy(this.mouseentermenu, this)) .on('mouseleave', $.proxy(this.mouseleavemenu, this)) .on('mouseup', $.proxy(this.mouseup, this)) } , eventSupported: function (eventName) { var isSupported = eventName in this.$element if (!isSupported) { this.$element.setAttribute(eventName, 'return;') isSupported = typeof this.$element[eventName] === 'function' } return isSupported } , move: function (e) { if (!this.shown) return switch (e.keyCode) { case 9: // tab case 13: // enter case 27: // escape e.preventDefault() break case 38: // up arrow e.preventDefault() this.prev() break case 40: // down arrow e.preventDefault() this.next() break } e.stopPropagation() } , keydown: function (e) { this.suppressKeyPressRepeat = ~$.inArray(e.keyCode, [40, 38, 9, 13, 27]) this.move(e) } , keyup: function (e) { switch (e.keyCode) { case 40: // down arrow case 38: // up arrow case 16: // shift case 17: // ctrl case 18: // alt break case 9: // tab case 13: // enter if (!this.shown) return this.select() break case 27: // escape if (!this.shown) return this.hide() break default: this.lookup() } e.stopPropagation() e.preventDefault() } , focus: function (e) { this.focused = true } , blur: function (e) { this.focused = false if (!this.mousedovermenu && this.shown) this.hide() } , click: function (e) { e.stopPropagation() e.preventDefault() this.select() this.$element.focus() } , mouseenter: function (e) { this.mousedover = true this.$menu.find('.active').removeClass('active') $(e.currentTarget).addClass('active') } , mouseleave: function (e) { this.mousedover = false } , mouseentermenu: function (e) { this.mousedovermenu = true } , mouseleavemenu: function (e) { this.mousedovermenu = false } , mouseup: function (e) { var selectedElement = this.$menu.find('.active') if (this.mousedovermenu && !this.mousedover) { this.focusItem = selectedElement this.$element.focus() } } } /* TYPEAHEAD PLUGIN DEFINITION * =========================== */ var old = $.fn.typeahead $.fn.typeahead = function (option) { return this.each(function () { var $this = $(this) , data = $this.data('typeahead') , options = typeof option == 'object' && option if (!data) $this.data('typeahead', (data = new Typeahead(this, options))) if (typeof option == 'string') data[option]() }) } $.fn.typeahead.defaults = { source: [] , items: 8 , menu: '' , item: '
  • ' , minLength: 1 } $.fn.typeahead.Constructor = Typeahead /* TYPEAHEAD NO CONFLICT * =================== */ $.fn.typeahead.noConflict = function () { $.fn.typeahead = old return this } /* TYPEAHEAD DATA-API * ================== */ $(document).on('focus.typeahead.data-api', '[data-provide="typeahead"]', function (e) { var $this = $(this) if ($this.data('typeahead')) return $this.typeahead($this.data()) }) }(jQuery); /* ============================================================= * bootstrap-better-typeahead.js v1.0.0 by Philipp Nolte * https://github.com/ptnplanet/Bootstrap-Better-Typeahead * ============================================================= * This plugin makes use of twitter bootstrap typeahead * http://twitter.github.com/bootstrap/javascript.html#typeahead * * Bootstrap is licensed under the Apache License, Version 2.0 * http://www.apache.org/licenses/LICENSE-2.0 * ============================================================ */ !function($) { "use strict"; /** * The better typeahead plugin will extend the bootstrap typeahead plugin and provide the ability to set the * minLength option to zero. The tab keyup event handler had to be moved to the keydown event handler, so that * the full list of available items is shown on tab-focus and the original behaviour is preserved as best as * possible. * * @type {object} */ var BetterTypeahead = { lookup: function(event) { var items; // Now supports empty queries (eg. with a length of 0). this.query = this.$element.val() || ''; if (this.query.length < this.options.minLength) { return this.shown ? this.hide() : this; } items = $.isFunction(this.source) ? this.source(this.query, $.proxy(this.process, this)) : this.source; return items ? this.process(items) : this; } , process: function (items) { var that = this; items = $.grep(items, function (item) { return that.matcher(item); }); items = this.sorter(items); if (!items.length) { return this.shown ? this.hide() : this; } if (this.query.length) { items = items.slice(0, this.options.items); } if (this.focusItem) { this.focusItem = null; return; } return this.render(items).show(); } , render: function (items) { var that = this items = $(items).map(function (i, item) { var li = $(that.options.item).attr('data-value', item); li.attr('data-index', i); li.find('a').html(that.highlighter(item)); return li[0]; }); if (this.query.length > 0) { if (this.focusItem) return; else items.first().addClass('active'); } this.$menu.html(items); return this; } , move: function (e) { if (!this.shown) return; switch (e.keyCode) { case 9: // tab case 13: // enter if (this.options.useTabToSelect === true) e.preventDefault(); else if (this.shown) { this.select() this.hide(); } break; case 27: // escape e.preventDefault(); break; case 38: // up arrow e.preventDefault(); this.prev(); e.stopPropagation(); break; case 40: // down arrow e.preventDefault(); this.next(); e.stopPropagation(); break; } } , keydown: function (e) { this.suppressKeyPressRepeat = ~$.inArray(e.keyCode, [40,38,9,13,27]); this.move(e); } , keyup: function (e) { switch(e.keyCode) { case 37: // left case 39: // right return; case 40: // down arrow case 38: // up arrow case 16: // shift case 17: // ctrl case 18: // alt break; case 13: // enter case 9: // tab if (!this.shown) return; this.select(); this.show(); break; case 27: // escape; if (!this.shown) return; this.hide(); break; default: this.lookup(); } //if (!this.options.useTabToSelect) e.stopPropagation(); e.preventDefault(); } , focus: function(e) { this.focused = true; if (!this.mousedover) { this.lookup(e); } } }; $.extend($.fn.typeahead.Constructor.prototype, BetterTypeahead); }(jQuery); })(); ;(function() { if (Cognito.config.scripts.indexOf('cognito-toggle') >= 0) return; else Cognito.config.scripts.push('cognito-toggle');/*! ============================================================ * bootstrapSwitch v1.8 by Larentis Mattia @SpiritualGuru * http://www.larentis.eu/ * * Enhanced for radiobuttons by Stein, Peter @BdMdesigN * http://www.bdmdesign.org/ * * Project site: * http://www.larentis.eu/switch/ * ============================================================ * Licensed under the Apache License, Version 2.0 * http://www.apache.org/licenses/LICENSE-2.0 * ============================================================ */ !function ($) { "use strict"; $.fn['bootstrapSwitch'] = function (method) { var methods = { init: function () { return this.each(function () { var $element = $(this).parent() , $input = $(this) , $div , $switchLeft , $switchRight , $label , $form = $element.closest('form') , myClasses = "" , classes = $element.attr('class') , color , moving , onLabel = "ON" , offLabel = "OFF" , icon = false , textLabel = false; /* $.each(['switch-mini', 'switch-small', 'switch-large'], function (i, el) { if (classes.indexOf(el) >= 0) myClasses = el; }); */ $element.addClass('has-switch'); if ($element.data('on') !== undefined) color = "switch-" + $element.data('on'); if ($element.data('on-label') !== undefined) onLabel = $element.data('on-label'); if ($element.data('off-label') !== undefined) offLabel = $element.data('off-label'); if ($element.data('label-icon') !== undefined) icon = $element.data('label-icon'); if ($element.data('text-label') !== undefined) textLabel = $element.data('text-label'); $switchLeft = $('') .addClass("switch-left") .addClass(myClasses) .addClass(color) .html('' + onLabel + ''); color = ''; if ($element.data('off') !== undefined) color = "switch-" + $element.data('off'); $switchRight = $('') .addClass("switch-right") .addClass(myClasses) .addClass(color) .html('' + offLabel + ''); $label = $('