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