1662 lines
64 KiB
JavaScript
1662 lines
64 KiB
JavaScript
/**
|
||
* @preserve jQuery DateTimePicker plugin v2.4.0
|
||
* @homepage http://xdsoft.net/jqplugins/datetimepicker/
|
||
* (c) 2014, Chupurnov Valeriy.
|
||
*/
|
||
/*global document,window,jQuery,setTimeout,clearTimeout*/
|
||
(function ($) {
|
||
'use strict';
|
||
var default_options = {
|
||
i18n: {
|
||
ar: { // Arabic
|
||
months: [
|
||
"كانون الثاني", "شباط", "آذار", "نيسان", "مايو", "حزيران", "تموز", "آب", "أيلول", "تشرين الأول", "تشرين الثاني", "كانون الأول"
|
||
],
|
||
dayOfWeek: [
|
||
"ن", "ث", "ع", "خ", "ج", "س", "ح"
|
||
]
|
||
},
|
||
ro: { // Romanian
|
||
months: [
|
||
"ianuarie", "februarie", "martie", "aprilie", "mai", "iunie", "iulie", "august", "septembrie", "octombrie", "noiembrie", "decembrie"
|
||
],
|
||
dayOfWeek: [
|
||
"l", "ma", "mi", "j", "v", "s", "d"
|
||
]
|
||
},
|
||
id: { // Indonesian
|
||
months: [
|
||
"Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember"
|
||
],
|
||
dayOfWeek: [
|
||
"Sen", "Sel", "Rab", "Kam", "Jum", "Sab", "Min"
|
||
]
|
||
},
|
||
bg: { // Bulgarian
|
||
months: [
|
||
"Януари", "Февруари", "Март", "Април", "Май", "Юни", "Юли", "Август", "Септември", "Октомври", "Ноември", "Декември"
|
||
],
|
||
dayOfWeek: [
|
||
"Нд", "Пн", "Вт", "Ср", "Чт", "Пт", "Сб"
|
||
]
|
||
},
|
||
fa: { // Persian/Farsi
|
||
months: [
|
||
'فروردین', 'اردیبهشت', 'خرداد', 'تیر', 'مرداد', 'شهریور', 'مهر', 'آبان', 'آذر', 'دی', 'بهمن', 'اسفند'
|
||
],
|
||
dayOfWeek: [
|
||
'یکشنبه', 'دوشنبه', 'سه شنبه', 'چهارشنبه', 'پنجشنبه', 'جمعه', 'شنبه'
|
||
]
|
||
},
|
||
ru: { // Russian
|
||
months: [
|
||
'Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'
|
||
],
|
||
dayOfWeek: [
|
||
"Вск", "Пн", "Вт", "Ср", "Чт", "Пт", "Сб"
|
||
]
|
||
},
|
||
uk: { // Ukrainian
|
||
months: [
|
||
'Січень', 'Лютий', 'Березень', 'Квітень', 'Травень', 'Червень', 'Липень', 'Серпень', 'Вересень', 'Жовтень', 'Листопад', 'Грудень'
|
||
],
|
||
dayOfWeek: [
|
||
"Ндл", "Пнд", "Втр", "Срд", "Чтв", "Птн", "Сбт"
|
||
]
|
||
},
|
||
en: { // English
|
||
months: [
|
||
"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
|
||
],
|
||
dayOfWeek: [
|
||
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
|
||
]
|
||
},
|
||
el: { // Ελληνικά
|
||
months: [
|
||
"Ιανουάριος", "Φεβρουάριος", "Μάρτιος", "Απρίλιος", "Μάιος", "Ιούνιος", "Ιούλιος", "Αύγουστος", "Σεπτέμβριος", "Οκτώβριος", "Νοέμβριος", "Δεκέμβριος"
|
||
],
|
||
dayOfWeek: [
|
||
"Κυρ", "Δευ", "Τρι", "Τετ", "Πεμ", "Παρ", "Σαβ"
|
||
]
|
||
},
|
||
de: { // German
|
||
months: [
|
||
'Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'
|
||
],
|
||
dayOfWeek: [
|
||
"So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"
|
||
]
|
||
},
|
||
nl: { // Dutch
|
||
months: [
|
||
"januari", "februari", "maart", "april", "mei", "juni", "juli", "augustus", "september", "oktober", "november", "december"
|
||
],
|
||
dayOfWeek: [
|
||
"zo", "ma", "di", "wo", "do", "vr", "za"
|
||
]
|
||
},
|
||
tr: { // Turkish
|
||
months: [
|
||
"Ocak", "Şubat", "Mart", "Nisan", "Mayıs", "Haziran", "Temmuz", "Ağustos", "Eylül", "Ekim", "Kasım", "Aralık"
|
||
],
|
||
dayOfWeek: [
|
||
"Paz", "Pts", "Sal", "Çar", "Per", "Cum", "Cts"
|
||
]
|
||
},
|
||
fr: { //French
|
||
months: [
|
||
"Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"
|
||
],
|
||
dayOfWeek: [
|
||
"Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"
|
||
]
|
||
},
|
||
es: { // Spanish
|
||
months: [
|
||
"Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"
|
||
],
|
||
dayOfWeek: [
|
||
"Dom", "Lun", "Mar", "Mié", "Jue", "Vie", "Sáb"
|
||
]
|
||
},
|
||
th: { // Thai
|
||
months: [
|
||
'มกราคม', 'กุมภาพันธ์', 'มีนาคม', 'เมษายน', 'พฤษภาคม', 'มิถุนายน', 'กรกฎาคม', 'สิงหาคม', 'กันยายน', 'ตุลาคม', 'พฤศจิกายน', 'ธันวาคม'
|
||
],
|
||
dayOfWeek: [
|
||
'อา.', 'จ.', 'อ.', 'พ.', 'พฤ.', 'ศ.', 'ส.'
|
||
]
|
||
},
|
||
pl: { // Polish
|
||
months: [
|
||
"styczeń", "luty", "marzec", "kwiecień", "maj", "czerwiec", "lipiec", "sierpień", "wrzesień", "październik", "listopad", "grudzień"
|
||
],
|
||
dayOfWeek: [
|
||
"nd", "pn", "wt", "śr", "cz", "pt", "sb"
|
||
]
|
||
},
|
||
pt: { // Portuguese
|
||
months: [
|
||
"Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"
|
||
],
|
||
dayOfWeek: [
|
||
"Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sab"
|
||
]
|
||
},
|
||
ch: { // Simplified Chinese
|
||
months: [
|
||
"一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"
|
||
],
|
||
dayOfWeek: [
|
||
"日", "一", "二", "三", "四", "五", "六"
|
||
]
|
||
},
|
||
se: { // Swedish
|
||
months: [
|
||
"Januari", "Februari", "Mars", "April", "Maj", "Juni", "Juli", "Augusti", "September", "Oktober", "November", "December"
|
||
],
|
||
dayOfWeek: [
|
||
"Sön", "Mån", "Tis", "Ons", "Tor", "Fre", "Lör"
|
||
]
|
||
},
|
||
kr: { // Korean
|
||
months: [
|
||
"1월", "2월", "3월", "4월", "5월", "6월", "7월", "8월", "9월", "10월", "11월", "12월"
|
||
],
|
||
dayOfWeek: [
|
||
"일", "월", "화", "수", "목", "금", "토"
|
||
]
|
||
},
|
||
it: { // Italian
|
||
months: [
|
||
"Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"
|
||
],
|
||
dayOfWeek: [
|
||
"Dom", "Lun", "Mar", "Mer", "Gio", "Ven", "Sab"
|
||
]
|
||
},
|
||
da: { // Dansk
|
||
months: [
|
||
"January", "Februar", "Marts", "April", "Maj", "Juni", "July", "August", "September", "Oktober", "November", "December"
|
||
],
|
||
dayOfWeek: [
|
||
"Søn", "Man", "Tir", "Ons", "Tor", "Fre", "Lør"
|
||
]
|
||
},
|
||
no: { // Norwegian
|
||
months: [
|
||
"Januar", "Februar", "Mars", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Desember"
|
||
],
|
||
dayOfWeek: [
|
||
"Søn", "Man", "Tir", "Ons", "Tor", "Fre", "Lør"
|
||
]
|
||
},
|
||
ja: { // Japanese
|
||
months: [
|
||
"1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"
|
||
],
|
||
dayOfWeek: [
|
||
"日", "月", "火", "水", "木", "金", "土"
|
||
]
|
||
},
|
||
vi: { // Vietnamese
|
||
months: [
|
||
"Tháng 1", "Tháng 2", "Tháng 3", "Tháng 4", "Tháng 5", "Tháng 6", "Tháng 7", "Tháng 8", "Tháng 9", "Tháng 10", "Tháng 11", "Tháng 12"
|
||
],
|
||
dayOfWeek: [
|
||
"CN", "T2", "T3", "T4", "T5", "T6", "T7"
|
||
]
|
||
},
|
||
sl: { // Slovenščina
|
||
months: [
|
||
"Januar", "Februar", "Marec", "April", "Maj", "Junij", "Julij", "Avgust", "September", "Oktober", "November", "December"
|
||
],
|
||
dayOfWeek: [
|
||
"Ned", "Pon", "Tor", "Sre", "Čet", "Pet", "Sob"
|
||
]
|
||
},
|
||
cs: { // Čeština
|
||
months: [
|
||
"Leden", "Únor", "Březen", "Duben", "Květen", "Červen", "Červenec", "Srpen", "Září", "Říjen", "Listopad", "Prosinec"
|
||
],
|
||
dayOfWeek: [
|
||
"Ne", "Po", "Út", "St", "Čt", "Pá", "So"
|
||
]
|
||
},
|
||
hu: { // Hungarian
|
||
months: [
|
||
"Január", "Február", "Március", "Április", "Május", "Június", "Július", "Augusztus", "Szeptember", "Október", "November", "December"
|
||
],
|
||
dayOfWeek: [
|
||
"Va", "Hé", "Ke", "Sze", "Cs", "Pé", "Szo"
|
||
]
|
||
}
|
||
},
|
||
value: '',
|
||
lang: 'en',
|
||
|
||
format: 'Y/m/d H:i',
|
||
formatTime: 'H:i',
|
||
formatDate: 'Y/m/d',
|
||
|
||
startDate: false, // new Date(), '1986/12/08', '-1970/01/05','-1970/01/05',
|
||
step: 60,
|
||
monthChangeSpinner: true,
|
||
|
||
closeOnDateSelect: false,
|
||
closeOnWithoutClick: true,
|
||
closeOnInputClick: true,
|
||
|
||
timepicker: true,
|
||
datepicker: true,
|
||
weeks: false,
|
||
|
||
defaultTime: false, // use formatTime format (ex. '10:00' for formatTime: 'H:i')
|
||
defaultDate: false, // use formatDate format (ex new Date() or '1986/12/08' or '-1970/01/05' or '-1970/01/05')
|
||
|
||
minDate: false,
|
||
maxDate: false,
|
||
minTime: false,
|
||
maxTime: false,
|
||
|
||
allowTimes: [],
|
||
opened: false,
|
||
initTime: true,
|
||
inline: false,
|
||
theme: '',
|
||
|
||
onSelectDate: function () {},
|
||
onSelectTime: function () {},
|
||
onChangeMonth: function () {},
|
||
onChangeYear: function () {},
|
||
onChangeDateTime: function () {},
|
||
onShow: function () {},
|
||
onClose: function () {},
|
||
onGenerate: function () {},
|
||
|
||
withoutCopyright: true,
|
||
inverseButton: false,
|
||
hours12: false,
|
||
next: 'xdsoft_next',
|
||
prev : 'xdsoft_prev',
|
||
dayOfWeekStart: 0,
|
||
parentID: 'body',
|
||
timeHeightInTimePicker: 25,
|
||
timepickerScrollbar: true,
|
||
todayButton: true,
|
||
defaultSelect: true,
|
||
|
||
scrollMonth: true,
|
||
scrollTime: true,
|
||
scrollInput: true,
|
||
|
||
lazyInit: false,
|
||
mask: false,
|
||
validateOnBlur: true,
|
||
allowBlank: true,
|
||
yearStart: 1950,
|
||
yearEnd: 2050,
|
||
style: '',
|
||
id: '',
|
||
fixed: false,
|
||
roundTime: 'round', // ceil, floor
|
||
className: '',
|
||
weekends: [],
|
||
disabledDates : [],
|
||
yearOffset: 0,
|
||
beforeShowDay: null,
|
||
|
||
enterLikeTab: true
|
||
};
|
||
// fix for ie8
|
||
if (!Array.prototype.indexOf) {
|
||
Array.prototype.indexOf = function (obj, start) {
|
||
var i, j;
|
||
for (i = (start || 0), j = this.length; i < j; i += 1) {
|
||
if (this[i] === obj) { return i; }
|
||
}
|
||
return -1;
|
||
};
|
||
}
|
||
Date.prototype.countDaysInMonth = function () {
|
||
return new Date(this.getFullYear(), this.getMonth() + 1, 0).getDate();
|
||
};
|
||
$.fn.xdsoftScroller = function (percent) {
|
||
return this.each(function () {
|
||
var timeboxparent = $(this),
|
||
pointerEventToXY = function (e) {
|
||
var out = {x: 0, y: 0},
|
||
touch;
|
||
if (e.type === 'touchstart' || e.type === 'touchmove' || e.type === 'touchend' || e.type === 'touchcancel') {
|
||
touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
|
||
out.x = touch.clientX;
|
||
out.y = touch.clientY;
|
||
} else if (e.type === 'mousedown' || e.type === 'mouseup' || e.type === 'mousemove' || e.type === 'mouseover' || e.type === 'mouseout' || e.type === 'mouseenter' || e.type === 'mouseleave') {
|
||
out.x = e.clientX;
|
||
out.y = e.clientY;
|
||
}
|
||
return out;
|
||
},
|
||
move = 0,
|
||
timebox,
|
||
parentHeight,
|
||
height,
|
||
scrollbar,
|
||
scroller,
|
||
maximumOffset = 100,
|
||
start = false,
|
||
startY = 0,
|
||
startTop = 0,
|
||
h1 = 0,
|
||
touchStart = false,
|
||
startTopScroll = 0,
|
||
calcOffset = function () {};
|
||
if (percent === 'hide') {
|
||
timeboxparent.find('.xdsoft_scrollbar').hide();
|
||
return;
|
||
}
|
||
if (!$(this).hasClass('xdsoft_scroller_box')) {
|
||
timebox = timeboxparent.children().eq(0);
|
||
parentHeight = timeboxparent[0].clientHeight;
|
||
height = timebox[0].offsetHeight;
|
||
scrollbar = $('<div class="xdsoft_scrollbar"></div>');
|
||
scroller = $('<div class="xdsoft_scroller"></div>');
|
||
scrollbar.append(scroller);
|
||
|
||
timeboxparent.addClass('xdsoft_scroller_box').append(scrollbar);
|
||
calcOffset = function calcOffset(event) {
|
||
var offset = pointerEventToXY(event).y - startY + startTopScroll;
|
||
if (offset < 0) {
|
||
offset = 0;
|
||
}
|
||
if (offset + scroller[0].offsetHeight > h1) {
|
||
offset = h1 - scroller[0].offsetHeight;
|
||
}
|
||
timeboxparent.trigger('scroll_element.xdsoft_scroller', [maximumOffset ? offset / maximumOffset : 0]);
|
||
};
|
||
|
||
scroller
|
||
.on('touchstart.xdsoft_scroller mousedown.xdsoft_scroller', function (event) {
|
||
if (!parentHeight) {
|
||
timeboxparent.trigger('resize_scroll.xdsoft_scroller', [percent]);
|
||
}
|
||
|
||
startY = pointerEventToXY(event).y;
|
||
startTopScroll = parseInt(scroller.css('margin-top'), 10);
|
||
h1 = scrollbar[0].offsetHeight;
|
||
|
||
if (event.type === 'mousedown') {
|
||
if (document) {
|
||
$(document.body).addClass('xdsoft_noselect');
|
||
}
|
||
$([document.body, window]).on('mouseup.xdsoft_scroller', function arguments_callee() {
|
||
$([document.body, window]).off('mouseup.xdsoft_scroller', arguments_callee)
|
||
.off('mousemove.xdsoft_scroller', calcOffset)
|
||
.removeClass('xdsoft_noselect');
|
||
});
|
||
$(document.body).on('mousemove.xdsoft_scroller', calcOffset);
|
||
} else {
|
||
touchStart = true;
|
||
event.stopPropagation();
|
||
event.preventDefault();
|
||
}
|
||
})
|
||
.on('touchmove', function (event) {
|
||
if (touchStart) {
|
||
event.preventDefault();
|
||
calcOffset(event);
|
||
}
|
||
})
|
||
.on('touchend touchcancel', function (event) {
|
||
touchStart = false;
|
||
startTopScroll = 0;
|
||
});
|
||
|
||
timeboxparent
|
||
.on('scroll_element.xdsoft_scroller', function (event, percentage) {
|
||
if (!parentHeight) {
|
||
timeboxparent.trigger('resize_scroll.xdsoft_scroller', [percentage, true]);
|
||
}
|
||
percentage = percentage > 1 ? 1 : (percentage < 0 || isNaN(percentage)) ? 0 : percentage;
|
||
|
||
scroller.css('margin-top', maximumOffset * percentage);
|
||
|
||
setTimeout(function () {
|
||
timebox.css('marginTop', -parseInt((timebox[0].offsetHeight - parentHeight) * percentage, 10));
|
||
}, 10);
|
||
})
|
||
.on('resize_scroll.xdsoft_scroller', function (event, percentage, noTriggerScroll) {
|
||
var percent, sh;
|
||
parentHeight = timeboxparent[0].clientHeight;
|
||
height = timebox[0].offsetHeight;
|
||
percent = parentHeight / height;
|
||
sh = percent * scrollbar[0].offsetHeight;
|
||
if (percent > 1) {
|
||
scroller.hide();
|
||
} else {
|
||
scroller.show();
|
||
scroller.css('height', parseInt(sh > 10 ? sh : 10, 10));
|
||
maximumOffset = scrollbar[0].offsetHeight - scroller[0].offsetHeight;
|
||
if (noTriggerScroll !== true) {
|
||
timeboxparent.trigger('scroll_element.xdsoft_scroller', [percentage || Math.abs(parseInt(timebox.css('marginTop'), 10)) / (height - parentHeight)]);
|
||
}
|
||
}
|
||
});
|
||
|
||
timeboxparent.on('mousewheel', function (event) {
|
||
var top = Math.abs(parseInt(timebox.css('marginTop'), 10));
|
||
|
||
top = top - (event.deltaY * 20);
|
||
if (top < 0) {
|
||
top = 0;
|
||
}
|
||
|
||
timeboxparent.trigger('scroll_element.xdsoft_scroller', [top / (height - parentHeight)]);
|
||
event.stopPropagation();
|
||
return false;
|
||
});
|
||
|
||
timeboxparent.on('touchstart', function (event) {
|
||
start = pointerEventToXY(event);
|
||
startTop = Math.abs(parseInt(timebox.css('marginTop'), 10));
|
||
});
|
||
|
||
timeboxparent.on('touchmove', function (event) {
|
||
if (start) {
|
||
event.preventDefault();
|
||
var coord = pointerEventToXY(event);
|
||
timeboxparent.trigger('scroll_element.xdsoft_scroller', [(startTop - (coord.y - start.y)) / (height - parentHeight)]);
|
||
}
|
||
});
|
||
|
||
timeboxparent.on('touchend touchcancel', function (event) {
|
||
start = false;
|
||
startTop = 0;
|
||
});
|
||
}
|
||
timeboxparent.trigger('resize_scroll.xdsoft_scroller', [percent]);
|
||
});
|
||
};
|
||
|
||
$.fn.datetimepicker = function (opt) {
|
||
var KEY0 = 48,
|
||
KEY9 = 57,
|
||
_KEY0 = 96,
|
||
_KEY9 = 105,
|
||
CTRLKEY = 17,
|
||
DEL = 46,
|
||
ENTER = 13,
|
||
ESC = 27,
|
||
BACKSPACE = 8,
|
||
ARROWLEFT = 37,
|
||
ARROWUP = 38,
|
||
ARROWRIGHT = 39,
|
||
ARROWDOWN = 40,
|
||
TAB = 9,
|
||
F5 = 116,
|
||
AKEY = 65,
|
||
CKEY = 67,
|
||
VKEY = 86,
|
||
ZKEY = 90,
|
||
YKEY = 89,
|
||
ctrlDown = false,
|
||
options = ($.isPlainObject(opt) || !opt) ? $.extend(true, {}, default_options, opt) : $.extend(true, {}, default_options),
|
||
|
||
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')) {
|
||
return;
|
||
}
|
||
clearTimeout(lazyInitTimer);
|
||
lazyInitTimer = setTimeout(function () {
|
||
|
||
if (!input.data('xdsoft_datetimepicker')) {
|
||
createDateTimePicker(input);
|
||
}
|
||
input
|
||
.off('open.xdsoft focusin.xdsoft mousedown.xdsoft', initOnActionCallback)
|
||
.trigger('open.xdsoft');
|
||
}, 100);
|
||
});
|
||
};
|
||
|
||
createDateTimePicker = function (input) {
|
||
var datetimepicker = $('<div ' + (options.id ? 'id="' + options.id + '"' : '') + ' ' + (options.style ? 'style="' + options.style + '"' : '') + ' class="xdsoft_datetimepicker xdsoft_' + options.theme + ' xdsoft_noselect ' + (options.weeks ? ' xdsoft_showweeks' : '') + options.className + '"></div>'),
|
||
xdsoft_copyright = $('<div class="xdsoft_copyright"><a target="_blank" href="http://xdsoft.net/jqplugins/datetimepicker/">xdsoft.net</a></div>'),
|
||
datepicker = $('<div class="xdsoft_datepicker active"></div>'),
|
||
mounth_picker = $('<div class="xdsoft_mounthpicker"><button type="button" class="xdsoft_prev"></button><button type="button" class="xdsoft_today_button"></button>' +
|
||
'<div class="xdsoft_label xdsoft_month"><span></span><i></i></div>' +
|
||
'<div class="xdsoft_label xdsoft_year"><span></span><i></i></div>' +
|
||
'<button type="button" class="xdsoft_next"></button></div>'),
|
||
calendar = $('<div class="xdsoft_calendar"></div>'),
|
||
timepicker = $('<div class="xdsoft_timepicker active"><button type="button" class="xdsoft_prev"></button><div class="xdsoft_time_box"></div><button type="button" class="xdsoft_next"></button></div>'),
|
||
timeboxparent = timepicker.find('.xdsoft_time_box').eq(0),
|
||
timebox = $('<div class="xdsoft_time_variant"></div>'),
|
||
/*scrollbar = $('<div class="xdsoft_scrollbar"></div>'),
|
||
scroller = $('<div class="xdsoft_scroller"></div>'),*/
|
||
monthselect = $('<div class="xdsoft_select xdsoft_monthselect"><div></div></div>'),
|
||
yearselect = $('<div class="xdsoft_select xdsoft_yearselect"><div></div></div>'),
|
||
triggerAfterOpen = false,
|
||
XDSoft_datetime,
|
||
//scroll_element,
|
||
xchangeTimer,
|
||
timerclick,
|
||
current_time_index,
|
||
setPos,
|
||
timer = 0,
|
||
timer1 = 0;
|
||
|
||
mounth_picker
|
||
.find('.xdsoft_month span')
|
||
.after(monthselect);
|
||
mounth_picker
|
||
.find('.xdsoft_year span')
|
||
.after(yearselect);
|
||
|
||
mounth_picker
|
||
.find('.xdsoft_month,.xdsoft_year')
|
||
.on('mousedown.xdsoft', function (event) {
|
||
var select = $(this).find('.xdsoft_select').eq(0),
|
||
val = 0,
|
||
top = 0,
|
||
visible = select.is(':visible'),
|
||
items,
|
||
i;
|
||
|
||
mounth_picker
|
||
.find('.xdsoft_select')
|
||
.hide();
|
||
if (_xdsoft_datetime.currentTime) {
|
||
val = _xdsoft_datetime.currentTime[$(this).hasClass('xdsoft_month') ? 'getMonth' : 'getFullYear']();
|
||
}
|
||
|
||
select[visible ? 'hide' : 'show']();
|
||
for (items = select.find('div.xdsoft_option'), i = 0; i < items.length; i += 1) {
|
||
if (items.eq(i).data('value') === val) {
|
||
break;
|
||
} else {
|
||
top += items[0].offsetHeight;
|
||
}
|
||
}
|
||
|
||
select.xdsoftScroller(top / (select.children()[0].offsetHeight - (select[0].clientHeight)));
|
||
event.stopPropagation();
|
||
return false;
|
||
});
|
||
|
||
mounth_picker
|
||
.find('.xdsoft_select')
|
||
.xdsoftScroller()
|
||
.on('mousedown.xdsoft', function (event) {
|
||
event.stopPropagation();
|
||
event.preventDefault();
|
||
})
|
||
.on('mousedown.xdsoft', '.xdsoft_option', function (event) {
|
||
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'));
|
||
}
|
||
|
||
$(this).parent().parent().hide();
|
||
|
||
datetimepicker.trigger('xchange.xdsoft');
|
||
if (options.onChangeMonth && $.isFunction(options.onChangeMonth)) {
|
||
options.onChangeMonth.call(datetimepicker, _xdsoft_datetime.currentTime, datetimepicker.data('input'));
|
||
}
|
||
|
||
if (year !== _xdsoft_datetime.currentTime.getFullYear() && $.isFunction(options.onChangeYear)) {
|
||
options.onChangeYear.call(datetimepicker, _xdsoft_datetime.currentTime, datetimepicker.data('input'));
|
||
}
|
||
});
|
||
|
||
datetimepicker.setOptions = function (_options) {
|
||
options = $.extend(true, {}, options, _options);
|
||
|
||
if (_options.allowTimes && $.isArray(_options.allowTimes) && _options.allowTimes.length) {
|
||
options.allowTimes = $.extend(true, [], _options.allowTimes);
|
||
}
|
||
|
||
if (_options.weekends && $.isArray(_options.weekends) && _options.weekends.length) {
|
||
options.weekends = $.extend(true, [], _options.weekends);
|
||
}
|
||
|
||
if (_options.disabledDates && $.isArray(_options.disabledDates) && _options.disabledDates.length) {
|
||
options.disabledDates = $.extend(true, [], _options.disabledDates);
|
||
}
|
||
|
||
if ((options.open || options.opened) && (!options.inline)) {
|
||
input.trigger('open.xdsoft');
|
||
}
|
||
|
||
if (options.inline) {
|
||
triggerAfterOpen = true;
|
||
datetimepicker.addClass('xdsoft_inline');
|
||
input.after(datetimepicker).hide();
|
||
}
|
||
|
||
if (options.inverseButton) {
|
||
options.next = 'xdsoft_prev';
|
||
options.prev = 'xdsoft_next';
|
||
}
|
||
|
||
if (options.datepicker) {
|
||
datepicker.addClass('active');
|
||
} else {
|
||
datepicker.removeClass('active');
|
||
}
|
||
|
||
if (options.timepicker) {
|
||
timepicker.addClass('active');
|
||
} else {
|
||
timepicker.removeClass('active');
|
||
}
|
||
|
||
if (options.value) {
|
||
if (input && input.val) {
|
||
input.val(options.value);
|
||
}
|
||
_xdsoft_datetime.setCurrentTime(options.value);
|
||
}
|
||
|
||
if (isNaN(options.dayOfWeekStart)) {
|
||
options.dayOfWeekStart = 0;
|
||
} else {
|
||
options.dayOfWeekStart = parseInt(options.dayOfWeekStart, 10) % 7;
|
||
}
|
||
|
||
if (!options.timepickerScrollbar) {
|
||
timeboxparent.xdsoftScroller('hide');
|
||
}
|
||
|
||
if (options.minDate && /^-(.*)$/.test(options.minDate)) {
|
||
options.minDate = _xdsoft_datetime.strToDateTime(options.minDate).dateFormat(options.formatDate);
|
||
}
|
||
|
||
if (options.maxDate && /^\+(.*)$/.test(options.maxDate)) {
|
||
options.maxDate = _xdsoft_datetime.strToDateTime(options.maxDate).dateFormat(options.formatDate);
|
||
}
|
||
|
||
mounth_picker
|
||
.find('.xdsoft_today_button')
|
||
.css('visibility', !options.todayButton ? '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) {
|
||
options.mask = options.format
|
||
.replace(/Y/g, '9999')
|
||
.replace(/F/g, '9999')
|
||
.replace(/m/g, '19')
|
||
.replace(/d/g, '39')
|
||
.replace(/H/g, '29')
|
||
.replace(/i/g, '59')
|
||
.replace(/s/g, '59');
|
||
}
|
||
|
||
if ($.type(options.mask) === 'string') {
|
||
if (!isValidValue(options.mask, input.val())) {
|
||
input.val(options.mask.replace(/[0-9]/g, '_'));
|
||
}
|
||
|
||
input.on('keydown.xdsoft', function (event) {
|
||
var val = this.value,
|
||
key = event.which,
|
||
pos,
|
||
digit;
|
||
|
||
if (((key >= KEY0 && key <= KEY9) || (key >= _KEY0 && key <= _KEY9)) || (key === BACKSPACE || key === DEL)) {
|
||
pos = getCaretPos(this);
|
||
digit = (key !== BACKSPACE && key !== DEL) ? String.fromCharCode((_KEY0 <= key && key <= _KEY9) ? key - KEY0 : key) : '_';
|
||
|
||
if ((key === BACKSPACE || key === DEL) && pos) {
|
||
pos -= 1;
|
||
digit = '_';
|
||
}
|
||
|
||
while (/[^0-9_]/.test(options.mask.substr(pos, 1)) && pos < options.mask.length && pos > 0) {
|
||
pos += (key === BACKSPACE || key === DEL) ? -1 : 1;
|
||
}
|
||
|
||
val = val.substr(0, pos) + digit + val.substr(pos + 1);
|
||
if ($.trim(val) === '') {
|
||
val = options.mask.replace(/[0-9]/g, '_');
|
||
} else {
|
||
if (pos === options.mask.length) {
|
||
event.preventDefault();
|
||
return false;
|
||
}
|
||
}
|
||
|
||
pos += (key === BACKSPACE || key === DEL) ? 0 : 1;
|
||
while (/[^0-9_]/.test(options.mask.substr(pos, 1)) && pos < options.mask.length && pos > 0) {
|
||
pos += (key === BACKSPACE || key === DEL) ? -1 : 1;
|
||
}
|
||
|
||
if (isValidValue(options.mask, val)) {
|
||
this.value = val;
|
||
setCaretPos(this, pos);
|
||
} else if ($.trim(val) === '') {
|
||
this.value = options.mask.replace(/[0-9]/g, '_');
|
||
} else {
|
||
input.trigger('error_input.xdsoft');
|
||
}
|
||
} else {
|
||
if (([AKEY, CKEY, VKEY, ZKEY, YKEY].indexOf(key) !== -1 && ctrlDown) || [ESC, ARROWUP, ARROWDOWN, ARROWLEFT, ARROWRIGHT, F5, CTRLKEY, TAB, ENTER].indexOf(key) !== -1) {
|
||
return true;
|
||
}
|
||
}
|
||
|
||
event.preventDefault();
|
||
return false;
|
||
});
|
||
}
|
||
}
|
||
if (options.validateOnBlur) {
|
||
input
|
||
.off('blur.xdsoft')
|
||
.on('blur.xdsoft', function () {
|
||
if (options.allowBlank && !$.trim($(this).val()).length) {
|
||
$(this).val(null);
|
||
datetimepicker.data('xdsoft_datetime').empty();
|
||
} else if (!Date.parseDate($(this).val(), options.format)) {
|
||
$(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');
|
||
});
|
||
}
|
||
options.dayOfWeekStartPrev = (options.dayOfWeekStart === 0) ? 6 : options.dayOfWeekStart - 1;
|
||
|
||
datetimepicker
|
||
.trigger('xchange.xdsoft')
|
||
.trigger('afterOpen.xdsoft');
|
||
};
|
||
|
||
datetimepicker
|
||
.data('options', options)
|
||
.on('mousedown.xdsoft', function (event) {
|
||
event.stopPropagation();
|
||
event.preventDefault();
|
||
yearselect.hide();
|
||
monthselect.hide();
|
||
return false;
|
||
});
|
||
|
||
//scroll_element = timepicker.find('.xdsoft_time_box');
|
||
timeboxparent.append(timebox);
|
||
timeboxparent.xdsoftScroller();
|
||
|
||
datetimepicker.on('afterOpen.xdsoft', function () {
|
||
timeboxparent.xdsoftScroller();
|
||
});
|
||
|
||
datetimepicker
|
||
.append(datepicker)
|
||
.append(timepicker);
|
||
|
||
if (options.withoutCopyright !== true) {
|
||
datetimepicker
|
||
.append(xdsoft_copyright);
|
||
}
|
||
|
||
datepicker
|
||
.append(mounth_picker)
|
||
.append(calendar);
|
||
|
||
$(options.parentID)
|
||
.append(datetimepicker);
|
||
|
||
XDSoft_datetime = function () {
|
||
var _this = this;
|
||
_this.now = function (norecursion) {
|
||
var d = new Date(),
|
||
date,
|
||
time;
|
||
|
||
if (!norecursion && options.defaultDate) {
|
||
date = _this.strToDate(options.defaultDate);
|
||
d.setFullYear(date.getFullYear());
|
||
d.setMonth(date.getMonth());
|
||
d.setDate(date.getDate());
|
||
}
|
||
|
||
if (options.yearOffset) {
|
||
d.setFullYear(d.getFullYear() + options.yearOffset);
|
||
}
|
||
|
||
if (!norecursion && options.defaultTime) {
|
||
time = _this.strtotime(options.defaultTime);
|
||
d.setHours(time.getHours());
|
||
d.setMinutes(time.getMinutes());
|
||
}
|
||
|
||
return d;
|
||
};
|
||
|
||
_this.isValidDate = function (d) {
|
||
if (Object.prototype.toString.call(d) !== "[object Date]") {
|
||
return false;
|
||
}
|
||
return !isNaN(d.getTime());
|
||
};
|
||
|
||
_this.setCurrentTime = function (dTime) {
|
||
_this.currentTime = (typeof dTime === 'string') ? _this.strToDateTime(dTime) : _this.isValidDate(dTime) ? dTime : _this.now();
|
||
datetimepicker.trigger('xchange.xdsoft');
|
||
};
|
||
|
||
_this.empty = function () {
|
||
_this.currentTime = null;
|
||
};
|
||
|
||
_this.getCurrentTime = function (dTime) {
|
||
return _this.currentTime;
|
||
};
|
||
|
||
_this.nextMonth = function () {
|
||
var month = _this.currentTime.getMonth() + 1,
|
||
year;
|
||
if (month === 12) {
|
||
_this.currentTime.setFullYear(_this.currentTime.getFullYear() + 1);
|
||
month = 0;
|
||
}
|
||
|
||
year = _this.currentTime.getFullYear();
|
||
|
||
_this.currentTime.setDate(
|
||
Math.min(
|
||
new Date(_this.currentTime.getFullYear(), month + 1, 0).getDate(),
|
||
_this.currentTime.getDate()
|
||
)
|
||
);
|
||
_this.currentTime.setMonth(month);
|
||
|
||
if (options.onChangeMonth && $.isFunction(options.onChangeMonth)) {
|
||
options.onChangeMonth.call(datetimepicker, _xdsoft_datetime.currentTime, datetimepicker.data('input'));
|
||
}
|
||
|
||
if (year !== _this.currentTime.getFullYear() && $.isFunction(options.onChangeYear)) {
|
||
options.onChangeYear.call(datetimepicker, _xdsoft_datetime.currentTime, datetimepicker.data('input'));
|
||
}
|
||
|
||
datetimepicker.trigger('xchange.xdsoft');
|
||
return month;
|
||
};
|
||
|
||
_this.prevMonth = function () {
|
||
var month = _this.currentTime.getMonth() - 1;
|
||
if (month === -1) {
|
||
_this.currentTime.setFullYear(_this.currentTime.getFullYear() - 1);
|
||
month = 11;
|
||
}
|
||
_this.currentTime.setDate(
|
||
Math.min(
|
||
new Date(_this.currentTime.getFullYear(), month + 1, 0).getDate(),
|
||
_this.currentTime.getDate()
|
||
)
|
||
);
|
||
_this.currentTime.setMonth(month);
|
||
if (options.onChangeMonth && $.isFunction(options.onChangeMonth)) {
|
||
options.onChangeMonth.call(datetimepicker, _xdsoft_datetime.currentTime, datetimepicker.data('input'));
|
||
}
|
||
datetimepicker.trigger('xchange.xdsoft');
|
||
return month;
|
||
};
|
||
|
||
_this.getWeekOfYear = function (datetime) {
|
||
var onejan = new Date(datetime.getFullYear(), 0, 1);
|
||
return Math.ceil((((datetime - onejan) / 86400000) + onejan.getDay() + 1) / 7);
|
||
};
|
||
|
||
_this.strToDateTime = function (sDateTime) {
|
||
var tmpDate = [], timeOffset, currentTime;
|
||
|
||
if (sDateTime && sDateTime instanceof Date && _this.isValidDate(sDateTime)) {
|
||
return sDateTime;
|
||
}
|
||
|
||
tmpDate = /^(\+|\-)(.*)$/.exec(sDateTime);
|
||
if (tmpDate) {
|
||
tmpDate[2] = Date.parseDate(tmpDate[2], options.formatDate);
|
||
}
|
||
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);
|
||
} else {
|
||
currentTime = sDateTime ? Date.parseDate(sDateTime, options.format) : _this.now();
|
||
}
|
||
|
||
if (!_this.isValidDate(currentTime)) {
|
||
currentTime = _this.now();
|
||
}
|
||
|
||
return currentTime;
|
||
};
|
||
|
||
_this.strToDate = function (sDate) {
|
||
if (sDate && sDate instanceof Date && _this.isValidDate(sDate)) {
|
||
return sDate;
|
||
}
|
||
|
||
var currentTime = sDate ? Date.parseDate(sDate, options.formatDate) : _this.now(true);
|
||
if (!_this.isValidDate(currentTime)) {
|
||
currentTime = _this.now(true);
|
||
}
|
||
return currentTime;
|
||
};
|
||
|
||
_this.strtotime = function (sTime) {
|
||
if (sTime && sTime instanceof Date && _this.isValidDate(sTime)) {
|
||
return sTime;
|
||
}
|
||
var currentTime = sTime ? Date.parseDate(sTime, options.formatTime) : _this.now(true);
|
||
if (!_this.isValidDate(currentTime)) {
|
||
currentTime = _this.now(true);
|
||
}
|
||
return currentTime;
|
||
};
|
||
|
||
_this.str = function () {
|
||