Advertisement
hrb2020

Untitled

Aug 28th, 2020
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 55.71 KB | None | 0 0
  1. /**
  2. * @preserve jQuery DateTimePicker plugin v2.2.4
  3. * @homepage http://xdsoft.net/jqplugins/datetimepicker/
  4. * (c) 2014, Chupurnov Valeriy.
  5. */
  6. (function( $ ) {
  7. 'use strict'
  8. var default_options = {
  9. i18n:{
  10. ru:{ // Russian
  11. months:[
  12. 'Январь','Февраль','Март','Апрель','Май','Июнь','Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'
  13. ],
  14. dayOfWeek:[
  15. "Вск", "Пн", "Вт", "Ср", "Чт", "Пт", "Сб"
  16. ]
  17. },
  18. en:{ // English
  19. months: [
  20. "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
  21. ],
  22. dayOfWeek: [
  23. "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
  24. ]
  25. },
  26. de:{ // German
  27. months:[
  28. 'Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'
  29. ],
  30. dayOfWeek:[
  31. "So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"
  32. ]
  33. },
  34. nl:{ // Dutch
  35. months:[
  36. "januari", "februari", "maart", "april", "mei", "juni", "juli", "augustus", "september", "oktober", "november", "december"
  37. ],
  38. dayOfWeek:[
  39. "zo", "ma", "di", "wo", "do", "vr", "za"
  40. ]
  41. },
  42. tr:{ // Turkish
  43. months:[
  44. "Ocak", "Şubat", "Mart", "Nisan", "Mayıs", "Haziran", "Temmuz", "Ağustos", "Eylül", "Ekim", "Kasım", "Aralık"
  45. ],
  46. dayOfWeek:[
  47. "Paz", "Pts", "Sal", "Çar", "Per", "Cum", "Cts"
  48. ]
  49. },
  50. fr:{ //French
  51. months:[
  52. "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"
  53. ],
  54. dayOfWeek:[
  55. "Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"
  56. ]
  57. },
  58. es:{ // Spanish
  59. months: [
  60. "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"
  61. ],
  62. dayOfWeek: [
  63. "Dom", "Lun", "Mar", "Mié", "Jue", "Vie", "Sáb"
  64. ]
  65. },
  66. th:{ // Thai
  67. months:[
  68. 'มกราคม','กุมภาพันธ์','มีนาคม','เมษายน','พฤษภาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม'
  69. ],
  70. dayOfWeek:[
  71. 'อา.','จ.','อ.','พ.','พฤ.','ศ.','ส.'
  72. ]
  73. },
  74. pl:{ // Polish
  75. months: [
  76. "styczeń", "luty", "marzec", "kwiecień", "maj", "czerwiec", "lipiec", "sierpień", "wrzesień", "październik", "listopad", "grudzień"
  77. ],
  78. dayOfWeek: [
  79. "nd", "pn", "wt", "śr", "cz", "pt", "sb"
  80. ]
  81. },
  82. pt:{ // Portuguese
  83. months: [
  84. "Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"
  85. ],
  86. dayOfWeek: [
  87. "Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sab"
  88. ]
  89. },
  90. ch:{ // Simplified Chinese
  91. months: [
  92. "一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"
  93. ],
  94. dayOfWeek: [
  95. "日", "一","二","三","四","五","六"
  96. ]
  97. },
  98. se:{ // Swedish
  99. months: [
  100. "Januari", "Februari", "Mars", "April", "Maj", "Juni", "Juli", "Augusti", "September","Oktober", "November", "December"
  101. ],
  102. dayOfWeek: [
  103. "Sön", "Mån", "Tis", "Ons", "Tor", "Fre", "Lör"
  104. ]
  105. },
  106. kr:{ // Korean
  107. months: [
  108. "1ì›”", "2ì›”", "3ì›”", "4ì›”", "5ì›”", "6ì›”", "7ì›”", "8ì›”", "9ì›”", "10ì›”", "11ì›”", "12ì›”"
  109. ],
  110. dayOfWeek: [
  111. "일", "ì›”", "í™”", "수", "목", "금", "í† "
  112. ]
  113. },
  114. it:{ // Italian
  115. months: [
  116. "Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"
  117. ],
  118. dayOfWeek: [
  119. "Dom", "Lun", "Mar", "Mer", "Gio", "Ven", "Sab"
  120. ]
  121. },
  122. da:{ // Dansk
  123. months: [
  124. "January", "Februar", "Marts", "April", "Maj", "Juni", "July", "August", "September", "Oktober", "November", "December"
  125. ],
  126. dayOfWeek: [
  127. "Søn", "Man", "Tir", "ons", "Tor", "Fre", "lør"
  128. ]
  129. },
  130. ja:{ // Japanese
  131. months: [
  132. "1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"
  133. ],
  134. dayOfWeek: [
  135. "日", "月", "火", "水", "木", "金", "土"
  136. ]
  137. },
  138. },
  139. value:'',
  140. lang: 'en',
  141.  
  142. format: 'Y/m/d H:i',
  143. formatTime: 'H:i',
  144. formatDate: 'Y/m/d',
  145.  
  146. startDate: false, // new Date(), '1986/12/08', '-1970/01/05','-1970/01/05',
  147.  
  148. //fromUnixtime: false,
  149.  
  150. step:60,
  151.  
  152. closeOnDateSelect:true,
  153. closeOnWithoutClick:true,
  154.  
  155. timepicker:true,
  156. datepicker:true,
  157.  
  158. minDate:false,
  159. maxDate:false,
  160. minTime:false,
  161. maxTime:false,
  162.  
  163. allowTimes:[],
  164. opened:false,
  165. initTime:true,
  166. inline:false,
  167.  
  168. onSelectDate:function() {},
  169. onSelectTime:function() {},
  170. onChangeMonth:function() {},
  171. onChangeDateTime:function() {},
  172. onShow:function() {},
  173. onClose:function() {},
  174. onGenerate:function() {},
  175.  
  176. withoutCopyright:true,
  177.  
  178. inverseButton:false,
  179. hours12:false,
  180. next: 'xdsoft_next',
  181. prev : 'xdsoft_prev',
  182. dayOfWeekStart:0,
  183.  
  184. timeHeightInTimePicker:25,
  185. timepickerScrollbar:true,
  186.  
  187. todayButton:true, // 2.1.0
  188. defaultSelect:true, // 2.1.0
  189.  
  190. scrollMonth:true,
  191. scrollTime:true,
  192. scrollInput:true,
  193.  
  194. lazyInit:false,
  195.  
  196. mask:false,
  197. validateOnBlur:true,
  198. allowBlank:true,
  199.  
  200. yearStart:1950,
  201. yearEnd:2050,
  202.  
  203. style:'',
  204. id:'',
  205.  
  206. roundTime:'round', // ceil, floor
  207. className:'',
  208.  
  209. weekends : [],
  210. yearOffset:0
  211. };
  212.  
  213. // fix for ie8
  214. if ( !Array.prototype.indexOf ) {
  215. Array.prototype.indexOf = function(obj, start) {
  216. for (var i = (start || 0), j = this.length; i < j; i++) {
  217. if (this[i] === obj) { return i; }
  218. }
  219. return -1;
  220. }
  221. };
  222.  
  223. $.fn.xdsoftScroller = function( _percent ) {
  224. return this.each(function() {
  225. var timeboxparent = $(this);
  226. if( !$(this).hasClass('xdsoft_scroller_box') ) {
  227. var pointerEventToXY = function( e ) {
  228. var out = {x:0, y:0};
  229. if( e.type == 'touchstart' || e.type == 'touchmove' || e.type == 'touchend' || e.type == 'touchcancel' ) {
  230. var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
  231. out.x = touch.pageX;
  232. out.y = touch.pageY;
  233. }else if (e.type == 'mousedown' || e.type == 'mouseup' || e.type == 'mousemove' || e.type == 'mouseover'|| e.type=='mouseout' || e.type=='mouseenter' || e.type=='mouseleave') {
  234. out.x = e.pageX;
  235. out.y = e.pageY;
  236. }
  237. return out;
  238. },
  239. move = 0,
  240. timebox = timeboxparent.children().eq(0),
  241. parentHeight = timeboxparent[0].clientHeight,
  242. height = timebox[0].offsetHeight,
  243. scrollbar = $('<div class="xdsoft_scrollbar"></div>'),
  244. scroller = $('<div class="xdsoft_scroller"></div>'),
  245. maximumOffset = 100,
  246. start = false;
  247.  
  248. scrollbar.append(scroller);
  249.  
  250. timeboxparent.addClass('xdsoft_scroller_box').append(scrollbar);
  251. scroller.on('mousedown.xdsoft_scroller',function ( event ) {
  252. if( !parentHeight )
  253. timeboxparent.trigger('resize_scroll.xdsoft_scroller',[_percent]);
  254. var pageY = event.pageY,
  255. top = parseInt(scroller.css('margin-top')),
  256. h1 = scrollbar[0].offsetHeight;
  257. $(document.body).addClass('xdsoft_noselect');
  258. $([document.body,window]).on('mouseup.xdsoft_scroller',function arguments_callee() {
  259. $([document.body,window]).off('mouseup.xdsoft_scroller',arguments_callee)
  260. .off('mousemove.xdsoft_scroller',move)
  261. .removeClass('xdsoft_noselect');
  262. });
  263. $(document.body).on('mousemove.xdsoft_scroller',move = function(event) {
  264. var offset = event.pageY-pageY+top;
  265. if( offset<0 )
  266. offset = 0;
  267. if( offset+scroller[0].offsetHeight>h1 )
  268. offset = h1-scroller[0].offsetHeight;
  269. timeboxparent.trigger('scroll_element.xdsoft_scroller',[maximumOffset?offset/maximumOffset:0]);
  270. });
  271. });
  272.  
  273. timeboxparent
  274. .on('scroll_element.xdsoft_scroller',function( event,percent ) {
  275. if( !parentHeight )
  276. timeboxparent.trigger('resize_scroll.xdsoft_scroller',[percent,true]);
  277. percent = percent>1?1:(percent<0||isNaN(percent))?0:percent;
  278. scroller.css('margin-top',maximumOffset*percent);
  279. timebox.css('marginTop',-parseInt((height-parentHeight)*percent))
  280. })
  281. .on('resize_scroll.xdsoft_scroller',function( event,_percent,noTriggerScroll ) {
  282. parentHeight = timeboxparent[0].clientHeight;
  283. height = timebox[0].offsetHeight;
  284. var percent = parentHeight/height,
  285. sh = percent*scrollbar[0].offsetHeight;
  286. if( percent>1 )
  287. scroller.hide();
  288. else{
  289. scroller.show();
  290. scroller.css('height',parseInt(sh>10?sh:10));
  291. maximumOffset = scrollbar[0].offsetHeight-scroller[0].offsetHeight;
  292. if( noTriggerScroll!==true )
  293. timeboxparent.trigger('scroll_element.xdsoft_scroller',[_percent?_percent:Math.abs(parseInt(timebox.css('marginTop')))/(height-parentHeight)]);
  294. }
  295. });
  296. timeboxparent.mousewheel&&timeboxparent.mousewheel(function(event, delta, deltaX, deltaY) {
  297. var top = Math.abs(parseInt(timebox.css('marginTop')));
  298. timeboxparent.trigger('scroll_element.xdsoft_scroller',[(top-delta*20)/(height-parentHeight)]);
  299. event.stopPropagation();
  300. return false;
  301. });
  302. timeboxparent.on('touchstart',function( event ) {
  303. start = pointerEventToXY(event);
  304. });
  305. timeboxparent.on('touchmove',function( event ) {
  306. if( start ) {
  307. var coord = pointerEventToXY(event), top = Math.abs(parseInt(timebox.css('marginTop')));
  308. timeboxparent.trigger('scroll_element.xdsoft_scroller',[(top-(coord.y-start.y))/(height-parentHeight)]);
  309. event.stopPropagation();
  310. event.preventDefault();
  311. };
  312. });
  313. timeboxparent.on('touchend touchcancel',function( event ) {
  314. start = false;
  315. });
  316. }
  317. timeboxparent.trigger('resize_scroll.xdsoft_scroller',[_percent]);
  318. });
  319. };
  320. $.fn.datetimepicker = function( opt ) {
  321. var KEY0 = 48,
  322. KEY9 = 57,
  323. _KEY0 = 96,
  324. _KEY9 = 105,
  325. CTRLKEY = 17,
  326. DEL = 46,
  327. ENTER = 13,
  328. ESC = 27,
  329. BACKSPACE = 8,
  330. ARROWLEFT = 37,
  331. ARROWUP = 38,
  332. ARROWRIGHT = 39,
  333. ARROWDOWN = 40,
  334. TAB = 9,
  335. F5 = 116,
  336. AKEY = 65,
  337. CKEY = 67,
  338. VKEY = 86,
  339. ZKEY = 90,
  340. YKEY = 89,
  341. ctrlDown = false,
  342. options = ($.isPlainObject(opt)||!opt)?$.extend(true,{},default_options,opt):$.extend({},default_options),
  343.  
  344. lazyInitTimer = 0,
  345.  
  346. lazyInit = function( input ){
  347. input
  348. .on('open.xdsoft focusin.xdsoft mousedown.xdsoft',function initOnActionCallback(event) {
  349. if( input.is(':disabled')||input.is(':hidden')||!input.is(':visible')||input.data( 'xdsoft_datetimepicker') )
  350. return;
  351.  
  352. clearTimeout(lazyInitTimer);
  353.  
  354. lazyInitTimer = setTimeout(function() {
  355.  
  356. if( !input.data( 'xdsoft_datetimepicker') )
  357. createDateTimePicker(input);
  358.  
  359. input
  360. .off('open.xdsoft focusin.xdsoft mousedown.xdsoft',initOnActionCallback)
  361. .trigger('open.xdsoft');
  362. },100);
  363.  
  364. });
  365. },
  366.  
  367. createDateTimePicker = function( input ) {
  368.  
  369. var datetimepicker = $('<div '+(options.id?'id="'+options.id+'"':'')+' '+(options.style?'style="'+options.style+'"':'')+' class="xdsoft_datetimepicker xdsoft_noselect '+options.className+'"></div>'),
  370. xdsoft_copyright = $('<div class="xdsoft_copyright"><a target="_blank" href="http://xdsoft.net/jqplugins/datetimepicker/">xdsoft.net</a></div>'),
  371. datepicker = $('<div class="xdsoft_datepicker active"></div>'),
  372. 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></div><div class="xdsoft_label xdsoft_year"><span></span></div><button type="button" class="xdsoft_next"></button></div>'),
  373. calendar = $('<div class="xdsoft_calendar"></div>'),
  374. 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>'),
  375. timeboxparent = timepicker.find('.xdsoft_time_box').eq(0),
  376. timebox = $('<div class="xdsoft_time_variant"></div>'),
  377. scrollbar = $('<div class="xdsoft_scrollbar"></div>'),
  378. scroller = $('<div class="xdsoft_scroller"></div>'),
  379. monthselect =$('<div class="xdsoft_select xdsoft_monthselect"><div></div></div>'),
  380. yearselect =$('<div class="xdsoft_select xdsoft_yearselect"><div></div></div>');
  381.  
  382. //constructor lego
  383. mounth_picker
  384. .find('.xdsoft_month span')
  385. .after(monthselect);
  386. mounth_picker
  387. .find('.xdsoft_year span')
  388. .after(yearselect);
  389.  
  390. mounth_picker
  391. .find('.xdsoft_month,.xdsoft_year')
  392. .on('mousedown.xdsoft',function(event) {
  393. mounth_picker
  394. .find('.xdsoft_select')
  395. .hide();
  396.  
  397. var select = $(this).find('.xdsoft_select').eq(0),
  398. val = 0,
  399. top = 0;
  400.  
  401. if( _xdsoft_datetime.currentTime )
  402. val = _xdsoft_datetime.currentTime[$(this).hasClass('xdsoft_month')?'getMonth':'getFullYear']();
  403.  
  404. select.show();
  405.  
  406. for(var items = select.find('div.xdsoft_option'),i = 0;i<items.length;i++) {
  407. if( items.eq(i).data('value')==val ) {
  408. break;
  409. }else top+=items[0].offsetHeight;
  410. }
  411.  
  412. select.xdsoftScroller(top/(select.children()[0].offsetHeight-(select[0].clientHeight)));
  413. event.stopPropagation();
  414.  
  415. return false;
  416. });
  417.  
  418. mounth_picker
  419. .find('.xdsoft_select')
  420. .xdsoftScroller()
  421. .on('mousedown.xdsoft',function( event ) {
  422. event.stopPropagation();
  423. event.preventDefault();
  424. })
  425. .on('mousedown.xdsoft','.xdsoft_option',function( event ) {
  426. if( _xdsoft_datetime&&_xdsoft_datetime.currentTime )
  427. _xdsoft_datetime.currentTime[$(this).parent().parent().hasClass('xdsoft_monthselect')?'setMonth':'setFullYear']($(this).data('value'));
  428.  
  429. $(this).parent().parent().hide();
  430.  
  431. datetimepicker.trigger('xchange.xdsoft');
  432. options.onChangeMonth&&options.onChangeMonth.call&&options.onChangeMonth.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
  433. });
  434.  
  435.  
  436. // set options
  437. datetimepicker.setOptions = function( _options ) {
  438. options = $.extend(true,{},options,_options);
  439.  
  440. if( _options.allowTimes && $.isArray(_options.allowTimes) && _options.allowTimes.length ){
  441. options['allowTimes'] = $.extend(true,[],_options.allowTimes);
  442. }
  443.  
  444. if( _options.weekends && $.isArray(_options.weekends) && _options.weekends.length ){
  445. options['weekends'] = $.extend(true,[],_options.weekends);
  446. }
  447.  
  448. if( (options.open||options.opened)&&(!options.inline) ) {
  449. input.trigger('open.xdsoft');
  450. }
  451.  
  452. if( options.inline ) {
  453. datetimepicker.addClass('xdsoft_inline');
  454. input.after(datetimepicker).hide();
  455. datetimepicker.trigger('afterOpen.xdsoft');
  456. }
  457.  
  458. if( options.inverseButton ) {
  459. options.next = 'xdsoft_prev';
  460. options.prev = 'xdsoft_next';
  461. }
  462.  
  463. if( options.datepicker )
  464. datepicker.addClass('active');
  465. else
  466. datepicker.removeClass('active');
  467.  
  468. if( options.timepicker )
  469. timepicker.addClass('active');
  470. else
  471. timepicker.removeClass('active');
  472.  
  473. if( options.value ){
  474. input&&input.val&&input.val(options.value);
  475. _xdsoft_datetime.setCurrentTime(options.value);
  476. }
  477.  
  478. if( isNaN(options.dayOfWeekStart)||parseInt(options.dayOfWeekStart)<0||parseInt(options.dayOfWeekStart)>6 )
  479. options.dayOfWeekStart = 0;
  480. else
  481. options.dayOfWeekStart = parseInt(options.dayOfWeekStart);
  482.  
  483. if( !options.timepickerScrollbar )
  484. scrollbar.hide();
  485.  
  486. if( options.minDate && /^-(.*)$/.test(options.minDate) ){
  487. options.minDate = _xdsoft_datetime.strToDateTime(options.minDate).dateFormat( options.formatDate );
  488. }
  489.  
  490. if( options.maxDate && /^\+(.*)$/.test(options.maxDate) ) {
  491. options.maxDate = _xdsoft_datetime.strToDateTime(options.maxDate).dateFormat( options.formatDate );
  492. }
  493.  
  494. mounth_picker
  495. .find('.xdsoft_today_button')
  496. .css('visibility',!options.todayButton?'hidden':'visible');
  497.  
  498. if( options.mask ) {
  499. var e,
  500. getCaretPos = function ( input ) {
  501. try{
  502. if ( document.selection && document.selection.createRange ) {
  503. var range = document.selection.createRange();
  504. return range.getBookmark().charCodeAt(2) - 2;
  505. }else
  506. if ( input.setSelectionRange )
  507. return input.selectionStart;
  508. }catch(e) {
  509. return 0;
  510. }
  511. },
  512. setCaretPos = function ( node,pos ) {
  513. var node = (typeof node == "string" || node instanceof String) ? document.getElementById(node) : node;
  514. if(!node) {
  515. return false;
  516. }else if(node.createTextRange) {
  517. var textRange = node.createTextRange();
  518. textRange.collapse(true);
  519. textRange.moveEnd(pos);
  520. textRange.moveStart(pos);
  521. textRange.select();
  522. return true;
  523. }else if(node.setSelectionRange) {
  524. node.setSelectionRange(pos,pos);
  525. return true;
  526. }
  527. return false;
  528. },
  529. isValidValue = function ( mask,value ) {
  530. var reg = mask
  531. .replace(/([\[\]\/\{\}\(\)\-\.\+]{1})/g,'\\$1')
  532. .replace(/_/g,'{digit+}')
  533. .replace(/([0-9]{1})/g,'{digit$1}')
  534. .replace(/\{digit([0-9]{1})\}/g,'[0-$1_]{1}')
  535. .replace(/\{digit[\+]\}/g,'[0-9_]{1}');
  536. return RegExp(reg).test(value);
  537. };
  538. input.off('keydown.xdsoft');
  539. switch(true) {
  540. case ( options.mask===true ):
  541.  
  542. options.mask = options.format
  543. .replace(/Y/g,'9999')
  544. .replace(/F/g,'9999')
  545. .replace(/m/g,'19')
  546. .replace(/d/g,'39')
  547. .replace(/H/g,'29')
  548. .replace(/i/g,'59')
  549. .replace(/s/g,'59');
  550.  
  551. case ( $.type(options.mask) == 'string' ):
  552.  
  553. if( !isValidValue( options.mask,input.val() ) )
  554. input.val(options.mask.replace(/[0-9]/g,'_'));
  555.  
  556. input.on('keydown.xdsoft',function( event ) {
  557. var val = this.value,
  558. key = event.which;
  559.  
  560. switch(true) {
  561. case (( key>=KEY0&&key<=KEY9 )||( key>=_KEY0&&key<=_KEY9 ))||(key==BACKSPACE||key==DEL):
  562. var pos = getCaretPos(this),
  563. digit = ( key!=BACKSPACE&&key!=DEL )?String.fromCharCode((_KEY0 <= key && key <= _KEY9)? key-KEY0 : key):'_';
  564.  
  565. if( (key==BACKSPACE||key==DEL)&&pos ) {
  566. pos--;
  567. digit='_';
  568. }
  569.  
  570. while( /[^0-9_]/.test(options.mask.substr(pos,1))&&pos<options.mask.length&&pos>0 )
  571. pos+=( key==BACKSPACE||key==DEL )?-1:1;
  572.  
  573. val = val.substr(0,pos)+digit+val.substr(pos+1);
  574. if( $.trim(val)=='' ){
  575. val = options.mask.replace(/[0-9]/g,'_');
  576. }else{
  577. if( pos==options.mask.length )
  578. break;
  579. }
  580.  
  581. pos+=(key==BACKSPACE||key==DEL)?0:1;
  582. while( /[^0-9_]/.test(options.mask.substr(pos,1))&&pos<options.mask.length&&pos>0 )
  583. pos+=(key==BACKSPACE||key==DEL)?-1:1;
  584.  
  585. if( isValidValue( options.mask,val ) ) {
  586. this.value = val;
  587. setCaretPos(this,pos);
  588. }else if( $.trim(val)=='' )
  589. this.value = options.mask.replace(/[0-9]/g,'_');
  590. else{
  591. input.trigger('error_input.xdsoft');
  592. }
  593. break;
  594. case ( !!~([AKEY,CKEY,VKEY,ZKEY,YKEY].indexOf(key))&&ctrlDown ):
  595. case !!~([ESC,ARROWUP,ARROWDOWN,ARROWLEFT,ARROWRIGHT,F5,CTRLKEY,TAB,ENTER].indexOf(key)):
  596. return true;
  597. }
  598. event.preventDefault();
  599. return false;
  600. });
  601. break;
  602. }
  603. }
  604. if( options.validateOnBlur ) {
  605. input
  606. .off('blur.xdsoft')
  607. .on('blur.xdsoft', function() {
  608. if( options.allowBlank && !$.trim($(this).val()).length ) {
  609. $(this).val(null);
  610. datetimepicker.data('xdsoft_datetime').empty();
  611. }else if( !Date.parseDate( $(this).val(), options.format ) ) {
  612. $(this).val((_xdsoft_datetime.now()).dateFormat( options.format ));
  613. datetimepicker.data('xdsoft_datetime').setCurrentTime($(this).val());
  614. }
  615. else{
  616. datetimepicker.data('xdsoft_datetime').setCurrentTime($(this).val());
  617. }
  618. datetimepicker.trigger('changedatetime.xdsoft');
  619. });
  620. }
  621. options.dayOfWeekStartPrev = (options.dayOfWeekStart==0)?6:options.dayOfWeekStart-1;
  622. datetimepicker
  623. .trigger('xchange.xdsoft');
  624. };
  625.  
  626. datetimepicker
  627. .data('options',options)
  628. .on('mousedown.xdsoft',function( event ) {
  629. event.stopPropagation();
  630. event.preventDefault();
  631. yearselect.hide();
  632. monthselect.hide();
  633. return false;
  634. });
  635.  
  636. var scroll_element = timepicker.find('.xdsoft_time_box');
  637. scroll_element.append(timebox);
  638. scroll_element.xdsoftScroller();
  639. datetimepicker.on('afterOpen.xdsoft',function() {
  640. scroll_element.xdsoftScroller();
  641. });
  642.  
  643. datetimepicker
  644. .append(datepicker)
  645. .append(timepicker);
  646.  
  647. if( options.withoutCopyright!==true )
  648. datetimepicker
  649. .append(xdsoft_copyright);
  650.  
  651. datepicker
  652. .append(mounth_picker)
  653. .append(calendar);
  654.  
  655. $('body').append(datetimepicker);
  656.  
  657. var _xdsoft_datetime = new function() {
  658. var _this = this;
  659. _this.now = function() {
  660. var d = new Date();
  661. if( options.yearOffset )
  662. d.setFullYear(d.getFullYear()+options.yearOffset);
  663. return d;
  664. };
  665.  
  666. _this.currentTime = this.now();
  667. _this.isValidDate = function (d) {
  668. if ( Object.prototype.toString.call(d) !== "[object Date]" )
  669. return false;
  670. return !isNaN(d.getTime());
  671. };
  672.  
  673. _this.setCurrentTime = function( dTime) {
  674. _this.currentTime = (typeof dTime == 'string')? _this.strToDateTime(dTime) : _this.isValidDate(dTime) ? dTime: _this.now();
  675. datetimepicker.trigger('xchange.xdsoft');
  676. };
  677.  
  678. _this.empty = function() {
  679. _this.currentTime = null;
  680. };
  681.  
  682. _this.getCurrentTime = function( dTime) {
  683. return _this.currentTime;
  684. };
  685.  
  686. _this.nextMonth = function() {
  687. var month = _this.currentTime.getMonth()+1;
  688. if( month==12 ) {
  689. _this.currentTime.setFullYear(_this.currentTime.getFullYear()+1);
  690. month = 0;
  691. }
  692. _this.currentTime.setDate(
  693. Math.min(
  694. Date.daysInMonth[month],
  695. _this.currentTime.getDate()
  696. )
  697. )
  698. _this.currentTime.setMonth(month);
  699. options.onChangeMonth&&options.onChangeMonth.call&&options.onChangeMonth.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
  700. datetimepicker.trigger('xchange.xdsoft');
  701. return month;
  702. };
  703.  
  704. _this.prevMonth = function() {
  705. var month = _this.currentTime.getMonth()-1;
  706. if( month==-1 ) {
  707. _this.currentTime.setFullYear(_this.currentTime.getFullYear()-1);
  708. month = 11;
  709. }
  710. _this.currentTime.setDate(
  711. Math.min(
  712. Date.daysInMonth[month],
  713. _this.currentTime.getDate()
  714. )
  715. )
  716. _this.currentTime.setMonth(month);
  717. options.onChangeMonth&&options.onChangeMonth.call&&options.onChangeMonth.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
  718. datetimepicker.trigger('xchange.xdsoft');
  719. return month;
  720. };
  721.  
  722. _this.strToDateTime = function( sDateTime ) {
  723. var tmpDate = [],timeOffset,currentTime;
  724.  
  725. if( ( tmpDate = /^(\+|\-)(.*)$/.exec(sDateTime) ) && ( tmpDate[2]=Date.parseDate(tmpDate[2], options.formatDate) ) ) {
  726. timeOffset = tmpDate[2].getTime()-1*(tmpDate[2].getTimezoneOffset())*60000;
  727. currentTime = new Date((_xdsoft_datetime.now()).getTime()+parseInt(tmpDate[1]+'1')*timeOffset);
  728. }else
  729. currentTime = sDateTime?Date.parseDate(sDateTime, options.format):_this.now();
  730.  
  731. if( !_this.isValidDate(currentTime) )
  732. currentTime = _this.now();
  733.  
  734. return currentTime;
  735. };
  736.  
  737. _this.strtodate = function( sDate ) {
  738. var currentTime = sDate?Date.parseDate(sDate, options.formatDate):_this.now();
  739. if( !_this.isValidDate(currentTime) )
  740. currentTime = _this.now();
  741. return currentTime;
  742. };
  743.  
  744. _this.strtotime = function( sTime ) {
  745. var currentTime = sTime?Date.parseDate(sTime, options.formatTime):_this.now();
  746. if( !_this.isValidDate(currentTime) )
  747. currentTime = _this.now();
  748. return currentTime;
  749. };
  750.  
  751. _this.str = function() {
  752. return _this.currentTime.dateFormat(options.format);
  753. };
  754. };
  755. mounth_picker
  756. .find('.xdsoft_today_button')
  757. .on('mousedown.xdsoft',function() {
  758. datetimepicker.data('changed',true);
  759. _xdsoft_datetime.setCurrentTime(0);
  760. datetimepicker.trigger('afterOpen.xdsoft');
  761. }).on('dblclick.xdsoft',function(){
  762. input.val( _xdsoft_datetime.str() );
  763. datetimepicker.trigger('close.xdsoft');
  764. });
  765. mounth_picker
  766. .find('.xdsoft_prev,.xdsoft_next')
  767. .on('mousedown.xdsoft',function() {
  768. var $this = $(this),
  769. timer = 0,
  770. stop = false;
  771.  
  772. (function arguments_callee1(v) {
  773. var month = _xdsoft_datetime.currentTime.getMonth();
  774. if( $this.hasClass( options.next ) ) {
  775. _xdsoft_datetime.nextMonth();
  776. }else if( $this.hasClass( options.prev ) ) {
  777. _xdsoft_datetime.prevMonth();
  778. }
  779. !stop&&(timer = setTimeout(arguments_callee1,v?v:100));
  780. })(500);
  781.  
  782. $([document.body,window]).on('mouseup.xdsoft',function arguments_callee2() {
  783. clearTimeout(timer);
  784. stop = true;
  785. $([document.body,window]).off('mouseup.xdsoft',arguments_callee2);
  786. });
  787. });
  788.  
  789. timepicker
  790. .find('.xdsoft_prev,.xdsoft_next')
  791. .on('mousedown.xdsoft',function() {
  792. var $this = $(this),
  793. timer = 0,
  794. stop = false,
  795. period = 110;
  796. (function arguments_callee4(v) {
  797. var pheight = timeboxparent[0].clientHeight,
  798. height = timebox[0].offsetHeight,
  799. top = Math.abs(parseInt(timebox.css('marginTop')));
  800. if( $this.hasClass(options.next) && (height-pheight)- options.timeHeightInTimePicker>=top ) {
  801. timebox.css('marginTop','-'+(top+options.timeHeightInTimePicker)+'px')
  802. }else if( $this.hasClass(options.prev) && top-options.timeHeightInTimePicker>=0 ) {
  803. timebox.css('marginTop','-'+(top-options.timeHeightInTimePicker)+'px')
  804. }
  805. timeboxparent.trigger('scroll_element.xdsoft_scroller',[Math.abs(parseInt(timebox.css('marginTop'))/(height-pheight))]);
  806. period= ( period>10 )?10:period-10;
  807. !stop&&(timer = setTimeout(arguments_callee4,v?v:period));
  808. })(500);
  809. $([document.body,window]).on('mouseup.xdsoft',function arguments_callee5() {
  810. clearTimeout(timer);
  811. stop = true;
  812. $([document.body,window])
  813. .off('mouseup.xdsoft',arguments_callee5);
  814. });
  815. });
  816.  
  817. // base handler - generating a calendar and timepicker
  818. datetimepicker
  819. .on('xchange.xdsoft',function( event ) {
  820. var table = '',
  821. start = new Date(_xdsoft_datetime.currentTime.getFullYear(),_xdsoft_datetime.currentTime.getMonth(),1, 12, 0, 0),
  822. i = 0,
  823. today = _xdsoft_datetime.now();
  824.  
  825. while( start.getDay()!=options.dayOfWeekStart )
  826. start.setDate(start.getDate()-1);
  827.  
  828. //generate calendar
  829. table+='<table><thead><tr>';
  830.  
  831. // days
  832. for(var j = 0; j<7; j++) {
  833. table+='<th>'+options.i18n[options.lang].dayOfWeek[(j+options.dayOfWeekStart)>6?0:j+options.dayOfWeekStart]+'</th>';
  834. }
  835.  
  836. table+='</tr></thead>';
  837. table+='<tbody><tr>';
  838. var maxDate = false, minDate = false;
  839.  
  840. if( options.maxDate!==false ) {
  841. maxDate = _xdsoft_datetime.strtodate(options.maxDate);
  842. maxDate = new Date(maxDate.getFullYear(),maxDate.getMonth(),maxDate.getDate(),23,59,59,999);
  843. }
  844.  
  845. if( options.minDate!==false ) {
  846. minDate = _xdsoft_datetime.strtodate(options.minDate);
  847. minDate = new Date(minDate.getFullYear(),minDate.getMonth(),minDate.getDate());
  848. }
  849.  
  850. var d,y,m,classes = [];
  851.  
  852. while( i<_xdsoft_datetime.currentTime.getDaysInMonth()||start.getDay()!=options.dayOfWeekStart||_xdsoft_datetime.currentTime.getMonth()==start.getMonth() ) {
  853. classes = [];
  854. i++;
  855.  
  856. d = start.getDate(); y = start.getFullYear(); m = start.getMonth();
  857.  
  858. classes.push('xdsoft_date');
  859.  
  860. if( ( maxDate!==false && start > maxDate )||( minDate!==false && start < minDate ) ){
  861. classes.push('xdsoft_disabled');
  862. }
  863.  
  864. if( _xdsoft_datetime.currentTime.getMonth()!=m ) classes.push('xdsoft_other_month');
  865.  
  866. if( (options.defaultSelect||datetimepicker.data('changed')) && _xdsoft_datetime.currentTime.dateFormat('d.m.Y')==start.dateFormat('d.m.Y') ) {
  867. classes.push('xdsoft_current');
  868. }
  869.  
  870. if( today.dateFormat('d.m.Y')==start.dateFormat('d.m.Y') ) {
  871. classes.push('xdsoft_today');
  872. }
  873.  
  874. if( start.getDay()==0||start.getDay()==6||~options.weekends.indexOf(start.dateFormat('d.m.Y')) ) {
  875. classes.push('xdsoft_weekend');
  876. }
  877.  
  878. table+='<td data-date="'+d+'" data-month="'+m+'" data-year="'+y+'"'+' class="xdsoft_date xdsoft_day_of_week'+start.getDay()+' '+ classes.join(' ')+'">'+
  879. '<div>'+d+'</div>'+
  880. '</td>';
  881.  
  882. if( start.getDay()==options.dayOfWeekStartPrev ) {
  883. table+='</tr>';
  884. }
  885.  
  886. start.setDate(d+1);
  887. }
  888. table+='</tbody></table>';
  889.  
  890. calendar.html(table);
  891.  
  892. mounth_picker.find('.xdsoft_label span').eq(0).text(options.i18n[options.lang].months[_xdsoft_datetime.currentTime.getMonth()]);
  893. mounth_picker.find('.xdsoft_label span').eq(1).text(_xdsoft_datetime.currentTime.getFullYear());
  894.  
  895. // generate timebox
  896. var time = '',
  897. h = '',
  898. m ='',
  899. line_time = function line_time( h,m ) {
  900. var now = _xdsoft_datetime.now();
  901. now.setHours(h);
  902. h = parseInt(now.getHours());
  903. now.setMinutes(m);
  904. m = parseInt(now.getMinutes());
  905.  
  906. classes = [];
  907. if( (options.maxTime!==false&&_xdsoft_datetime.strtotime(options.maxTime).getTime()<now.getTime())||(options.minTime!==false&&_xdsoft_datetime.strtotime(options.minTime).getTime()>now.getTime()))
  908. classes.push('xdsoft_disabled');
  909. if( (options.initTime||options.defaultSelect||datetimepicker.data('changed')) && parseInt(_xdsoft_datetime.currentTime.getHours())==parseInt(h)&&(options.step>59||Math[options.roundTime](_xdsoft_datetime.currentTime.getMinutes()/options.step)*options.step==parseInt(m))) {
  910. if( options.defaultSelect||datetimepicker.data('changed')) {
  911. classes.push('xdsoft_current');
  912. } else if( options.initTime ) {
  913. classes.push('xdsoft_init_time');
  914. }
  915. }
  916. if( parseInt(today.getHours())==parseInt(h)&&parseInt(today.getMinutes())==parseInt(m))
  917. classes.push('xdsoft_today');
  918. time+= '<div class="xdsoft_time '+classes.join(' ')+'" data-hour="'+h+'" data-minute="'+m+'">'+now.dateFormat(options.formatTime)+'</div>';
  919. };
  920.  
  921. if( !options.allowTimes || !$.isArray(options.allowTimes) || !options.allowTimes.length ) {
  922. for( var i=0,j=0;i<(options.hours12?12:24);i++ ) {
  923. for( j=0;j<60;j+=options.step ) {
  924. h = (i<10?'0':'')+i;
  925. m = (j<10?'0':'')+j;
  926. line_time( h,m );
  927. }
  928. }
  929. }else{
  930. for( var i=0;i<options.allowTimes.length;i++ ) {
  931. h = _xdsoft_datetime.strtotime(options.allowTimes[i]).getHours();
  932. m = _xdsoft_datetime.strtotime(options.allowTimes[i]).getMinutes();
  933. line_time( h,m );
  934. }
  935. }
  936.  
  937. timebox.html(time);
  938.  
  939. var opt = '',
  940. i = 0;
  941.  
  942. for( i = parseInt(options.yearStart,10)+options.yearOffset;i<= parseInt(options.yearEnd,10)+options.yearOffset;i++ ) {
  943. opt+='<div class="xdsoft_option '+(_xdsoft_datetime.currentTime.getFullYear()==i?'xdsoft_current':'')+'" data-value="'+i+'">'+i+'</div>';
  944. }
  945. yearselect.children().eq(0)
  946. .html(opt);
  947.  
  948. for( i = 0,opt = '';i<= 11;i++ ) {
  949. opt+='<div class="xdsoft_option '+(_xdsoft_datetime.currentTime.getMonth()==i?'xdsoft_current':'')+'" data-value="'+i+'">'+options.i18n[options.lang].months[i]+'</div>';
  950. }
  951. monthselect.children().eq(0).html(opt);
  952. $(this).trigger('generate.xdsoft');
  953. event.stopPropagation();
  954. })
  955. .on('afterOpen.xdsoft',function() {
  956. if( options.timepicker ) {
  957. var classType;
  958. if( timebox.find('.xdsoft_current').length ) {
  959. classType = '.xdsoft_current';
  960. } else if( timebox.find('.xdsoft_init_time').length ) {
  961. classType = '.xdsoft_init_time';
  962. }
  963.  
  964. if( classType ) {
  965. var pheight = timeboxparent[0].clientHeight,
  966. height = timebox[0].offsetHeight,
  967. top = timebox.find(classType).index()*options.timeHeightInTimePicker+1;
  968. if( (height-pheight)<top )
  969. top = height-pheight;
  970. timebox.css('marginTop','-'+parseInt(top)+'px');
  971. timeboxparent.trigger('scroll_element.xdsoft_scroller',[parseInt(top)/(height-pheight)]);
  972. }
  973. }
  974. });
  975.  
  976. var timerclick = 0;
  977. calendar
  978. .on('click.xdsoft', 'td', function (xdevent) {
  979. xdevent.stopPropagation(); // Prevents closing of Pop-ups, Modals and Flyouts in Bootstrap
  980. timerclick++;
  981. var $this = $(this),
  982. currentTime = _xdsoft_datetime.currentTime;
  983. if( $this.hasClass('xdsoft_disabled') )
  984. return false;
  985.  
  986. currentTime.setFullYear( $this.data('year') );
  987. currentTime.setMonth( $this.data('month') );
  988. currentTime.setDate( $this.data('date') );
  989. datetimepicker.trigger('select.xdsoft',[currentTime]);
  990.  
  991. input.val( _xdsoft_datetime.str() );
  992. if( (timerclick>1||(options.closeOnDateSelect===true||( options.closeOnDateSelect===0&&!options.timepicker )))&&!options.inline ) {
  993. datetimepicker.trigger('close.xdsoft');
  994. }
  995.  
  996. if( options.onSelectDate && options.onSelectDate.call ) {
  997. options.onSelectDate.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
  998. }
  999.  
  1000. datetimepicker.data('changed',true);
  1001. datetimepicker.trigger('xchange.xdsoft');
  1002. datetimepicker.trigger('changedatetime.xdsoft');
  1003. setTimeout(function(){
  1004. timerclick = 0;
  1005. },200);
  1006. });
  1007.  
  1008. timebox
  1009. .on('click.xdsoft', 'div', function (xdevent) {
  1010. xdevent.stopPropagation(); // NAJ: Prevents closing of Pop-ups, Modals and Flyouts
  1011. var $this = $(this),
  1012. currentTime = _xdsoft_datetime.currentTime;
  1013. if( $this.hasClass('xdsoft_disabled') )
  1014. return false;
  1015. currentTime.setHours($this.data('hour'));
  1016. currentTime.setMinutes($this.data('minute'));
  1017. datetimepicker.trigger('select.xdsoft',[currentTime]);
  1018.  
  1019. datetimepicker.data('input').val( _xdsoft_datetime.str() );
  1020.  
  1021. !options.inline&&datetimepicker.trigger('close.xdsoft');
  1022.  
  1023. if( options.onSelectTime&&options.onSelectTime.call ) {
  1024. options.onSelectTime.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
  1025. }
  1026. datetimepicker.data('changed',true);
  1027. datetimepicker.trigger('xchange.xdsoft');
  1028. datetimepicker.trigger('changedatetime.xdsoft');
  1029. });
  1030.  
  1031. datetimepicker.mousewheel&&datepicker.mousewheel(function(event, delta, deltaX, deltaY) {
  1032. if( !options.scrollMonth )
  1033. return true;
  1034. if( delta<0 )
  1035. _xdsoft_datetime.nextMonth();
  1036. else
  1037. _xdsoft_datetime.prevMonth();
  1038. return false;
  1039. });
  1040.  
  1041. datetimepicker.mousewheel&&timeboxparent.unmousewheel().mousewheel(function(event, delta, deltaX, deltaY) {
  1042. if( !options.scrollTime )
  1043. return true;
  1044. var pheight = timeboxparent[0].clientHeight,
  1045. height = timebox[0].offsetHeight,
  1046. top = Math.abs(parseInt(timebox.css('marginTop'))),
  1047. fl = true;
  1048. if( delta<0 && (height-pheight)-options.timeHeightInTimePicker>=top ) {
  1049. timebox.css('marginTop','-'+(top+options.timeHeightInTimePicker)+'px');
  1050. fl = false;
  1051. }else if( delta>0&&top-options.timeHeightInTimePicker>=0 ) {
  1052. timebox.css('marginTop','-'+(top-options.timeHeightInTimePicker)+'px');
  1053. fl = false;
  1054. }
  1055. timeboxparent.trigger('scroll_element.xdsoft_scroller',[Math.abs(parseInt(timebox.css('marginTop'))/(height-pheight))]);
  1056. event.stopPropagation();
  1057. return fl;
  1058. });
  1059.  
  1060. datetimepicker
  1061. .on('changedatetime.xdsoft',function() {
  1062. if( options.onChangeDateTime&&options.onChangeDateTime.call ) {
  1063. var $input = datetimepicker.data('input');
  1064. options.onChangeDateTime.call(datetimepicker, _xdsoft_datetime.currentTime, $input);
  1065. $input.trigger('change');
  1066. }
  1067. })
  1068. .on('generate.xdsoft',function() {
  1069. if( options.onGenerate&&options.onGenerate.call )
  1070. options.onGenerate.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
  1071. });
  1072.  
  1073. var current_time_index = 0;
  1074. input.mousewheel&&input.mousewheel(function( event, delta, deltaX, deltaY ) {
  1075. if( !options.scrollInput )
  1076. return true;
  1077. if( !options.datepicker && options.timepicker ) {
  1078. current_time_index = timebox.find('.xdsoft_current').length?timebox.find('.xdsoft_current').eq(0).index():0;
  1079. if( current_time_index+delta>=0&&current_time_index+delta<timebox.children().length )
  1080. current_time_index+=delta;
  1081. timebox.children().eq(current_time_index).length&&timebox.children().eq(current_time_index).trigger('mousedown');
  1082. return false;
  1083. }else if( options.datepicker && !options.timepicker ) {
  1084. datepicker.trigger( event, [delta, deltaX, deltaY]);
  1085. input.val&&input.val( _xdsoft_datetime.str() );
  1086. datetimepicker.trigger('changedatetime.xdsoft');
  1087. return false;
  1088. }
  1089. });
  1090. var setPos = function() {
  1091. var offset = datetimepicker.data('input').offset(), top = offset.top+datetimepicker.data('input')[0].offsetHeight-1, left = offset.left;
  1092. if( top+datetimepicker[0].offsetHeight>$(window).height()+$(window).scrollTop() )
  1093. top = offset.top-datetimepicker[0].offsetHeight+1;
  1094. if (top < 0)
  1095. top = 0;
  1096. if( left+datetimepicker[0].offsetWidth>$(window).width() )
  1097. left = offset.left-datetimepicker[0].offsetWidth+datetimepicker.data('input')[0].offsetWidth;
  1098. datetimepicker.css({
  1099. left:left,
  1100. top:top
  1101. });
  1102. };
  1103. datetimepicker
  1104. .on('open.xdsoft', function() {
  1105. var onShow = true;
  1106. if( options.onShow&&options.onShow.call) {
  1107. onShow = options.onShow.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
  1108. }
  1109. if( onShow!==false ) {
  1110. datetimepicker.show();
  1111. datetimepicker.trigger('afterOpen.xdsoft');
  1112. setPos();
  1113. $(window)
  1114. .off('resize.xdsoft',setPos)
  1115. .on('resize.xdsoft',setPos);
  1116.  
  1117. if( options.closeOnWithoutClick ) {
  1118. $([document.body,window]).on('mousedown.xdsoft',function arguments_callee6() {
  1119. datetimepicker.trigger('close.xdsoft');
  1120. $([document.body,window]).off('mousedown.xdsoft',arguments_callee6);
  1121. });
  1122. }
  1123. }
  1124. })
  1125. .on('close.xdsoft', function( event ) {
  1126. var onClose = true;
  1127. if( options.onClose&&options.onClose.call ) {
  1128. onClose=options.onClose.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
  1129. }
  1130. if( onClose!==false&&!options.opened&&!options.inline ) {
  1131. datetimepicker.hide();
  1132. }
  1133. event.stopPropagation();
  1134. })
  1135. .data('input',input);
  1136.  
  1137. var timer = 0,
  1138. timer1 = 0;
  1139.  
  1140. datetimepicker.data('xdsoft_datetime',_xdsoft_datetime);
  1141. datetimepicker.setOptions(options);
  1142.  
  1143. function getCurrentValue(){
  1144. var ct = options.value?options.value:(input&&input.val&&input.val())?input.val():'';
  1145.  
  1146. if( ct && _xdsoft_datetime.isValidDate(ct = Date.parseDate(ct, options.format)) ) {
  1147. datetimepicker.data('changed',true);
  1148. }else
  1149. ct = '';
  1150.  
  1151. if( !ct && options.startDate!==false ){
  1152. ct = _xdsoft_datetime.strToDateTime(options.startDate);
  1153. }
  1154.  
  1155. return ct?ct:0;
  1156. }
  1157.  
  1158. _xdsoft_datetime.setCurrentTime( getCurrentValue() );
  1159.  
  1160. datetimepicker.trigger('afterOpen.xdsoft');
  1161.  
  1162. input
  1163. .data( 'xdsoft_datetimepicker',datetimepicker )
  1164. .on('open.xdsoft focusin.xdsoft mousedown.xdsoft',function(event) {
  1165. if( input.is(':disabled')||input.is(':hidden')||!input.is(':visible') )
  1166. return;
  1167. clearTimeout(timer);
  1168. timer = setTimeout(function() {
  1169. if( input.is(':disabled')||input.is(':hidden')||!input.is(':visible') )
  1170. return;
  1171. _xdsoft_datetime.setCurrentTime(getCurrentValue());
  1172.  
  1173. datetimepicker.trigger('open.xdsoft');
  1174. },100);
  1175. })
  1176. .on('keydown.xdsoft',function( event ) {
  1177. var val = this.value,
  1178. key = event.which;
  1179. switch(true) {
  1180. case !!~([ENTER].indexOf(key)):
  1181. var elementSelector = $("input:visible,textarea:visible");
  1182. datetimepicker.trigger('close.xdsoft');
  1183. elementSelector.eq(elementSelector.index(this) + 1).focus();
  1184. return false;
  1185. case !!~[TAB].indexOf(key):
  1186. datetimepicker.trigger('close.xdsoft');
  1187. return true;
  1188. }
  1189. });
  1190. },
  1191. destroyDateTimePicker = function( input ) {
  1192. var datetimepicker = input.data('xdsoft_datetimepicker');
  1193. if( datetimepicker ) {
  1194. datetimepicker.data('xdsoft_datetime',null);
  1195. datetimepicker.remove();
  1196. input
  1197. .data( 'xdsoft_datetimepicker',null )
  1198. .off( 'open.xdsoft focusin.xdsoft focusout.xdsoft mousedown.xdsoft blur.xdsoft keydown.xdsoft' );
  1199. $(window).off('resize.xdsoft');
  1200. $([window,document.body]).off('mousedown.xdsoft');
  1201. input.unmousewheel&&input.unmousewheel();
  1202. }
  1203. };
  1204. $(document)
  1205. .off('keydown.xdsoftctrl keyup.xdsoftctrl')
  1206. .on('keydown.xdsoftctrl',function(e) {
  1207. if ( e.keyCode == CTRLKEY )
  1208. ctrlDown = true;
  1209. })
  1210. .on('keyup.xdsoftctrl',function(e) {
  1211. if ( e.keyCode == CTRLKEY )
  1212. ctrlDown = false;
  1213. });
  1214. return this.each(function() {
  1215. var datetimepicker;
  1216. if( datetimepicker = $(this).data('xdsoft_datetimepicker') ) {
  1217. if( $.type(opt) === 'string' ) {
  1218. switch(opt) {
  1219. case 'show':
  1220. $(this).select().focus();
  1221. datetimepicker.trigger( 'open.xdsoft' );
  1222. break;
  1223. case 'hide':
  1224. datetimepicker.trigger('close.xdsoft');
  1225. break;
  1226. case 'destroy':
  1227. destroyDateTimePicker($(this));
  1228. break;
  1229. case 'reset':
  1230. this.value = this.defaultValue;
  1231. if(!this.value || !datetimepicker.data('xdsoft_datetime').isValidDate(Date.parseDate(this.value, options.format)))
  1232. datetimepicker.data('changed',false);
  1233. datetimepicker.data('xdsoft_datetime').setCurrentTime(this.value);
  1234. break;
  1235. }
  1236. }else{
  1237. datetimepicker
  1238. .setOptions(opt);
  1239. }
  1240. return 0;
  1241. }else
  1242. if( ($.type(opt) !== 'string') ){
  1243. if( !options.lazyInit||options.open||options.inline ){
  1244. createDateTimePicker($(this));
  1245. }else
  1246. lazyInit($(this));
  1247. }
  1248. });
  1249. };
  1250. })( jQuery );
  1251.  
  1252. //http://www.xaprb.com/blog/2005/12/12/javascript-closures-for-runtime-efficiency/
  1253. /*
  1254. * Copyright (C) 2004 Baron Schwartz <baron at sequent dot org>
  1255. *
  1256. * This program is free software; you can redistribute it and/or modify it
  1257. * under the terms of the GNU Lesser General Public License as published by the
  1258. * Free Software Foundation, version 2.1.
  1259. *
  1260. * This program is distributed in the hope that it will be useful, but WITHOUT
  1261. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1262. * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  1263. * details.
  1264. */
  1265. Date.parseFunctions={count:0};Date.parseRegexes=[];Date.formatFunctions={count:0};Date.prototype.dateFormat=function(format){if(format=='unixtime')return parseInt(this.getTime()/1000);if(Date.formatFunctions[format]==null){Date.createNewFormat(format)}var func=Date.formatFunctions[format];return this[func]()};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<format.length;++i){ch=format.charAt(i);if(!special&&ch=="\\"){special=true}else if(special){special=false;code+="'"+String.escape(ch)+"' + "}else{code+=Date.getFormatCode(ch)}}eval(code.substring(0,code.length-3)+";}")};Date.getFormatCode=function(character){switch(character){case"d":return"String.leftPad(this.getDate(), 2, '0') + ";case"D":return"Date.dayNames[this.getDay()].substring(0, 3) + ";case"j":return"this.getDate() + ";case"l":return"Date.dayNames[this.getDay()] + ";case"S":return"this.getSuffix() + ";case"w":return"this.getDay() + ";case"z":return"this.getDayOfYear() + ";case"W":return"this.getWeekOfYear() + ";case"F":return"Date.monthNames[this.getMonth()] + ";case"m":return"String.leftPad(this.getMonth() + 1, 2, '0') + ";case"M":return"Date.monthNames[this.getMonth()].substring(0, 3) + ";case"n":return"(this.getMonth() + 1) + ";case"t":return"this.getDaysInMonth() + ";case"L":return"(this.isLeapYear() ? 1 : 0) + ";case"Y":return"this.getFullYear() + ";case"y":return"('' + this.getFullYear()).substring(2, 4) + ";case"a":return"(this.getHours() < 12 ? 'am' : 'pm') + ";case"A":return"(this.getHours() < 12 ? 'AM' : 'PM') + ";case"g":return"((this.getHours() %12) ? this.getHours() % 12 : 12) + ";case"G":return"this.getHours() + ";case"h":return"String.leftPad((this.getHours() %12) ? this.getHours() % 12 : 12, 2, '0') + ";case"H":return"String.leftPad(this.getHours(), 2, '0') + ";case"i":return"String.leftPad(this.getMinutes(), 2, '0') + ";case"s":return"String.leftPad(this.getSeconds(), 2, '0') + ";case"O":return"this.getGMTOffset() + ";case"T":return"this.getTimezone() + ";case"Z":return"(this.getTimezoneOffset() * -60) + ";default:return"'"+String.escape(character)+"' + "}};Date.parseDate=function(input,format){if(format=='unixtime')return new Date(!isNaN(parseInt(input))?parseInt(input)*1000:0);if(Date.parseFunctions[format]==null){Date.createParser(format)}var func=Date.parseFunctions[format];return Date[func](input)};Date.createParser=function(format){var funcName="parse"+Date.parseFunctions.count++;var regexNum=Date.parseRegexes.length;var currentGroup=1;Date.parseFunctions[format]=funcName;var code="Date."+funcName+" = function(input) {\n"+"var y = -1, m = -1, d = -1, h = -1, i = -1, s = -1;\n"+"var d = new Date();\n"+"y = d.getFullYear();\n"+"m = d.getMonth();\n"+"d = d.getDate();\n"+"var results = input.match(Date.parseRegexes["+regexNum+"]);\n"+"if (results && results.length > 0) {";var regex="";var special=false;var ch='';for(var i=0;i<format.length;++i){ch=format.charAt(i);if(!special&&ch=="\\"){special=true}else if(special){special=false;regex+=String.escape(ch)}else{obj=Date.formatCodeToRegex(ch,currentGroup);currentGroup+=obj.g;regex+=obj.s;if(obj.g&&obj.c){code+=obj.c}}}code+="if (y > 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0)\n"+"{return new Date(y, m, d, h, i, s);}\n"+"else if (y > 0 && m >= 0 && d > 0 && h >= 0 && i >= 0)\n"+"{return new Date(y, m, d, h, i);}\n"+"else if (y > 0 && m >= 0 && d > 0 && h >= 0)\n"+"{return new Date(y, m, d, h);}\n"+"else if (y > 0 && m >= 0 && d > 0)\n"+"{return new Date(y, m, d);}\n"+"else if (y > 0 && m >= 0)\n"+"{return new Date(y, m);}\n"+"else if (y > 0)\n"+"{return new Date(y);}\n"+"}return null;}";Date.parseRegexes[regexNum]=new RegExp("^"+regex+"$");eval(code)};Date.formatCodeToRegex=function(character,currentGroup){switch(character){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["+currentGroup+"], 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:0,c:null,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["+currentGroup+"].substring(0, 3)], 10);\n",s:"("+Date.monthNames.join("|")+")"};case"M":return{g:1,c:"m = parseInt(Date.monthNumbers[results["+currentGroup+"]], 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["+currentGroup+"], 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["+currentGroup+"], 10);\n",s:"(\\d{4})"};case"y":return{g:1,c:"var ty = parseInt(results["+currentGroup+"], 10);\n"+"y = ty > Date.y2kYear ? 1900 + ty : 2000 + ty;\n",s:"(\\d{1,2})"};case"a":return{g:1,c:"if (results["+currentGroup+"] == 'am') {\n"+"if (h == 12) { h = 0; }\n"+"} else { if (h < 12) { h += 12; }}",s:"(am|pm)"};case"A":return{g:1,c:"if (results["+currentGroup+"] == 'AM') {\n"+"if (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["+currentGroup+"], 10);\n",s:"(\\d{1,2})"};case"i":return{g:1,c:"i = parseInt(results["+currentGroup+"], 10);\n",s:"(\\d{2})"};case"s":return{g:1,c:"s = parseInt(results["+currentGroup+"], 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(character)}}};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 num=0;Date.daysInMonth[1]=this.isLeapYear()?29:28;for(var i=0;i<this.getMonth();++i){num+=Date.daysInMonth[i]}return num+this.getDate()-1};Date.prototype.getWeekOfYear=function(){var now=this.getDayOfYear()+(4-this.getDay());var jan1=new Date(this.getFullYear(),0,1);var then=(7-jan1.getDay()+4);document.write(then);return String.leftPad(((now-then)/7)+1,2,"0")};Date.prototype.isLeapYear=function(){var year=this.getFullYear();return((year&3)==0&&(year%100||(year%400==0&&year)))};Date.prototype.getFirstDayOfMonth=function(){var day=(this.getDay()-(this.getDate()-1))%7;return(day<0)?(day+7):day};Date.prototype.getLastDayOfMonth=function(){var day=(this.getDay()+(Date.daysInMonth[this.getMonth()]-this.getDate()))%7;return(day<0)?(day+7):day};Date.prototype.getDaysInMonth=function(){Date.daysInMonth[1]=this.isLeapYear()?29:28;return Date.daysInMonth[this.getMonth()]};Date.prototype.getSuffix=function(){switch(this.getDate()){case 1:case 21:case 31:return"st";case 2:case 22:return"nd";case 3:case 23:return"rd";default:return"th"}};String.escape=function(string){return string.replace(/('|\\)/g,"\\$1")};String.leftPad=function(val,size,ch){var result=new String(val);if(ch==null){ch=" "}while(result.length<size){result=ch+result}return result};Date.daysInMonth=[31,28,31,30,31,30,31,31,30,31,30,31];Date.monthNames=["January","February","March","April","May","June","July","August","September","October","November","December"];Date.dayNames=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];Date.y2kYear=50;Date.monthNumbers={Jan:0,Feb:1,Mar:2,Apr:3,May:4,Jun:5,Jul:6,Aug:7,Sep:8,Oct:9,Nov:10,Dec:11};Date.patterns={ISO8601LongPattern:"Y-m-d H:i:s",ISO8601ShortPattern:"Y-m-d",ShortDatePattern:"n/j/Y",LongDatePattern:"l, F d, Y",FullDateTimePattern:"l, F d, Y g:i:s A",MonthDayPattern:"F d",ShortTimePattern:"g:i A",LongTimePattern:"g:i:s A",SortableDateTimePattern:"Y-m-d\\TH:i:s",UniversalSortableDateTimePattern:"Y-m-d H:i:sO",YearMonthPattern:"F, Y"};
  1266. //https://github.com/brandonaaron/jquery-mousewheel/blob/master/jquery.mousewheel.js
  1267. /*
  1268. * Copyright (c) 2013 Brandon Aaron (http://brandonaaron.net)
  1269. *
  1270. * Licensed under the MIT License (LICENSE.txt).
  1271. *
  1272. * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
  1273. * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
  1274. * Thanks to: Seamus Leahy for adding deltaX and deltaY
  1275. *
  1276. * Version: 3.1.3
  1277. *
  1278. * Requires: 1.2.2+
  1279. */
  1280. (function(factory) {if(typeof define==='function'&&define.amd) {define(['jquery'],factory)}else if(typeof exports==='object') {module.exports=factory}else{factory(jQuery)}}(function($) {var toFix=['wheel','mousewheel','DOMMouseScroll','MozMousePixelScroll'];var toBind='onwheel'in document||document.documentMode>=9?['wheel']:['mousewheel','DomMouseScroll','MozMousePixelScroll'];var lowestDelta,lowestDeltaXY;if($.event.fixHooks) {for(var i=toFix.length;i;) {$.event.fixHooks[toFix[--i]]=$.event.mouseHooks}}$.event.special.mousewheel={setup:function() {if(this.addEventListener) {for(var i=toBind.length;i;) {this.addEventListener(toBind[--i],handler,false)}}else{this.onmousewheel=handler}},teardown:function() {if(this.removeEventListener) {for(var i=toBind.length;i;) {this.removeEventListener(toBind[--i],handler,false)}}else{this.onmousewheel=null}}};$.fn.extend({mousewheel:function(fn) {return fn?this.bind("mousewheel",fn):this.trigger("mousewheel")},unmousewheel:function(fn) {return this.unbind("mousewheel",fn)}});function handler(event) {var orgEvent=event||window.event,args=[].slice.call(arguments,1),delta=0,deltaX=0,deltaY=0,absDelta=0,absDeltaXY=0,fn;event=$.event.fix(orgEvent);event.type="mousewheel";if(orgEvent.wheelDelta) {delta=orgEvent.wheelDelta}if(orgEvent.detail) {delta=orgEvent.detail*-1}if(orgEvent.deltaY) {deltaY=orgEvent.deltaY*-1;delta=deltaY}if(orgEvent.deltaX) {deltaX=orgEvent.deltaX;delta=deltaX*-1}if(orgEvent.wheelDeltaY!==undefined) {deltaY=orgEvent.wheelDeltaY}if(orgEvent.wheelDeltaX!==undefined) {deltaX=orgEvent.wheelDeltaX*-1}absDelta=Math.abs(delta);if(!lowestDelta||absDelta<lowestDelta) {lowestDelta=absDelta}absDeltaXY=Math.max(Math.abs(deltaY),Math.abs(deltaX));if(!lowestDeltaXY||absDeltaXY<lowestDeltaXY) {lowestDeltaXY=absDeltaXY}fn=delta>0?'floor':'ceil';delta=Math[fn](delta/lowestDelta);deltaX=Math[fn](deltaX/lowestDeltaXY);deltaY=Math[fn](deltaY/lowestDeltaXY);args.unshift(event,delta,deltaX,deltaY);return($.event.dispatch||$.event.handle).apply(this,args)}}));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement