jquery.datetimepicker.js 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146
  1. /**
  2. * @preserve jQuery DateTimePicker plugin v2.1.9
  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. },
  123. value:'',
  124. lang:'ch',
  125. format:'Y-m-d H:i',
  126. formatTime:'H:i',
  127. formatDate:'Y-m-d',
  128. step:60,
  129. closeOnDateSelect:0,
  130. closeOnWithoutClick:true,
  131. timepicker:true,
  132. datepicker:true,
  133. minDate:false,
  134. maxDate:false,
  135. minTime:false,
  136. maxTime:false,
  137. allowTimes:[],
  138. opened:false,
  139. inline:false,
  140. onSelectDate:function() {},
  141. onSelectTime:function() {},
  142. onChangeMonth:function() {},
  143. onChangeDateTime:function() {},
  144. onShow:function() {},
  145. onClose:function() {},
  146. onGenerate:function() {},
  147. withoutCopyright:true,
  148. inverseButton:false,
  149. hours12:false,
  150. next: 'xdsoft_next',
  151. prev : 'xdsoft_prev',
  152. dayOfWeekStart:0,
  153. timeHeightInTimePicker:25,
  154. timepickerScrollbar:true,
  155. todayButton:true, // 2.1.0
  156. defaultSelect:true, // 2.1.0
  157. scrollMonth:true,
  158. scrollTime:true,
  159. scrollInput:true,
  160. mask:false,
  161. validateOnBlur:true,
  162. allowBlank:false,
  163. yearStart:1950,
  164. yearEnd:2050,
  165. style:'',
  166. id:'',
  167. roundTime:'round', // ceil, floor
  168. className:'',
  169. weekends : [],
  170. yearOffset:0
  171. };
  172. // fix for ie8
  173. if ( !Array.prototype.indexOf ) {
  174. Array.prototype.indexOf = function(obj, start) {
  175. for (var i = (start || 0), j = this.length; i < j; i++) {
  176. if (this[i] === obj) { return i; }
  177. }
  178. return -1;
  179. }
  180. };
  181. $.fn.xdsoftScroller = function( _percent ) {
  182. return this.each(function() {
  183. var timeboxparent = $(this);
  184. if( !$(this).hasClass('xdsoft_scroller_box') ) {
  185. var pointerEventToXY = function( e ) {
  186. var out = {x:0, y:0};
  187. if( e.type == 'touchstart' || e.type == 'touchmove' || e.type == 'touchend' || e.type == 'touchcancel' ) {
  188. var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
  189. out.x = touch.pageX;
  190. out.y = touch.pageY;
  191. }else if (e.type == 'mousedown' || e.type == 'mouseup' || e.type == 'mousemove' || e.type == 'mouseover'|| e.type=='mouseout' || e.type=='mouseenter' || e.type=='mouseleave') {
  192. out.x = e.pageX;
  193. out.y = e.pageY;
  194. }
  195. return out;
  196. },
  197. move = 0,
  198. timebox = timeboxparent.children().eq(0),
  199. parentHeight = timeboxparent[0].clientHeight,
  200. height = timebox[0].offsetHeight,
  201. scrollbar = $('<div class="xdsoft_scrollbar"></div>'),
  202. scroller = $('<div class="xdsoft_scroller"></div>'),
  203. maximumOffset = 100,
  204. start = false;
  205. scrollbar.append(scroller);
  206. timeboxparent.addClass('xdsoft_scroller_box').append(scrollbar);
  207. scroller.on('mousedown.xdsoft_scroller',function ( event ) {
  208. if( !parentHeight )
  209. timeboxparent.trigger('resize_scroll.xdsoft_scroller',[_percent]);
  210. var pageY = event.pageY,
  211. top = parseInt(scroller.css('margin-top')),
  212. h1 = scrollbar[0].offsetHeight;
  213. $(document.body).addClass('xdsoft_noselect');
  214. $([document.body,window]).on('mouseup.xdsoft_scroller',function arguments_callee() {
  215. $([document.body,window]).off('mouseup.xdsoft_scroller',arguments_callee)
  216. .off('mousemove.xdsoft_scroller',move)
  217. .removeClass('xdsoft_noselect');
  218. });
  219. $(document.body).on('mousemove.xdsoft_scroller',move = function(event) {
  220. var offset = event.pageY-pageY+top;
  221. if( offset<0 )
  222. offset = 0;
  223. if( offset+scroller[0].offsetHeight>h1 )
  224. offset = h1-scroller[0].offsetHeight;
  225. timeboxparent.trigger('scroll_element.xdsoft_scroller',[maximumOffset?offset/maximumOffset:0]);
  226. });
  227. });
  228. timeboxparent
  229. .on('scroll_element.xdsoft_scroller',function( event,percent ) {
  230. if( !parentHeight )
  231. timeboxparent.trigger('resize_scroll.xdsoft_scroller',[percent,true]);
  232. percent = percent>1?1:(percent<0||isNaN(percent))?0:percent;
  233. scroller.css('margin-top',maximumOffset*percent);
  234. timebox.css('marginTop',-parseInt((height-parentHeight)*percent))
  235. })
  236. .on('resize_scroll.xdsoft_scroller',function( event,_percent,noTriggerScroll ) {
  237. parentHeight = timeboxparent[0].clientHeight;
  238. height = timebox[0].offsetHeight;
  239. var percent = parentHeight/height,
  240. sh = percent*scrollbar[0].offsetHeight;
  241. if( percent>1 )
  242. scroller.hide();
  243. else{
  244. scroller.show();
  245. scroller.css('height',parseInt(sh>10?sh:10));
  246. maximumOffset = scrollbar[0].offsetHeight-scroller[0].offsetHeight;
  247. if( noTriggerScroll!==true )
  248. timeboxparent.trigger('scroll_element.xdsoft_scroller',[_percent?_percent:Math.abs(parseInt(timebox.css('marginTop')))/(height-parentHeight)]);
  249. }
  250. });
  251. timeboxparent.mousewheel&&timeboxparent.mousewheel(function(event, delta, deltaX, deltaY) {
  252. var top = Math.abs(parseInt(timebox.css('marginTop')));
  253. timeboxparent.trigger('scroll_element.xdsoft_scroller',[(top-delta*20)/(height-parentHeight)]);
  254. event.stopPropagation();
  255. return false;
  256. });
  257. timeboxparent.on('touchstart',function( event ) {
  258. start = pointerEventToXY(event);
  259. });
  260. timeboxparent.on('touchmove',function( event ) {
  261. if( start ) {
  262. var coord = pointerEventToXY(event), top = Math.abs(parseInt(timebox.css('marginTop')));
  263. timeboxparent.trigger('scroll_element.xdsoft_scroller',[(top-(coord.y-start.y))/(height-parentHeight)]);
  264. event.stopPropagation();
  265. event.preventDefault();
  266. };
  267. });
  268. timeboxparent.on('touchend touchcancel',function( event ) {
  269. start = false;
  270. });
  271. }
  272. timeboxparent.trigger('resize_scroll.xdsoft_scroller',[_percent]);
  273. });
  274. };
  275. $.fn.datetimepicker = function( opt ) {
  276. var KEY0 = 48,
  277. KEY9 = 57,
  278. _KEY0 = 96,
  279. _KEY9 = 105,
  280. CTRLKEY = 17,
  281. DEL = 46,
  282. ENTER = 13,
  283. ESC = 27,
  284. BACKSPACE = 8,
  285. ARROWLEFT = 37,
  286. ARROWUP = 38,
  287. ARROWRIGHT = 39,
  288. ARROWDOWN = 40,
  289. TAB = 9,
  290. F5 = 116,
  291. AKEY = 65,
  292. CKEY = 67,
  293. VKEY = 86,
  294. ZKEY = 90,
  295. YKEY = 89,
  296. ctrlDown = false,
  297. options = ($.isPlainObject(opt)||!opt)?$.extend(true,{},default_options,opt):$.extend({},default_options),
  298. createDateTimePicker = function( input ) {
  299. var datetimepicker = $('<div '+(options.id?'id="'+options.id+'"':'')+' '+(options.style?'style="'+options.style+'"':'')+' class="xdsoft_datetimepicker xdsoft_noselect '+options.className+'"></div>'),
  300. xdsoft_copyright = $('<div class="xdsoft_copyright"><a target="_blank" href="http://xdsoft.net/jqplugins/datetimepicker/">xdsoft.net</a></div>'),
  301. datepicker = $('<div class="xdsoft_datepicker active"></div>'),
  302. 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>'),
  303. calendar = $('<div class="xdsoft_calendar"></div>'),
  304. 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>'),
  305. timeboxparent = timepicker.find('.xdsoft_time_box').eq(0),
  306. timebox = $('<div class="xdsoft_time_variant"></div>'),
  307. scrollbar = $('<div class="xdsoft_scrollbar"></div>'),
  308. scroller = $('<div class="xdsoft_scroller"></div>'),
  309. monthselect =$('<div class="xdsoft_select xdsoft_monthselect"><div></div></div>'),
  310. yearselect =$('<div class="xdsoft_select xdsoft_yearselect"><div></div></div>');
  311. //constructor lego
  312. mounth_picker
  313. .find('.xdsoft_month span')
  314. .after(monthselect);
  315. mounth_picker
  316. .find('.xdsoft_year span')
  317. .after(yearselect);
  318. mounth_picker
  319. .find('.xdsoft_month,.xdsoft_year')
  320. .on('mousedown.xdsoft',function(event) {
  321. mounth_picker
  322. .find('.xdsoft_select')
  323. .hide();
  324. var select = $(this).find('.xdsoft_select').eq(0),
  325. val = 0,
  326. top = 0;
  327. if( _xdsoft_datetime.currentTime )
  328. val = _xdsoft_datetime.currentTime[$(this).hasClass('xdsoft_month')?'getMonth':'getFullYear']();
  329. select.show();
  330. for(var items = select.find('div.xdsoft_option'),i = 0;i<items.length;i++) {
  331. if( items.eq(i).data('value')==val ) {
  332. break;
  333. }else top+=items[0].offsetHeight;
  334. }
  335. select.xdsoftScroller(top/(select.children()[0].offsetHeight-(select[0].clientHeight)));
  336. event.stopPropagation();
  337. return false;
  338. });
  339. mounth_picker
  340. .find('.xdsoft_select')
  341. .xdsoftScroller()
  342. .on('mousedown.xdsoft',function( event ) {
  343. event.stopPropagation();
  344. event.preventDefault();
  345. })
  346. .on('mousedown.xdsoft','.xdsoft_option',function( event ) {
  347. if( _xdsoft_datetime&&_xdsoft_datetime.currentTime )
  348. _xdsoft_datetime.currentTime[$(this).parent().parent().hasClass('xdsoft_monthselect')?'setMonth':'setFullYear']($(this).data('value'));
  349. $(this).parent().parent().hide();
  350. datetimepicker.trigger('xchange.xdsoft');
  351. options.onChangeMonth&&options.onChangeMonth.call&&options.onChangeMonth.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
  352. });
  353. // set options
  354. datetimepicker.setOptions = function( _options ) {
  355. options = $.extend(true,{},options,_options);
  356. if( (options.open||options.opened)&&(!options.inline) ) {
  357. input.trigger('open.xdsoft');
  358. }
  359. if( options.inline ) {
  360. datetimepicker.addClass('xdsoft_inline');
  361. input.after(datetimepicker).hide();
  362. datetimepicker.trigger('afterOpen.xdsoft');
  363. }
  364. if( options.inverseButton ) {
  365. options.next = 'xdsoft_prev';
  366. options.prev = 'xdsoft_next';
  367. }
  368. if( options.datepicker )
  369. datepicker.addClass('active');
  370. else
  371. datepicker.removeClass('active');
  372. if( options.timepicker )
  373. timepicker.addClass('active');
  374. else
  375. timepicker.removeClass('active');
  376. if( options.value ){
  377. input&&input.val&&input.val(options.value);
  378. _xdsoft_datetime.setCurrentTime(options.value);
  379. }
  380. if( isNaN(options.dayOfWeekStart)||parseInt(options.dayOfWeekStart)<0||parseInt(options.dayOfWeekStart)>6 )
  381. options.dayOfWeekStart = 0;
  382. else
  383. options.dayOfWeekStart = parseInt(options.dayOfWeekStart);
  384. if( !options.timepickerScrollbar )
  385. scrollbar.hide();
  386. var tmpDate = [],timeOffset;
  387. if( options.minDate && ( tmpDate = /^-(.*)$/.exec(options.minDate) ) && (tmpDate=Date.parseDate(tmpDate[1], options.formatDate)) ) {
  388. timeOffset = tmpDate.getTime()+-1*(tmpDate.getTimezoneOffset())*60000;
  389. options.minDate = new Date((_xdsoft_datetime.now()).getTime()-timeOffset).dateFormat( options.formatDate );
  390. }
  391. if( options.maxDate && ( tmpDate = /^\+(.*)$/.exec(options.maxDate) ) && (tmpDate=Date.parseDate(tmpDate[1], options.formatDate)) ) {
  392. timeOffset = tmpDate.getTime()+-1*(tmpDate.getTimezoneOffset())*60000;
  393. options.maxDate = new Date((_xdsoft_datetime.now()).getTime()+timeOffset).dateFormat( options.formatDate );
  394. }
  395. mounth_picker
  396. .find('.xdsoft_today_button')
  397. .css('visibility',!options.todayButton?'hidden':'visible');
  398. if( options.mask ) {
  399. var e,
  400. getCaretPos = function ( input ) {
  401. try{
  402. if ( document.selection && document.selection.createRange ) {
  403. var range = document.selection.createRange();
  404. return range.getBookmark().charCodeAt(2) - 2;
  405. }else
  406. if ( input.setSelectionRange )
  407. return input.selectionStart;
  408. }catch(e) {
  409. return 0;
  410. }
  411. },
  412. setCaretPos = function ( node,pos ) {
  413. var node = (typeof node == "string" || node instanceof String) ? document.getElementById(node) : node;
  414. if(!node) {
  415. return false;
  416. }else if(node.createTextRange) {
  417. var textRange = node.createTextRange();
  418. textRange.collapse(true);
  419. textRange.moveEnd(pos);
  420. textRange.moveStart(pos);
  421. textRange.select();
  422. return true;
  423. }else if(node.setSelectionRange) {
  424. node.setSelectionRange(pos,pos);
  425. return true;
  426. }
  427. return false;
  428. },
  429. isValidValue = function ( mask,value ) {
  430. var reg = mask
  431. .replace(/([\[\]\/\{\}\(\)\-\.\+]{1})/g,'\\$1')
  432. .replace(/_/g,'{digit+}')
  433. .replace(/([0-9]{1})/g,'{digit$1}')
  434. .replace(/\{digit([0-9]{1})\}/g,'[0-$1_]{1}')
  435. .replace(/\{digit[\+]\}/g,'[0-9_]{1}');
  436. return RegExp(reg).test(value);
  437. };
  438. input.off('keydown.xdsoft');
  439. switch(true) {
  440. case ( options.mask===true ):
  441. //options.mask = (new Date()).dateFormat( options.format );
  442. //options.mask = options.mask.replace(/[0-9]/g,'_');
  443. options.mask = options.format
  444. .replace(/Y/g,'9999')
  445. .replace(/F/g,'9999')
  446. .replace(/m/g,'19')
  447. .replace(/d/g,'39')
  448. .replace(/H/g,'29')
  449. .replace(/i/g,'59')
  450. .replace(/s/g,'59');
  451. case ( $.type(options.mask) == 'string' ):
  452. if( !isValidValue( options.mask,input.val() ) )
  453. input.val(options.mask.replace(/[0-9]/g,'_'));
  454. input.on('keydown.xdsoft',function( event ) {
  455. var val = this.value,
  456. key = event.which;
  457. switch(true) {
  458. case (( key>=KEY0&&key<=KEY9 )||( key>=_KEY0&&key<=_KEY9 ))||(key==BACKSPACE||key==DEL):
  459. var pos = getCaretPos(this),
  460. digit = ( key!=BACKSPACE&&key!=DEL )?String.fromCharCode((_KEY0 <= key && key <= _KEY9)? key-KEY0 : key):'_';
  461. if( (key==BACKSPACE||key==DEL)&&pos ) {
  462. pos--;
  463. digit='_';
  464. }
  465. while( /[^0-9_]/.test(options.mask.substr(pos,1))&&pos<options.mask.length&&pos>0 )
  466. pos+=( key==BACKSPACE||key==DEL )?-1:1;
  467. val = val.substr(0,pos)+digit+val.substr(pos+1);
  468. if( $.trim(val)=='' )
  469. val = options.mask.replace(/[0-9]/g,'_');
  470. else
  471. if( pos==options.mask.length )
  472. break;
  473. pos+=(key==BACKSPACE||key==DEL)?0:1;
  474. while( /[^0-9_]/.test(options.mask.substr(pos,1))&&pos<options.mask.length&&pos>0 )
  475. pos+=(key==BACKSPACE||key==DEL)?-1:1;
  476. if( isValidValue( options.mask,val ) ) {
  477. this.value = val;
  478. setCaretPos(this,pos);
  479. }else if( $.trim(val)=='' )
  480. this.value = options.mask.replace(/[0-9]/g,'_');
  481. else{
  482. input.trigger('error_input.xdsoft');
  483. }
  484. break;
  485. case ( !!~([AKEY,CKEY,VKEY,ZKEY,YKEY].indexOf(key))&&ctrlDown ):
  486. case !!~([ESC,ARROWUP,ARROWDOWN,ARROWLEFT,ARROWRIGHT,F5,CTRLKEY,TAB,ENTER].indexOf(key)):
  487. return true;
  488. }
  489. event.preventDefault();
  490. return false;
  491. });
  492. break;
  493. }
  494. }
  495. if( options.validateOnBlur ) {
  496. input
  497. .off('blur.xdsoft')
  498. .on('blur.xdsoft', function() {
  499. if( options.allowBlank && !$.trim($(this).val()).length ) {
  500. $(this).val(null);
  501. datetimepicker.data('xdsoft_datetime').empty();
  502. }else if( !Date.parseDate( $(this).val(), options.format ) ) {
  503. $(this).val((_xdsoft_datetime.now()).dateFormat( options.format ));
  504. datetimepicker.data('xdsoft_datetime').setCurrentTime($(this).val());
  505. }
  506. else{
  507. datetimepicker.data('xdsoft_datetime').setCurrentTime($(this).val());
  508. }
  509. datetimepicker.trigger('changedatetime.xdsoft');
  510. });
  511. }
  512. options.dayOfWeekStartPrev = (options.dayOfWeekStart==0)?6:options.dayOfWeekStart-1;
  513. datetimepicker
  514. .trigger('xchange.xdsoft');
  515. };
  516. datetimepicker
  517. .data('options',options)
  518. .on('mousedown.xdsoft',function( event ) {
  519. event.stopPropagation();
  520. event.preventDefault();
  521. yearselect.hide();
  522. monthselect.hide();
  523. return false;
  524. });
  525. var scroll_element = timepicker.find('.xdsoft_time_box');
  526. scroll_element.append(timebox);
  527. scroll_element.xdsoftScroller();
  528. datetimepicker.on('afterOpen.xdsoft',function() {
  529. scroll_element.xdsoftScroller();
  530. });
  531. datetimepicker
  532. .append(datepicker)
  533. .append(timepicker);
  534. if( options.withoutCopyright!==true )
  535. datetimepicker
  536. .append(xdsoft_copyright);
  537. datepicker
  538. .append(mounth_picker)
  539. .append(calendar);
  540. $('body').append(datetimepicker);
  541. var _xdsoft_datetime = new function() {
  542. var _this = this;
  543. _this.now = function() {
  544. var d = new Date();
  545. if( options.yearOffset )
  546. d.setFullYear(d.getFullYear()+options.yearOffset);
  547. return d;
  548. };
  549. _this.currentTime = this.now();
  550. _this.isValidDate = function (d) {
  551. if ( Object.prototype.toString.call(d) !== "[object Date]" )
  552. return false;
  553. return !isNaN(d.getTime());
  554. };
  555. _this.setCurrentTime = function( dTime) {
  556. _this.currentTime = (typeof dTime == 'string')? _this.strtodatetime(dTime) : _this.isValidDate(dTime) ? dTime: _this.now();
  557. datetimepicker.trigger('xchange.xdsoft');
  558. };
  559. _this.empty = function() {
  560. _this.currentTime = null;
  561. };
  562. _this.getCurrentTime = function( dTime) {
  563. return _this.currentTime;
  564. };
  565. _this.nextMonth = function() {
  566. var month = _this.currentTime.getMonth()+1;
  567. if( month==12 ) {
  568. _this.currentTime.setFullYear(_this.currentTime.getFullYear()+1);
  569. month = 0;
  570. }
  571. _this.currentTime.setDate(
  572. Math.min(
  573. Date.daysInMonth[month],
  574. _this.currentTime.getDate()
  575. )
  576. )
  577. _this.currentTime.setMonth(month);
  578. options.onChangeMonth&&options.onChangeMonth.call&&options.onChangeMonth.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
  579. datetimepicker.trigger('xchange.xdsoft');
  580. return month;
  581. };
  582. _this.prevMonth = function() {
  583. var month = _this.currentTime.getMonth()-1;
  584. if( month==-1 ) {
  585. _this.currentTime.setFullYear(_this.currentTime.getFullYear()-1);
  586. month = 11;
  587. }
  588. _this.currentTime.setDate(
  589. Math.min(
  590. Date.daysInMonth[month],
  591. _this.currentTime.getDate()
  592. )
  593. )
  594. _this.currentTime.setMonth(month);
  595. options.onChangeMonth&&options.onChangeMonth.call&&options.onChangeMonth.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
  596. datetimepicker.trigger('xchange.xdsoft');
  597. return month;
  598. };
  599. _this.strtodatetime = function( sDateTime ) {
  600. var currentTime = sDateTime?Date.parseDate(sDateTime, options.format):_this.now();
  601. if( !_this.isValidDate(currentTime) )
  602. currentTime = _this.now();
  603. return currentTime;
  604. };
  605. _this.strtodate = function( sDate ) {
  606. var currentTime = sDate?Date.parseDate(sDate, options.formatDate):_this.now();
  607. if( !_this.isValidDate(currentTime) )
  608. currentTime = _this.now();
  609. return currentTime;
  610. };
  611. _this.strtotime = function( sTime ) {
  612. var currentTime = sTime?Date.parseDate(sTime, options.formatTime):_this.now();
  613. if( !_this.isValidDate(currentTime) )
  614. currentTime = _this.now();
  615. return currentTime;
  616. };
  617. _this.str = function() {
  618. return _this.currentTime.dateFormat(options.format);
  619. };
  620. };
  621. mounth_picker
  622. .find('.xdsoft_today_button')
  623. .on('mousedown.xdsoft',function() {
  624. datetimepicker.data('changed',true);
  625. _xdsoft_datetime.setCurrentTime(0);
  626. datetimepicker.trigger('afterOpen.xdsoft');
  627. }).on('dblclick.xdsoft',function(){
  628. input.val( _xdsoft_datetime.str() );
  629. datetimepicker.trigger('close.xdsoft');
  630. });
  631. mounth_picker
  632. .find('.xdsoft_prev,.xdsoft_next')
  633. .on('mousedown.xdsoft',function() {
  634. var $this = $(this),
  635. timer = 0,
  636. stop = false;
  637. (function arguments_callee1(v) {
  638. var month = _xdsoft_datetime.currentTime.getMonth();
  639. if( $this.hasClass( options.next ) ) {
  640. _xdsoft_datetime.nextMonth();
  641. }else if( $this.hasClass( options.prev ) ) {
  642. _xdsoft_datetime.prevMonth();
  643. }
  644. !stop&&(timer = setTimeout(arguments_callee1,v?v:100));
  645. })(500);
  646. $([document.body,window]).on('mouseup.xdsoft',function arguments_callee2() {
  647. clearTimeout(timer);
  648. stop = true;
  649. $([document.body,window]).off('mouseup.xdsoft',arguments_callee2);
  650. });
  651. });
  652. timepicker
  653. .find('.xdsoft_prev,.xdsoft_next')
  654. .on('mousedown.xdsoft',function() {
  655. var $this = $(this),
  656. timer = 0,
  657. stop = false,
  658. period = 110;
  659. (function arguments_callee4(v) {
  660. var pheight = timeboxparent[0].clientHeight,
  661. height = timebox[0].offsetHeight,
  662. top = Math.abs(parseInt(timebox.css('marginTop')));
  663. if( $this.hasClass(options.next) && (height-pheight)- options.timeHeightInTimePicker>=top ) {
  664. timebox.css('marginTop','-'+(top+options.timeHeightInTimePicker)+'px')
  665. }else if( $this.hasClass(options.prev) && top-options.timeHeightInTimePicker>=0 ) {
  666. timebox.css('marginTop','-'+(top-options.timeHeightInTimePicker)+'px')
  667. }
  668. timeboxparent.trigger('scroll_element.xdsoft_scroller',[Math.abs(parseInt(timebox.css('marginTop'))/(height-pheight))]);
  669. period= ( period>10 )?10:period-10;
  670. !stop&&(timer = setTimeout(arguments_callee4,v?v:period));
  671. })(500);
  672. $([document.body,window]).on('mouseup.xdsoft',function arguments_callee5() {
  673. clearTimeout(timer);
  674. stop = true;
  675. $([document.body,window])
  676. .off('mouseup.xdsoft',arguments_callee5);
  677. });
  678. });
  679. // base handler - generating a calendar and timepicker
  680. datetimepicker
  681. .on('xchange.xdsoft',function( event ) {
  682. var table = '',
  683. start = new Date(_xdsoft_datetime.currentTime.getFullYear(),_xdsoft_datetime.currentTime.getMonth(),1, 12, 0, 0),
  684. i = 0,
  685. today = _xdsoft_datetime.now();
  686. while( start.getDay()!=options.dayOfWeekStart )
  687. start.setDate(start.getDate()-1);
  688. //generate calendar
  689. table+='<table><thead><tr>';
  690. // days
  691. for(var j = 0; j<7; j++) {
  692. table+='<th>'+options.i18n[options.lang].dayOfWeek[(j+options.dayOfWeekStart)>6?0:j+options.dayOfWeekStart]+'</th>';
  693. }
  694. table+='</tr></thead>';
  695. table+='<tbody><tr>';
  696. var maxDate = false, minDate = false;
  697. if( options.maxDate!==false ) {
  698. maxDate = _xdsoft_datetime.strtodate(options.maxDate);
  699. maxDate = new Date(maxDate.getFullYear(),maxDate.getMonth(),maxDate.getDate(),23,59,59,999);
  700. }
  701. if( options.minDate!==false ) {
  702. minDate = _xdsoft_datetime.strtodate(options.minDate);
  703. minDate = new Date(minDate.getFullYear(),minDate.getMonth(),minDate.getDate());
  704. }
  705. var d,y,m,classes = [];
  706. while( i<_xdsoft_datetime.currentTime.getDaysInMonth()||start.getDay()!=options.dayOfWeekStart||_xdsoft_datetime.currentTime.getMonth()==start.getMonth() ) {
  707. classes = [];
  708. i++;
  709. d = start.getDate(); y = start.getFullYear(); m = start.getMonth();
  710. classes.push('xdsoft_date');
  711. if( ( maxDate!==false && start > maxDate )||( minDate!==false && start < minDate ) ){
  712. classes.push('xdsoft_disabled');
  713. }
  714. if( _xdsoft_datetime.currentTime.getMonth()!=m ) classes.push('xdsoft_other_month');
  715. if( (options.defaultSelect||datetimepicker.data('changed')) && _xdsoft_datetime.currentTime.dateFormat('d.m.Y')==start.dateFormat('d.m.Y') ) {
  716. classes.push('xdsoft_current');
  717. }
  718. if( today.dateFormat('d.m.Y')==start.dateFormat('d.m.Y') ) {
  719. classes.push('xdsoft_today');
  720. }
  721. if( start.getDay()==0||start.getDay()==6||~options.weekends.indexOf(start.dateFormat('d.m.Y')) ) {
  722. classes.push('xdsoft_weekend');
  723. }
  724. table+='<td data-date="'+d+'" data-month="'+m+'" data-year="'+y+'"'+' class="xdsoft_date xdsoft_day_of_week'+start.getDay()+' '+ classes.join(' ')+'">'+
  725. '<div>'+d+'</div>'+
  726. '</td>';
  727. if( start.getDay()==options.dayOfWeekStartPrev ) {
  728. table+='</tr>';
  729. }
  730. start.setDate(d+1);
  731. }
  732. table+='</tbody></table>';
  733. calendar.html(table);
  734. mounth_picker.find('.xdsoft_label span').eq(0).text(options.i18n[options.lang].months[_xdsoft_datetime.currentTime.getMonth()]);
  735. mounth_picker.find('.xdsoft_label span').eq(1).text(_xdsoft_datetime.currentTime.getFullYear());
  736. // generate timebox
  737. var time = '',
  738. h = '',
  739. m ='',
  740. line_time = function line_time( h,m ) {
  741. var now = _xdsoft_datetime.now();
  742. now.setHours(h);
  743. h = parseInt(now.getHours());
  744. now.setMinutes(m);
  745. m = parseInt(now.getMinutes());
  746. classes = [];
  747. if( (options.maxTime!==false&&_xdsoft_datetime.strtotime(options.maxTime).getTime()<now.getTime())||(options.minTime!==false&&_xdsoft_datetime.strtotime(options.minTime).getTime()>now.getTime()))
  748. classes.push('xdsoft_disabled');
  749. if( (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)))
  750. classes.push('xdsoft_current');
  751. if( parseInt(today.getHours())==parseInt(h)&&parseInt(today.getMinutes())==parseInt(m))
  752. classes.push('xdsoft_today');
  753. time+= '<div class="xdsoft_time '+classes.join(' ')+'" data-hour="'+h+'" data-minute="'+m+'">'+now.dateFormat(options.formatTime)+'</div>';
  754. };
  755. if( !options.allowTimes || !$.isArray(options.allowTimes) || !options.allowTimes.length ) {
  756. for( var i=0,j=0;i<(options.hours12?12:24);i++ ) {
  757. for( j=0;j<60;j+=options.step ) {
  758. h = (i<10?'0':'')+i;
  759. m = (j<10?'0':'')+j;
  760. line_time( h,m );
  761. }
  762. }
  763. }else{
  764. for( var i=0;i<options.allowTimes.length;i++ ) {
  765. h = _xdsoft_datetime.strtotime(options.allowTimes[i]).getHours();
  766. m = _xdsoft_datetime.strtotime(options.allowTimes[i]).getMinutes();
  767. line_time( h,m );
  768. }
  769. }
  770. timebox.html(time);
  771. var opt = '',
  772. i = 0;
  773. for( i = parseInt(options.yearStart,10)+options.yearOffset;i<= parseInt(options.yearEnd,10)+options.yearOffset;i++ ) {
  774. opt+='<div class="xdsoft_option '+(_xdsoft_datetime.currentTime.getFullYear()==i?'xdsoft_current':'')+'" data-value="'+i+'">'+i+'</div>';
  775. }
  776. yearselect.children().eq(0)
  777. .html(opt);
  778. for( i = 0,opt = '';i<= 11;i++ ) {
  779. opt+='<div class="xdsoft_option '+(_xdsoft_datetime.currentTime.getMonth()==i?'xdsoft_current':'')+'" data-value="'+i+'">'+options.i18n[options.lang].months[i]+'</div>';
  780. }
  781. monthselect.children().eq(0).html(opt);
  782. $(this).trigger('generate.xdsoft');
  783. event.stopPropagation();
  784. })
  785. .on('afterOpen.xdsoft',function() {
  786. if( options.timepicker && timebox.find('.xdsoft_current').length ) {
  787. var pheight = timeboxparent[0].clientHeight,
  788. height = timebox[0].offsetHeight,
  789. top = timebox.find('.xdsoft_current').index()*options.timeHeightInTimePicker+1;
  790. if( (height-pheight)<top )
  791. top = height-pheight;
  792. timebox.css('marginTop','-'+parseInt(top)+'px');
  793. timeboxparent.trigger('scroll_element.xdsoft_scroller',[parseInt(top)/(height-pheight)]);
  794. }
  795. });
  796. var timerclick = 0;
  797. calendar
  798. .on('click.xdsoft','td',function() {
  799. timerclick++;
  800. var $this = $(this),
  801. currentTime = _xdsoft_datetime.currentTime;
  802. if( $this.hasClass('xdsoft_disabled') )
  803. return false;
  804. currentTime.setFullYear( $this.data('year') );
  805. currentTime.setMonth( $this.data('month') );
  806. currentTime.setDate( $this.data('date') );
  807. datetimepicker.trigger('select.xdsoft',[currentTime]);
  808. input.val( _xdsoft_datetime.str() );
  809. if( (timerclick>1||(options.closeOnDateSelect===true||( options.closeOnDateSelect===0&&!options.timepicker )))&&!options.inline ) {
  810. datetimepicker.trigger('close.xdsoft');
  811. }
  812. if( options.onSelectDate && options.onSelectDate.call ) {
  813. options.onSelectDate.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
  814. }
  815. datetimepicker.data('changed',true);
  816. datetimepicker.trigger('xchange.xdsoft');
  817. datetimepicker.trigger('changedatetime.xdsoft');
  818. setTimeout(function(){
  819. timerclick = 0;
  820. },200);
  821. });
  822. timebox
  823. .on('click.xdsoft','div',function() {
  824. var $this = $(this),
  825. currentTime = _xdsoft_datetime.currentTime;
  826. if( $this.hasClass('xdsoft_disabled') )
  827. return false;
  828. currentTime.setHours($this.data('hour'));
  829. currentTime.setMinutes($this.data('minute'));
  830. datetimepicker.trigger('select.xdsoft',[currentTime]);
  831. datetimepicker.data('input').val( _xdsoft_datetime.str() );
  832. !options.inline&&datetimepicker.trigger('close.xdsoft');
  833. if( options.onSelectTime&&options.onSelectTime.call ) {
  834. options.onSelectTime.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
  835. }
  836. datetimepicker.data('changed',true);
  837. datetimepicker.trigger('xchange.xdsoft');
  838. datetimepicker.trigger('changedatetime.xdsoft');
  839. });
  840. datetimepicker.mousewheel&&datepicker.mousewheel(function(event, delta, deltaX, deltaY) {
  841. if( !options.scrollMonth )
  842. return true;
  843. if( delta<0 )
  844. _xdsoft_datetime.nextMonth();
  845. else
  846. _xdsoft_datetime.prevMonth();
  847. return false;
  848. });
  849. datetimepicker.mousewheel&&timeboxparent.unmousewheel().mousewheel(function(event, delta, deltaX, deltaY) {
  850. if( !options.scrollTime )
  851. return true;
  852. var pheight = timeboxparent[0].clientHeight,
  853. height = timebox[0].offsetHeight,
  854. top = Math.abs(parseInt(timebox.css('marginTop'))),
  855. fl = true;
  856. if( delta<0 && (height-pheight)-options.timeHeightInTimePicker>=top ) {
  857. timebox.css('marginTop','-'+(top+options.timeHeightInTimePicker)+'px');
  858. fl = false;
  859. }else if( delta>0&&top-options.timeHeightInTimePicker>=0 ) {
  860. timebox.css('marginTop','-'+(top-options.timeHeightInTimePicker)+'px');
  861. fl = false;
  862. }
  863. timeboxparent.trigger('scroll_element.xdsoft_scroller',[Math.abs(parseInt(timebox.css('marginTop'))/(height-pheight))]);
  864. event.stopPropagation();
  865. return fl;
  866. });
  867. datetimepicker
  868. .on('changedatetime.xdsoft',function() {
  869. if( options.onChangeDateTime&&options.onChangeDateTime.call )
  870. options.onChangeDateTime.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
  871. })
  872. .on('generate.xdsoft',function() {
  873. if( options.onGenerate&&options.onGenerate.call )
  874. options.onGenerate.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
  875. });
  876. var current_time_index = 0;
  877. input.mousewheel&&input.mousewheel(function( event, delta, deltaX, deltaY ) {
  878. if( !options.scrollInput )
  879. return true;
  880. if( !options.datepicker && options.timepicker ) {
  881. current_time_index = timebox.find('.xdsoft_current').length?timebox.find('.xdsoft_current').eq(0).index():0;
  882. if( current_time_index+delta>=0&&current_time_index+delta<timebox.children().length )
  883. current_time_index+=delta;
  884. timebox.children().eq(current_time_index).length&&timebox.children().eq(current_time_index).trigger('mousedown');
  885. return false;
  886. }else if( options.datepicker && !options.timepicker ) {
  887. datepicker.trigger( event, [delta, deltaX, deltaY]);
  888. input.val&&input.val( _xdsoft_datetime.str() );
  889. datetimepicker.trigger('changedatetime.xdsoft');
  890. return false;
  891. }
  892. });
  893. var setPos = function() {
  894. var offset = datetimepicker.data('input').offset(), top = offset.top+datetimepicker.data('input')[0].offsetHeight-1, left = offset.left;
  895. if( top+datetimepicker[0].offsetHeight>$(window).height()+$(window).scrollTop() )
  896. top = offset.top-datetimepicker[0].offsetHeight+1;
  897. if( left+datetimepicker[0].offsetWidth>$(window).width() )
  898. left = offset.left-datetimepicker[0].offsetWidth+datetimepicker.data('input')[0].offsetWidth;
  899. datetimepicker.css({
  900. left:left,
  901. top:top
  902. });
  903. };
  904. datetimepicker
  905. .on('open.xdsoft', function() {
  906. var onShow = true;
  907. if( options.onShow&&options.onShow.call) {
  908. onShow = options.onShow.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
  909. }
  910. if( onShow!==false ) {
  911. datetimepicker.show();
  912. datetimepicker.trigger('afterOpen.xdsoft');
  913. setPos();
  914. $(window)
  915. .off('resize.xdsoft',setPos)
  916. .on('resize.xdsoft',setPos);
  917. if( options.closeOnWithoutClick ) {
  918. $([document.body,window]).on('mousedown.xdsoft',function arguments_callee6() {
  919. datetimepicker.trigger('close.xdsoft');
  920. $([document.body,window]).off('mousedown.xdsoft',arguments_callee6);
  921. });
  922. }
  923. }
  924. })
  925. .on('close.xdsoft', function( event ) {
  926. var onClose = true;
  927. if( options.onClose&&options.onClose.call ) {
  928. onClose=options.onClose.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
  929. }
  930. if( onClose!==false&&!options.opened&&!options.inline ) {
  931. datetimepicker.hide();
  932. }
  933. event.stopPropagation();
  934. })
  935. .data('input',input);
  936. var timer = 0,
  937. timer1 = 0;
  938. datetimepicker.data('xdsoft_datetime',_xdsoft_datetime);
  939. datetimepicker.setOptions(options);
  940. var ct = options.value?options.value:(input&&input.val&&input.val())?input.val():'';
  941. if( ct && _xdsoft_datetime.isValidDate(ct = Date.parseDate(ct, options.format)) ) {
  942. datetimepicker.data('changed',true);
  943. }else
  944. ct = '';
  945. _xdsoft_datetime.setCurrentTime( ct?ct:0 );
  946. datetimepicker.trigger('afterOpen.xdsoft');
  947. input
  948. .data( 'xdsoft_datetimepicker',datetimepicker )
  949. .on('open.xdsoft focusin.xdsoft mousedown.xdsoft',function(event) {
  950. if( input.is(':disabled')||input.is(':hidden')||!input.is(':visible') )
  951. return;
  952. clearTimeout(timer);
  953. timer = setTimeout(function() {
  954. if( input.is(':disabled')||input.is(':hidden')||!input.is(':visible') )
  955. return;
  956. _xdsoft_datetime.setCurrentTime((input&&input.val&&input.val())?input.val():0);
  957. datetimepicker.trigger('open.xdsoft');
  958. },100);
  959. })
  960. .on('keydown.xdsoft',function( event ) {
  961. var val = this.value,
  962. key = event.which;
  963. switch(true) {
  964. case !!~([ENTER].indexOf(key)):
  965. var elementSelector = $("input:visible,textarea:visible");
  966. datetimepicker.trigger('close.xdsoft');
  967. elementSelector.eq(elementSelector.index(this) + 1).focus();
  968. return false;
  969. case !!~[TAB].indexOf(key):
  970. datetimepicker.trigger('close.xdsoft');
  971. return true;
  972. }
  973. });
  974. },
  975. destroyDateTimePicker = function( input ) {
  976. var datetimepicker = input.data('xdsoft_datetimepicker');
  977. if( datetimepicker ) {
  978. datetimepicker.data('xdsoft_datetime',null);
  979. datetimepicker.remove();
  980. input
  981. .data( 'xdsoft_datetimepicker',null )
  982. .off( 'open.xdsoft focusin.xdsoft focusout.xdsoft mousedown.xdsoft blur.xdsoft keydown.xdsoft' );
  983. $(window).off('resize.xdsoft');
  984. $([window,document.body]).off('mousedown.xdsoft');
  985. input.unmousewheel&&input.unmousewheel();
  986. }
  987. };
  988. $(document)
  989. .off('keydown.xdsoftctrl keyup.xdsoftctrl')
  990. .on('keydown.xdsoftctrl',function(e) {
  991. if ( e.keyCode == CTRLKEY )
  992. ctrlDown = true;
  993. })
  994. .on('keyup.xdsoftctrl',function(e) {
  995. if ( e.keyCode == CTRLKEY )
  996. ctrlDown = false;
  997. });
  998. return this.each(function() {
  999. var datetimepicker;
  1000. if( datetimepicker = $(this).data('xdsoft_datetimepicker') ) {
  1001. if( $.type(opt) === 'string' ) {
  1002. switch(opt) {
  1003. case 'show':
  1004. $(this).select().focus();
  1005. datetimepicker.trigger( 'open.xdsoft' );
  1006. break;
  1007. case 'hide':
  1008. datetimepicker.trigger('close.xdsoft');
  1009. break;
  1010. case 'destroy':
  1011. destroyDateTimePicker($(this));
  1012. break;
  1013. case 'reset':
  1014. this.value = this.defaultValue;
  1015. if(!this.value || !datetimepicker.data('xdsoft_datetime').isValidDate(Date.parseDate(this.value, options.format)))
  1016. datetimepicker.data('changed',false);
  1017. datetimepicker.data('xdsoft_datetime').setCurrentTime(this.value);
  1018. break;
  1019. }
  1020. }else{
  1021. datetimepicker
  1022. .setOptions(opt);
  1023. }
  1024. return 0;
  1025. }else
  1026. ($.type(opt) !== 'string')&&createDateTimePicker($(this));
  1027. });
  1028. };
  1029. })( jQuery );
  1030. //http://www.xaprb.com/blog/2005/12/12/javascript-closures-for-runtime-efficiency/
  1031. /*
  1032. * Copyright (C) 2004 Baron Schwartz <baron at sequent dot org>
  1033. *
  1034. * This program is free software; you can redistribute it and/or modify it
  1035. * under the terms of the GNU Lesser General Public License as published by the
  1036. * Free Software Foundation, version 2.1.
  1037. *
  1038. * This program is distributed in the hope that it will be useful, but WITHOUT
  1039. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1040. * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  1041. * details.
  1042. */
  1043. Date.parseFunctions={count:0};Date.parseRegexes=[];Date.formatFunctions={count:0};Date.prototype.dateFormat=function(format) {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(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"};
  1044. //https://github.com/brandonaaron/jquery-mousewheel/blob/master/jquery.mousewheel.js
  1045. /*
  1046. * Copyright (c) 2013 Brandon Aaron (http://brandonaaron.net)
  1047. *
  1048. * Licensed under the MIT License (LICENSE.txt).
  1049. *
  1050. * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
  1051. * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
  1052. * Thanks to: Seamus Leahy for adding deltaX and deltaY
  1053. *
  1054. * Version: 3.1.3
  1055. *
  1056. * Requires: 1.2.2+
  1057. */
  1058. (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)}}));