From 4c84a2ce615be12adfbeb1067b5c6652330027bb Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Sun, 22 Nov 2015 00:13:33 +0100 Subject: update datetimepicker and fix it for finish date --- library/datetimepicker/jquery.datetimepicker.js | 576 ++++++++++++++++++++---- 1 file changed, 494 insertions(+), 82 deletions(-) (limited to 'library/datetimepicker/jquery.datetimepicker.js') diff --git a/library/datetimepicker/jquery.datetimepicker.js b/library/datetimepicker/jquery.datetimepicker.js index d4e93dd13..9c00413c2 100644 --- a/library/datetimepicker/jquery.datetimepicker.js +++ b/library/datetimepicker/jquery.datetimepicker.js @@ -1,9 +1,9 @@ /** - * @preserve jQuery DateTimePicker plugin v2.4.0 + * @preserve jQuery DateTimePicker plugin v2.4.5 * @homepage http://xdsoft.net/jqplugins/datetimepicker/ * (c) 2014, Chupurnov Valeriy. */ -/*global document,window,jQuery,setTimeout,clearTimeout*/ +/*global document,window,jQuery,setTimeout,clearTimeout,HighlightedDate,getCurrentValue*/ (function ($) { 'use strict'; var default_options = { @@ -29,7 +29,15 @@ "Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember" ], dayOfWeek: [ - "Sen", "Sel", "Rab", "Kam", "Jum", "Sab", "Min" + "Min", "Sen", "Sel", "Rab", "Kam", "Jum", "Sab" + ] + }, + is: { // Icelandic + months: [ + "Janúar", "Febrúar", "Mars", "Apríl", "Maí", "Júní", "Júlí", "Ágúst", "September", "Október", "Nóvember", "Desember" + ], + dayOfWeek: [ + "Sun", "Mán", "Þrið", "Mið", "Fim", "Fös", "Lau" ] }, bg: { // Bulgarian @@ -231,7 +239,207 @@ dayOfWeek: [ "Va", "Hé", "Ke", "Sze", "Cs", "Pé", "Szo" ] - } + }, + az: { //Azerbaijanian (Azeri) + months: [ + "Yanvar", "Fevral", "Mart", "Aprel", "May", "Iyun", "Iyul", "Avqust", "Sentyabr", "Oktyabr", "Noyabr", "Dekabr" + ], + dayOfWeek: [ + "B", "Be", "Ça", "Ç", "Ca", "C", "Ş" + ] + }, + bs: { //Bosanski + months: [ + "Januar", "Februar", "Mart", "April", "Maj", "Jun", "Jul", "Avgust", "Septembar", "Oktobar", "Novembar", "Decembar" + ], + dayOfWeek: [ + "Ned", "Pon", "Uto", "Sri", "Čet", "Pet", "Sub" + ] + }, + ca: { //Català + months: [ + "Gener", "Febrer", "Març", "Abril", "Maig", "Juny", "Juliol", "Agost", "Setembre", "Octubre", "Novembre", "Desembre" + ], + dayOfWeek: [ + "Dg", "Dl", "Dt", "Dc", "Dj", "Dv", "Ds" + ] + }, + 'en-GB': { //English (British) + months: [ + "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" + ], + dayOfWeek: [ + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" + ] + }, + et: { //"Eesti" + months: [ + "Jaanuar", "Veebruar", "Märts", "Aprill", "Mai", "Juuni", "Juuli", "August", "September", "Oktoober", "November", "Detsember" + ], + dayOfWeek: [ + "P", "E", "T", "K", "N", "R", "L" + ] + }, + eu: { //Euskara + months: [ + "Urtarrila", "Otsaila", "Martxoa", "Apirila", "Maiatza", "Ekaina", "Uztaila", "Abuztua", "Iraila", "Urria", "Azaroa", "Abendua" + ], + dayOfWeek: [ + "Ig.", "Al.", "Ar.", "Az.", "Og.", "Or.", "La." + ] + }, + fi: { //Finnish (Suomi) + months: [ + "Tammikuu", "Helmikuu", "Maaliskuu", "Huhtikuu", "Toukokuu", "Kesäkuu", "Heinäkuu", "Elokuu", "Syyskuu", "Lokakuu", "Marraskuu", "Joulukuu" + ], + dayOfWeek: [ + "Su", "Ma", "Ti", "Ke", "To", "Pe", "La" + ] + }, + gl: { //Galego + months: [ + "Xan", "Feb", "Maz", "Abr", "Mai", "Xun", "Xul", "Ago", "Set", "Out", "Nov", "Dec" + ], + dayOfWeek: [ + "Dom", "Lun", "Mar", "Mer", "Xov", "Ven", "Sab" + ] + }, + hr: { //Hrvatski + months: [ + "Siječanj", "Veljača", "Ožujak", "Travanj", "Svibanj", "Lipanj", "Srpanj", "Kolovoz", "Rujan", "Listopad", "Studeni", "Prosinac" + ], + dayOfWeek: [ + "Ned", "Pon", "Uto", "Sri", "Čet", "Pet", "Sub" + ] + }, + ko: { //Korean (한국어) + months: [ + "1월", "2월", "3월", "4월", "5월", "6월", "7월", "8월", "9월", "10월", "11월", "12월" + ], + dayOfWeek: [ + "일", "월", "화", "수", "목", "금", "토" + ] + }, + lt: { //Lithuanian (lietuvių) + months: [ + "Sausio", "Vasario", "Kovo", "Balandžio", "Gegužės", "Birželio", "Liepos", "Rugpjūčio", "Rugsėjo", "Spalio", "Lapkričio", "Gruodžio" + ], + dayOfWeek: [ + "Sek", "Pir", "Ant", "Tre", "Ket", "Pen", "Šeš" + ] + }, + lv: { //Latvian (Latviešu) + months: [ + "Janvāris", "Februāris", "Marts", "Aprīlis ", "Maijs", "Jūnijs", "Jūlijs", "Augusts", "Septembris", "Oktobris", "Novembris", "Decembris" + ], + dayOfWeek: [ + "Sv", "Pr", "Ot", "Tr", "Ct", "Pk", "St" + ] + }, + mk: { //Macedonian (Македонски) + months: [ + "јануари", "февруари", "март", "април", "мај", "јуни", "јули", "август", "септември", "октомври", "ноември", "декември" + ], + dayOfWeek: [ + "нед", "пон", "вто", "сре", "чет", "пет", "саб" + ] + }, + mn: { //Mongolian (Монгол) + months: [ + "1-р сар", "2-р сар", "3-р сар", "4-р сар", "5-р сар", "6-р сар", "7-р сар", "8-р сар", "9-р сар", "10-р сар", "11-р сар", "12-р сар" + ], + dayOfWeek: [ + "Дав", "Мяг", "Лха", "Пүр", "Бсн", "Бям", "Ням" + ] + }, + 'pt-BR': { //Português(Brasil) + months: [ + "Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro" + ], + dayOfWeek: [ + "Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sáb" + ] + }, + sk: { //Slovenčina + months: [ + "Január", "Február", "Marec", "Apríl", "Máj", "Jún", "Júl", "August", "September", "Október", "November", "December" + ], + dayOfWeek: [ + "Ne", "Po", "Ut", "St", "Št", "Pi", "So" + ] + }, + sq: { //Albanian (Shqip) + months: [ + "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" + ], + dayOfWeek: [ + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" + ] + }, + 'sr-YU': { //Serbian (Srpski) + months: [ + "Januar", "Februar", "Mart", "April", "Maj", "Jun", "Jul", "Avgust", "Septembar", "Oktobar", "Novembar", "Decembar" + ], + dayOfWeek: [ + "Ned", "Pon", "Uto", "Sre", "čet", "Pet", "Sub" + ] + }, + sr: { //Serbian Cyrillic (Српски) + months: [ + "јануар", "фебруар", "март", "април", "мај", "јун", "јул", "август", "септембар", "октобар", "новембар", "децембар" + ], + dayOfWeek: [ + "нед", "пон", "уто", "сре", "чет", "пет", "суб" + ] + }, + sv: { //Svenska + months: [ + "Januari", "Februari", "Mars", "April", "Maj", "Juni", "Juli", "Augusti", "September", "Oktober", "November", "December" + ], + dayOfWeek: [ + "Sön", "Mån", "Tis", "Ons", "Tor", "Fre", "Lör" + ] + }, + 'zh-TW': { //Traditional Chinese (繁體中文) + months: [ + "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月" + ], + dayOfWeek: [ + "日", "一", "二", "三", "四", "五", "六" + ] + }, + zh: { //Simplified Chinese (简体中文) + months: [ + "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月" + ], + dayOfWeek: [ + "日", "一", "二", "三", "四", "五", "六" + ] + }, + he: { //Hebrew (עברית) + months: [ + 'ינואר', 'פברואר', 'מרץ', 'אפריל', 'מאי', 'יוני', 'יולי', 'אוגוסט', 'ספטמבר', 'אוקטובר', 'נובמבר', 'דצמבר' + ], + dayOfWeek: [ + 'א\'', 'ב\'', 'ג\'', 'ד\'', 'ה\'', 'ו\'', 'שבת' + ] + }, + hy: { // Armenian + months: [ + "Հունվար", "Փետրվար", "Մարտ", "Ապրիլ", "Մայիս", "Հունիս", "Հուլիս", "Օգոստոս", "Սեպտեմբեր", "Հոկտեմբեր", "Նոյեմբեր", "Դեկտեմբեր" + ], + dayOfWeek: [ + "Կի", "Երկ", "Երք", "Չոր", "Հնգ", "Ուրբ", "Շբթ" + ] + }, + kg: { // Kyrgyz + months: [ + 'Үчтүн айы', 'Бирдин айы', 'Жалган Куран', 'Чын Куран', 'Бугу', 'Кулжа', 'Теке', 'Баш Оона', 'Аяк Оона', 'Тогуздун айы', 'Жетинин айы', 'Бештин айы' + ], + dayOfWeek: [ + "Жек", "Дүй", "Шей", "Шар", "Бей", "Жум", "Ише" + ] + } }, value: '', lang: 'en', @@ -245,6 +453,7 @@ monthChangeSpinner: true, closeOnDateSelect: false, + closeOnTimeSelect: true, closeOnWithoutClick: true, closeOnInputClick: true, @@ -259,6 +468,8 @@ maxDate: false, minTime: false, maxTime: false, + disabledMinTime: false, + disabledMaxTime: false, allowTimes: [], opened: false, @@ -278,13 +489,15 @@ withoutCopyright: true, inverseButton: false, hours12: false, - next: 'xdsoft_next', + next: 'xdsoft_next', prev : 'xdsoft_prev', dayOfWeekStart: 0, parentID: 'body', timeHeightInTimePicker: 25, timepickerScrollbar: true, todayButton: true, + prevButton: true, + nextButton: true, defaultSelect: true, scrollMonth: true, @@ -297,19 +510,43 @@ allowBlank: true, yearStart: 1950, yearEnd: 2050, + monthStart: 0, + monthEnd: 11, style: '', id: '', fixed: false, roundTime: 'round', // ceil, floor className: '', weekends: [], + highlightedDates: [], + highlightedPeriods: [], disabledDates : [], + disabledWeekDays: [], yearOffset: 0, beforeShowDay: null, - enterLikeTab: true + enterLikeTab: true, + showApplyButton: false }; // fix for ie8 + if (!window.getComputedStyle) { + window.getComputedStyle = function (el, pseudo) { + this.el = el; + this.getPropertyValue = function (prop) { + var re = /(\-([a-z]){1})/g; + if (prop === 'float') { + prop = 'styleFloat'; + } + if (re.test(prop)) { + prop = prop.replace(re, function (a, b, c) { + return c.toUpperCase(); + }); + } + return el.currentStyle[prop] || null; + }; + return this; + }; + } if (!Array.prototype.indexOf) { Array.prototype.indexOf = function (obj, start) { var i, j; @@ -506,12 +743,11 @@ lazyInitTimer = 0, createDateTimePicker, destroyDateTimePicker, - _xdsoft_datetime, lazyInit = function (input) { input .on('open.xdsoft focusin.xdsoft mousedown.xdsoft', function initOnActionCallback(event) { - if (input.is(':disabled') || input.is(':hidden') || !input.is(':visible') || input.data('xdsoft_datetimepicker')) { + if (input.is(':disabled') || input.data('xdsoft_datetimepicker')) { return; } clearTimeout(lazyInitTimer); @@ -528,7 +764,7 @@ }; createDateTimePicker = function (input) { - var datetimepicker = $('
'), + var datetimepicker = $('
'), xdsoft_copyright = $(''), datepicker = $('
'), mounth_picker = $('
' + @@ -539,6 +775,7 @@ timepicker = $('
'), timeboxparent = timepicker.find('.xdsoft_time_box').eq(0), timebox = $('
'), + applyButton = $(''), /*scrollbar = $('
'), scroller = $('
'),*/ monthselect = $('
'), @@ -551,7 +788,21 @@ current_time_index, setPos, timer = 0, - timer1 = 0; + timer1 = 0, + _xdsoft_datetime; + + if (options.id) { + datetimepicker.attr('id', options.id); + } + if (options.style) { + datetimepicker.attr('style', options.style); + } + if (options.weeks) { + datetimepicker.addClass('xdsoft_showweeks'); + } + + datetimepicker.addClass('xdsoft_' + options.theme); + datetimepicker.addClass(options.className); mounth_picker .find('.xdsoft_month span') @@ -599,6 +850,11 @@ event.preventDefault(); }) .on('mousedown.xdsoft', '.xdsoft_option', function (event) { + + if (_xdsoft_datetime.currentTime === undefined || _xdsoft_datetime.currentTime === null) { + _xdsoft_datetime.currentTime = _xdsoft_datetime.now(); + } + var year = _xdsoft_datetime.currentTime.getFullYear(); if (_xdsoft_datetime && _xdsoft_datetime.currentTime) { _xdsoft_datetime.currentTime[$(this).parent().parent().hasClass('xdsoft_monthselect') ? 'setMonth' : 'setFullYear']($(this).data('value')); @@ -617,6 +873,48 @@ }); datetimepicker.setOptions = function (_options) { + var highlightedDates = {}, + getCaretPos = function (input) { + try { + if (document.selection && document.selection.createRange) { + var range = document.selection.createRange(); + return range.getBookmark().charCodeAt(2) - 2; + } + if (input.setSelectionRange) { + return input.selectionStart; + } + } catch (e) { + return 0; + } + }, + setCaretPos = function (node, pos) { + node = (typeof node === "string" || node instanceof String) ? document.getElementById(node) : node; + if (!node) { + return false; + } + if (node.createTextRange) { + var textRange = node.createTextRange(); + textRange.collapse(true); + textRange.moveEnd('character', pos); + textRange.moveStart('character', pos); + textRange.select(); + return true; + } + if (node.setSelectionRange) { + node.setSelectionRange(pos, pos); + return true; + } + return false; + }, + isValidValue = function (mask, value) { + var reg = mask + .replace(/([\[\]\/\{\}\(\)\-\.\+]{1})/g, '\\$1') + .replace(/_/g, '{digit+}') + .replace(/([0-9]{1})/g, '{digit$1}') + .replace(/\{digit([0-9]{1})\}/g, '[0-$1_]{1}') + .replace(/\{digit[\+]\}/g, '[0-9_]{1}'); + return (new RegExp(reg)).test(value); + }; options = $.extend(true, {}, options, _options); if (_options.allowTimes && $.isArray(_options.allowTimes) && _options.allowTimes.length) { @@ -627,9 +925,62 @@ options.weekends = $.extend(true, [], _options.weekends); } + if (_options.highlightedDates && $.isArray(_options.highlightedDates) && _options.highlightedDates.length) { + $.each(_options.highlightedDates, function (index, value) { + var splitData = $.map(value.split(','), $.trim), + exDesc, + hDate = new HighlightedDate(Date.parseDate(splitData[0], options.formatDate), splitData[1], splitData[2]), // date, desc, style + keyDate = hDate.date.dateFormat(options.formatDate); + if (highlightedDates[keyDate] !== undefined) { + exDesc = highlightedDates[keyDate].desc; + if (exDesc && exDesc.length && hDate.desc && hDate.desc.length) { + highlightedDates[keyDate].desc = exDesc + "\n" + hDate.desc; + } + } else { + highlightedDates[keyDate] = hDate; + } + }); + + options.highlightedDates = $.extend(true, [], highlightedDates); + } + + if (_options.highlightedPeriods && $.isArray(_options.highlightedPeriods) && _options.highlightedPeriods.length) { + highlightedDates = $.extend(true, [], options.highlightedDates); + $.each(_options.highlightedPeriods, function (index, value) { + var splitData = $.map(value.split(','), $.trim), + dateTest = Date.parseDate(splitData[0], options.formatDate), // start date + dateEnd = Date.parseDate(splitData[1], options.formatDate), + desc = splitData[2], + hDate, + keyDate, + exDesc, + style = splitData[3]; + + while (dateTest <= dateEnd) { + hDate = new HighlightedDate(dateTest, desc, style); + keyDate = dateTest.dateFormat(options.formatDate); + dateTest.setDate(dateTest.getDate() + 1); + if (highlightedDates[keyDate] !== undefined) { + exDesc = highlightedDates[keyDate].desc; + if (exDesc && exDesc.length && hDate.desc && hDate.desc.length) { + highlightedDates[keyDate].desc = exDesc + "\n" + hDate.desc; + } + } else { + highlightedDates[keyDate] = hDate; + } + } + }); + + options.highlightedDates = $.extend(true, [], highlightedDates); + } + if (_options.disabledDates && $.isArray(_options.disabledDates) && _options.disabledDates.length) { - options.disabledDates = $.extend(true, [], _options.disabledDates); - } + options.disabledDates = $.extend(true, [], _options.disabledDates); + } + + if (_options.disabledWeekDays && $.isArray(_options.disabledWeekDays) && _options.disabledWeekDays.length) { + options.disabledWeekDays = $.extend(true, [], _options.disabledWeekDays); + } if ((options.open || options.opened) && (!options.inline)) { input.trigger('open.xdsoft'); @@ -659,10 +1010,10 @@ } if (options.value) { + _xdsoft_datetime.setCurrentTime(options.value); if (input && input.val) { - input.val(options.value); + input.val(_xdsoft_datetime.str); } - _xdsoft_datetime.setCurrentTime(options.value); } if (isNaN(options.dayOfWeekStart)) { @@ -683,53 +1034,21 @@ options.maxDate = _xdsoft_datetime.strToDateTime(options.maxDate).dateFormat(options.formatDate); } + applyButton.toggle(options.showApplyButton); + mounth_picker .find('.xdsoft_today_button') .css('visibility', !options.todayButton ? 'hidden' : 'visible'); + mounth_picker + .find('.' + options.prev) + .css('visibility', !options.prevButton ? 'hidden' : 'visible'); + + mounth_picker + .find('.' + options.next) + .css('visibility', !options.nextButton ? 'hidden' : 'visible'); + if (options.mask) { - var e, - getCaretPos = function (input) { - try { - if (document.selection && document.selection.createRange) { - var range = document.selection.createRange(); - return range.getBookmark().charCodeAt(2) - 2; - } - if (input.setSelectionRange) { - return input.selectionStart; - } - } catch (e) { - return 0; - } - }, - setCaretPos = function (node, pos) { - node = (typeof node === "string" || node instanceof String) ? document.getElementById(node) : node; - if (!node) { - return false; - } - if (node.createTextRange) { - var textRange = node.createTextRange(); - textRange.collapse(true); - textRange.moveEnd('character', pos); - textRange.moveStart('character', pos); - textRange.select(); - return true; - } - if (node.setSelectionRange) { - node.setSelectionRange(pos, pos); - return true; - } - return false; - }, - isValidValue = function (mask, value) { - var reg = mask - .replace(/([\[\]\/\{\}\(\)\-\.\+]{1})/g, '\\$1') - .replace(/_/g, '{digit+}') - .replace(/([0-9]{1})/g, '{digit$1}') - .replace(/\{digit([0-9]{1})\}/g, '[0-$1_]{1}') - .replace(/\{digit[\+]\}/g, '[0-9_]{1}'); - return (new RegExp(reg)).test(value); - }; input.off('keydown.xdsoft'); if (options.mask === true) { @@ -809,11 +1128,23 @@ $(this).val(null); datetimepicker.data('xdsoft_datetime').empty(); } else if (!Date.parseDate($(this).val(), options.format)) { - $(this).val((_xdsoft_datetime.now()).dateFormat(options.format)); + var splittedHours = +([$(this).val()[0], $(this).val()[1]].join('')), + splittedMinutes = +([$(this).val()[2], $(this).val()[3]].join('')); + + // parse the numbers as 0312 => 03:12 + if (!options.datepicker && options.timepicker && splittedHours >= 0 && splittedHours < 24 && splittedMinutes >= 0 && splittedMinutes < 60) { + $(this).val([splittedHours, splittedMinutes].map(function (item) { + return item > 9 ? item : '0' + item; + }).join(':')); + } else { + $(this).val((_xdsoft_datetime.now()).dateFormat(options.format)); + } + datetimepicker.data('xdsoft_datetime').setCurrentTime($(this).val()); } else { datetimepicker.data('xdsoft_datetime').setCurrentTime($(this).val()); } + datetimepicker.trigger('changedatetime.xdsoft'); }); } @@ -853,7 +1184,8 @@ datepicker .append(mounth_picker) - .append(calendar); + .append(calendar) + .append(applyButton); $(options.parentID) .append(datetimepicker); @@ -866,7 +1198,7 @@ time; if (!norecursion && options.defaultDate) { - date = _this.strToDate(options.defaultDate); + date = _this.strToDateTime(options.defaultDate); d.setFullYear(date.getFullYear()); d.setMonth(date.getMonth()); d.setDate(date.getDate()); @@ -881,7 +1213,6 @@ d.setHours(time.getHours()); d.setMinutes(time.getMinutes()); } - return d; }; @@ -906,6 +1237,11 @@ }; _this.nextMonth = function () { + + if (_this.currentTime === undefined || _this.currentTime === null) { + _this.currentTime = _this.now(); + } + var month = _this.currentTime.getMonth() + 1, year; if (month === 12) { @@ -936,6 +1272,11 @@ }; _this.prevMonth = function () { + + if (_this.currentTime === undefined || _this.currentTime === null) { + _this.currentTime = _this.now(); + } + var month = _this.currentTime.getMonth() - 1; if (month === -1) { _this.currentTime.setFullYear(_this.currentTime.getFullYear() - 1); @@ -973,7 +1314,7 @@ } if (tmpDate && tmpDate[2]) { timeOffset = tmpDate[2].getTime() - (tmpDate[2].getTimezoneOffset()) * 60000; - currentTime = new Date((_xdsoft_datetime.now()).getTime() + parseInt(tmpDate[1] + '1', 10) * timeOffset); + currentTime = new Date((_this.now(true)).getTime() + parseInt(tmpDate[1] + '1', 10) * timeOffset); } else { currentTime = sDateTime ? Date.parseDate(sDateTime, options.format) : _this.now(); } @@ -1016,6 +1357,13 @@ _xdsoft_datetime = new XDSoft_datetime(); + applyButton.on('click', function (e) {//pathbrite + e.preventDefault(); + datetimepicker.data('changed', true); + _xdsoft_datetime.setCurrentTime(getCurrentValue()); + input.val(_xdsoft_datetime.str()); + datetimepicker.trigger('close.xdsoft'); + }); mounth_picker .find('.xdsoft_today_button') .on('mousedown.xdsoft', function () { @@ -1023,6 +1371,18 @@ _xdsoft_datetime.setCurrentTime(0); datetimepicker.trigger('afterOpen.xdsoft'); }).on('dblclick.xdsoft', function () { + var currentDate = _xdsoft_datetime.getCurrentTime(), minDate, maxDate; + currentDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate()); + minDate = _xdsoft_datetime.strToDate(options.minDate); + minDate = new Date(minDate.getFullYear(), minDate.getMonth(), minDate.getDate()); + if (currentDate < minDate) { + return; + } + maxDate = _xdsoft_datetime.strToDate(options.maxDate); + maxDate = new Date(maxDate.getFullYear(), maxDate.getMonth(), maxDate.getDate()); + if (currentDate > maxDate) { + return; + } input.val(_xdsoft_datetime.str()); datetimepicker.trigger('close.xdsoft'); }); @@ -1034,7 +1394,6 @@ stop = false; (function arguments_callee1(v) { - var month = _xdsoft_datetime.currentTime.getMonth(); if ($this.hasClass(options.next)) { _xdsoft_datetime.nextMonth(); } else if ($this.hasClass(options.prev)) { @@ -1090,6 +1449,11 @@ .on('xchange.xdsoft', function (event) { clearTimeout(xchangeTimer); xchangeTimer = setTimeout(function () { + + if (_xdsoft_datetime.currentTime === undefined || _xdsoft_datetime.currentTime === null) { + _xdsoft_datetime.currentTime = _xdsoft_datetime.now(); + } + var table = '', start = new Date(_xdsoft_datetime.currentTime.getFullYear(), _xdsoft_datetime.currentTime.getMonth(), 1, 12, 0, 0), i = 0, @@ -1097,6 +1461,8 @@ today = _xdsoft_datetime.now(), maxDate = false, minDate = false, + hDate, + day, d, y, m, @@ -1106,7 +1472,8 @@ newRow = true, time = '', h = '', - line_time; + line_time, + description; while (start.getDay() !== options.dayOfWeekStart) { start.setDate(start.getDate() - 1); @@ -1139,10 +1506,12 @@ classes = []; i += 1; + day = start.getDay(); d = start.getDate(); y = start.getFullYear(); m = start.getMonth(); w = _xdsoft_datetime.getWeekOfYear(start); + description = ''; classes.push('xdsoft_date'); @@ -1156,6 +1525,8 @@ classes.push('xdsoft_disabled'); } else if (options.disabledDates.indexOf(start.dateFormat(options.formatDate)) !== -1) { classes.push('xdsoft_disabled'); + } else if (options.disabledWeekDays.indexOf(day) !== -1) { + classes.push('xdsoft_disabled'); } if (customDateSettings && customDateSettings[1] !== "") { @@ -1174,10 +1545,16 @@ classes.push('xdsoft_today'); } - if (start.getDay() === 0 || start.getDay() === 6 || options.weekends.indexOf(start.dateFormat(options.formatDate)) === -1) { + if (start.getDay() === 0 || start.getDay() === 6 || options.weekends.indexOf(start.dateFormat(options.formatDate)) !== -1) { classes.push('xdsoft_weekend'); } + if (options.highlightedDates[start.dateFormat(options.formatDate)] !== undefined) { + hDate = options.highlightedDates[start.dateFormat(options.formatDate)]; + classes.push(hDate.style === undefined ? 'xdsoft_highlighted_default' : hDate.style); + description = hDate.desc === undefined ? '' : hDate.desc; + } + if (options.beforeShowDay && $.isFunction(options.beforeShowDay)) { classes.push(options.beforeShowDay(start)); } @@ -1190,7 +1567,7 @@ } } - table += '' + + table += '' + '
' + d + '
' + ''; @@ -1213,17 +1590,27 @@ h = ''; m = ''; line_time = function line_time(h, m) { - var now = _xdsoft_datetime.now(); + var now = _xdsoft_datetime.now(), optionDateTime, current_time; now.setHours(h); h = parseInt(now.getHours(), 10); now.setMinutes(m); m = parseInt(now.getMinutes(), 10); - + optionDateTime = new Date(_xdsoft_datetime.currentTime); + optionDateTime.setHours(h); + optionDateTime.setMinutes(m); classes = []; - if ((options.maxTime !== false && _xdsoft_datetime.strtotime(options.maxTime).getTime() < now.getTime()) || (options.minTime !== false && _xdsoft_datetime.strtotime(options.minTime).getTime() > now.getTime())) { + if ((options.minDateTime !== false && options.minDateTime > optionDateTime) || (options.maxTime !== false && _xdsoft_datetime.strtotime(options.maxTime).getTime() < now.getTime()) || (options.minTime !== false && _xdsoft_datetime.strtotime(options.minTime).getTime() > now.getTime())) { classes.push('xdsoft_disabled'); } - if ((options.initTime || options.defaultSelect || datetimepicker.data('changed')) && parseInt(_xdsoft_datetime.currentTime.getHours(), 10) === parseInt(h, 10) && (options.step > 59 || Math[options.roundTime](_xdsoft_datetime.currentTime.getMinutes() / options.step) * options.step === parseInt(m, 10))) { + if ((options.minDateTime !== false && options.minDateTime > optionDateTime) || ((options.disabledMinTime !== false && now.getTime() > _xdsoft_datetime.strtotime(options.disabledMinTime).getTime()) && (options.disabledMaxTime !== false && now.getTime() < _xdsoft_datetime.strtotime(options.disabledMaxTime).getTime()))) { + classes.push('xdsoft_disabled'); + } + + current_time = new Date(_xdsoft_datetime.currentTime); + current_time.setHours(parseInt(_xdsoft_datetime.currentTime.getHours(), 10)); + current_time.setMinutes(Math[options.roundTime](_xdsoft_datetime.currentTime.getMinutes() / options.step) * options.step); + + if ((options.initTime || options.defaultSelect || datetimepicker.data('changed')) && current_time.getHours() === parseInt(h, 10) && (options.step > 59 || current_time.getMinutes() === parseInt(m, 10))) { if (options.defaultSelect || datetimepicker.data('changed')) { classes.push('xdsoft_current'); } else if (options.initTime) { @@ -1263,7 +1650,7 @@ yearselect.children().eq(0) .html(opt); - for (i = 0, opt = ''; i <= 11; i += 1) { + for (i = parseInt(options.monthStart, 10), opt = ''; i <= parseInt(options.monthEnd, 10); i += 1) { opt += '
' + options.i18n[options.lang].months[i] + '
'; } monthselect.children().eq(0).html(opt); @@ -1319,7 +1706,7 @@ datetimepicker.trigger('select.xdsoft', [currentTime]); input.val(_xdsoft_datetime.str()); - if ((timerclick > 1 || (options.closeOnDateSelect === true || (options.closeOnDateSelect === 0 && !options.timepicker))) && !options.inline) { + if ((timerclick > 1 || (options.closeOnDateSelect === true || (options.closeOnDateSelect === false && !options.timepicker))) && !options.inline) { datetimepicker.trigger('close.xdsoft'); } @@ -1354,9 +1741,10 @@ datetimepicker.trigger('select.xdsoft', [currentTime]); datetimepicker.data('input').val(_xdsoft_datetime.str()); - if (!options.inline) { - datetimepicker.trigger('close.xdsoft'); - } + + if (options.inline !== true && options.closeOnTimeSelect === true) { + datetimepicker.trigger('close.xdsoft'); + } if (options.onSelectTime && $.isFunction(options.onSelectTime)) { options.onSelectTime.call(datetimepicker, _xdsoft_datetime.currentTime, datetimepicker.data('input'), xdevent); @@ -1430,7 +1818,7 @@ current_time_index = 0; setPos = function () { - var offset = datetimepicker.data('input').offset(), top = offset.top + datetimepicker.data('input')[0].offsetHeight - 1, left = offset.left, position = "absolute"; + var offset = datetimepicker.data('input').offset(), top = offset.top + datetimepicker.data('input')[0].offsetHeight - 1, left = offset.left, position = "absolute", node; if (options.fixed) { top -= $(window).scrollTop(); left -= $(window).scrollLeft(); @@ -1446,6 +1834,15 @@ left = $(window).width() - datetimepicker[0].offsetWidth; } } + + node = datetimepicker[0]; + do { + node = node.parentNode; + if (window.getComputedStyle(node).getPropertyValue('position') === 'relative' && $(window).width() >= node.offsetWidth) { + left = left - (($(window).width() - node.offsetWidth) / 2); + break; + } + } while (node.nodeName !== 'HTML'); datetimepicker.css({ left: left, top: top, @@ -1488,7 +1885,11 @@ event.stopPropagation(); }) .on('toggle.xdsoft', function (event) { - datetimepicker.is(':visible') ? datetimepicker.trigger('close.xdsoft') : datetimepicker.trigger('open.xdsoft'); + if (datetimepicker.is(':visible')) { + datetimepicker.trigger('close.xdsoft'); + } else { + datetimepicker.trigger('open.xdsoft'); + } }) .data('input', input); @@ -1499,7 +1900,6 @@ datetimepicker.setOptions(options); function getCurrentValue() { - var ct = false, time; if (options.startDate) { @@ -1509,7 +1909,7 @@ if (ct) { ct = _xdsoft_datetime.strToDateTime(ct); } else if (options.defaultDate) { - ct = _xdsoft_datetime.strToDate(options.defaultDate); + ct = _xdsoft_datetime.strToDateTime(options.defaultDate); if (options.defaultTime) { time = _xdsoft_datetime.strtotime(options.defaultTime); ct.setHours(time.getHours()); @@ -1532,12 +1932,12 @@ input .data('xdsoft_datetimepicker', datetimepicker) .on('open.xdsoft focusin.xdsoft mousedown.xdsoft', function (event) { - if (input.is(':disabled') || input.is(':hidden') || !input.is(':visible') || (input.data('xdsoft_datetimepicker').is(':visible') && options.closeOnInputClick)) { + if (input.is(':disabled') || (input.data('xdsoft_datetimepicker').is(':visible') && options.closeOnInputClick)) { return; } clearTimeout(timer); timer = setTimeout(function () { - if (input.is(':disabled') || input.is(':hidden') || !input.is(':visible')) { + if (input.is(':disabled')) { return; } @@ -1590,7 +1990,7 @@ } }); return this.each(function () { - var datetimepicker = $(this).data('xdsoft_datetimepicker'); + var datetimepicker = $(this).data('xdsoft_datetimepicker'), $input; if (datetimepicker) { if ($.type(opt) === 'string') { switch (opt) { @@ -1614,6 +2014,10 @@ } datetimepicker.data('xdsoft_datetime').setCurrentTime(this.value); break; + case 'validate': + $input = datetimepicker.data('input'); + $input.trigger('blur.xdsoft'); + break; } } else { datetimepicker @@ -1632,6 +2036,14 @@ }; $.fn.datetimepicker.defaults = default_options; }(jQuery)); + +function HighlightedDate(date, desc, style) { + "use strict"; + this.date = date; + this.desc = desc; + this.style = style; +} + (function () { /*! Copyright (c) 2013 Brandon Aaron (http://brandon.aaron.sh) @@ -1657,5 +2069,5 @@ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ -Date.parseFunctions={count:0};Date.parseRegexes=[];Date.formatFunctions={count:0};Date.prototype.dateFormat=function(b){if(b=="unixtime"){return parseInt(this.getTime()/1000);}if(Date.formatFunctions[b]==null){Date.createNewFormat(b);}var a=Date.formatFunctions[b];return this[a]();};Date.createNewFormat=function(format){var funcName="format"+Date.formatFunctions.count++;Date.formatFunctions[format]=funcName;var code="Date.prototype."+funcName+" = function() {return ";var special=false;var ch="";for(var i=0;i 0) {";var regex="";var special=false;var ch="";for(var i=0;i 0 && z > 0){\nvar doyDate = new Date(y,0);\ndoyDate.setDate(z);\nm = doyDate.getMonth();\nd = doyDate.getDate();\n}";code+="if (y > 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0)\n{return new Date(y, m, d, h, i, s);}\nelse if (y > 0 && m >= 0 && d > 0 && h >= 0 && i >= 0)\n{return new Date(y, m, d, h, i);}\nelse if (y > 0 && m >= 0 && d > 0 && h >= 0)\n{return new Date(y, m, d, h);}\nelse if (y > 0 && m >= 0 && d > 0)\n{return new Date(y, m, d);}\nelse if (y > 0 && m >= 0)\n{return new Date(y, m);}\nelse if (y > 0)\n{return new Date(y);}\n}return null;}";Date.parseRegexes[regexNum]=new RegExp("^"+regex+"$");eval(code);};Date.formatCodeToRegex=function(b,a){switch(b){case"D":return{g:0,c:null,s:"(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)"};case"j":case"d":return{g:1,c:"d = parseInt(results["+a+"], 10);\n",s:"(\\d{1,2})"};case"l":return{g:0,c:null,s:"(?:"+Date.dayNames.join("|")+")"};case"S":return{g:0,c:null,s:"(?:st|nd|rd|th)"};case"w":return{g:0,c:null,s:"\\d"};case"z":return{g:1,c:"z = parseInt(results["+a+"], 10);\n",s:"(\\d{1,3})"};case"W":return{g:0,c:null,s:"(?:\\d{2})"};case"F":return{g:1,c:"m = parseInt(Date.monthNumbers[results["+a+"].substring(0, 3)], 10);\n",s:"("+Date.monthNames.join("|")+")"};case"M":return{g:1,c:"m = parseInt(Date.monthNumbers[results["+a+"]], 10);\n",s:"(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)"};case"n":case"m":return{g:1,c:"m = parseInt(results["+a+"], 10) - 1;\n",s:"(\\d{1,2})"};case"t":return{g:0,c:null,s:"\\d{1,2}"};case"L":return{g:0,c:null,s:"(?:1|0)"};case"Y":return{g:1,c:"y = parseInt(results["+a+"], 10);\n",s:"(\\d{4})"};case"y":return{g:1,c:"var ty = parseInt(results["+a+"], 10);\ny = ty > Date.y2kYear ? 1900 + ty : 2000 + ty;\n",s:"(\\d{1,2})"};case"a":return{g:1,c:"if (results["+a+"] == 'am') {\nif (h == 12) { h = 0; }\n} else { if (h < 12) { h += 12; }}",s:"(am|pm)"};case"A":return{g:1,c:"if (results["+a+"] == 'AM') {\nif (h == 12) { h = 0; }\n} else { if (h < 12) { h += 12; }}",s:"(AM|PM)"};case"g":case"G":case"h":case"H":return{g:1,c:"h = parseInt(results["+a+"], 10);\n",s:"(\\d{1,2})"};case"i":return{g:1,c:"i = parseInt(results["+a+"], 10);\n",s:"(\\d{2})"};case"s":return{g:1,c:"s = parseInt(results["+a+"], 10);\n",s:"(\\d{2})"};case"O":return{g:0,c:null,s:"[+-]\\d{4}"};case"T":return{g:0,c:null,s:"[A-Z]{3}"};case"Z":return{g:0,c:null,s:"[+-]\\d{1,5}"};default:return{g:0,c:null,s:String.escape(b)};}};Date.prototype.getTimezone=function(){return this.toString().replace(/^.*? ([A-Z]{3}) [0-9]{4}.*$/,"$1").replace(/^.*?\(([A-Z])[a-z]+ ([A-Z])[a-z]+ ([A-Z])[a-z]+\)$/,"$1$2$3");};Date.prototype.getGMTOffset=function(){return(this.getTimezoneOffset()>0?"-":"+")+String.leftPad(Math.floor(Math.abs(this.getTimezoneOffset())/60),2,"0")+String.leftPad(Math.abs(this.getTimezoneOffset())%60,2,"0");};Date.prototype.getDayOfYear=function(){var a=0;Date.daysInMonth[1]=this.isLeapYear()?29:28;for(var b=0;b 0) {";var regex="";var special=false;var ch="";for(var i=0;i 0 && z > 0){\nvar doyDate = new Date(y,0);\ndoyDate.setDate(z);\nm = doyDate.getMonth();\nd = doyDate.getDate();\n}";code+="if (y > 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0)\n{return new Date(y, m, d, h, i, s);}\nelse if (y > 0 && m >= 0 && d > 0 && h >= 0 && i >= 0)\n{return new Date(y, m, d, h, i);}\nelse if (y > 0 && m >= 0 && d > 0 && h >= 0)\n{return new Date(y, m, d, h);}\nelse if (y > 0 && m >= 0 && d > 0)\n{return new Date(y, m, d);}\nelse if (y > 0 && m >= 0)\n{return new Date(y, m);}\nelse if (y > 0)\n{return new Date(y);}\n}return null;}";Date.parseRegexes[regexNum]=new RegExp("^"+regex+"$",'i');eval(code);};Date.formatCodeToRegex=function(b,a){switch(b){case"D":return{g:0,c:null,s:"(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)"};case"j":case"d":return{g:1,c:"d = parseInt(results["+a+"], 10);\n",s:"(\\d{1,2})"};case"l":return{g:0,c:null,s:"(?:"+Date.dayNames.join("|")+")"};case"S":return{g:0,c:null,s:"(?:st|nd|rd|th)"};case"w":return{g:0,c:null,s:"\\d"};case"z":return{g:1,c:"z = parseInt(results["+a+"], 10);\n",s:"(\\d{1,3})"};case"W":return{g:0,c:null,s:"(?:\\d{2})"};case"F":return{g:1,c:"m = parseInt(Date.monthNumbers[results["+a+"].substring(0, 3)], 10);\n",s:"("+Date.monthNames.join("|")+")"};case"M":return{g:1,c:"m = parseInt(Date.monthNumbers[results["+a+"]], 10);\n",s:"(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)"};case"n":case"m":return{g:1,c:"m = parseInt(results["+a+"], 10) - 1;\n",s:"(\\d{1,2})"};case"t":return{g:0,c:null,s:"\\d{1,2}"};case"L":return{g:0,c:null,s:"(?:1|0)"};case"Y":return{g:1,c:"y = parseInt(results["+a+"], 10);\n",s:"(\\d{4})"};case"y":return{g:1,c:"var ty = parseInt(results["+a+"], 10);\ny = ty > Date.y2kYear ? 1900 + ty : 2000 + ty;\n",s:"(\\d{1,2})"};case"a":return{g:1,c:"if (results["+a+"] == 'am') {\nif (h == 12) { h = 0; }\n} else { if (h < 12) { h += 12; }}",s:"(am|pm)"};case"A":return{g:1,c:"if (results["+a+"] == 'AM') {\nif (h == 12) { h = 0; }\n} else { if (h < 12) { h += 12; }}",s:"(AM|PM)"};case"g":case"G":case"h":case"H":return{g:1,c:"h = parseInt(results["+a+"], 10);\n",s:"(\\d{1,2})"};case"i":return{g:1,c:"i = parseInt(results["+a+"], 10);\n",s:"(\\d{2})"};case"s":return{g:1,c:"s = parseInt(results["+a+"], 10);\n",s:"(\\d{2})"};case"O":return{g:0,c:null,s:"[+-]\\d{4}"};case"T":return{g:0,c:null,s:"[A-Z]{3}"};case"Z":return{g:0,c:null,s:"[+-]\\d{1,5}"};default:return{g:0,c:null,s:String.escape(b)};}};Date.prototype.getTimezone=function(){return this.toString().replace(/^.*? ([A-Z]{3}) [0-9]{4}.*$/,"$1").replace(/^.*?\(([A-Z])[a-z]+ ([A-Z])[a-z]+ ([A-Z])[a-z]+\)$/,"$1$2$3");};Date.prototype.getGMTOffset=function(){return(this.getTimezoneOffset()>0?"-":"+")+String.leftPad(Math.floor(Math.abs(this.getTimezoneOffset())/60),2,"0")+String.leftPad(Math.abs(this.getTimezoneOffset())%60,2,"0");};Date.prototype.getDayOfYear=function(){var a=0;Date.daysInMonth[1]=this.isLeapYear()?29:28;for(var b=0;b