datetimepicker.js 48 KB

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