From 887c93414235c0f29403cfcedd4e97411a4549b7 Mon Sep 17 00:00:00 2001 From: Valeriy Date: Mon, 16 Dec 2013 09:51:07 +0600 Subject: [PATCH] new version 2.0.8 To add a class weekends xdsoft_weekend (Sunday, Saturday) and Added options options.weekends --- datetimepicker.jquery.json | 2 +- index.html | 10 ++ jquery.datetimepicker.js | 300 ++++++++++++++++++++----------------- 3 files changed, 172 insertions(+), 140 deletions(-) diff --git a/datetimepicker.jquery.json b/datetimepicker.jquery.json index 14004bb..7dba571 100644 --- a/datetimepicker.jquery.json +++ b/datetimepicker.jquery.json @@ -20,7 +20,7 @@ "jquery", "touch" ], - "version": "2.0.7", + "version": "2.0.8", "author": { "name": "Chupurnov Valeriy", "email": "chupurnov@gmail.com", diff --git a/index.html b/index.html index f613908..11ad655 100644 --- a/index.html +++ b/index.html @@ -27,6 +27,8 @@

If select day is Saturday, the minimum set 11:00, otherwise 8:00

onGenerate

+

disable all weekend

+ @@ -95,5 +97,13 @@ $('#datetimepicker8').datetimepicker({ maxDate:'+1970/01/2', timepicker:false }); +$('#datetimepicker9').datetimepicker({ + onGenerate:function( ct ){ + $(this).find('.xdsoft_date.xdsoft_weekend') + .addClass('xdsoft_disabled'); + }, + weekends:['01.01.2014','02.01.2014','03.01.2014','04.01.2014','05.01.2014','06.01.2014'], + timepicker:false +}); diff --git a/jquery.datetimepicker.js b/jquery.datetimepicker.js index e821244..6aa58ea 100644 --- a/jquery.datetimepicker.js +++ b/jquery.datetimepicker.js @@ -1,9 +1,9 @@ /** - * @preserve jQuery DateTimePicker plugin v2.0.7 + * @preserve jQuery DateTimePicker plugin v2.0.8 * @homepage http://xdsoft.net/jqplugins/datetimepicker/ * (c) 2013, Chupurnov Valeriy. */ -(function( $ ){ +(function( $ ) { // fix for ie8 if (!Array.prototype.indexOf) { Array.prototype.indexOf = function(obj, start) { @@ -13,13 +13,13 @@ return -1; } } - $.fn.xdsoftScroller = function( _percent ){ - return this.each(function(){ + $.fn.xdsoftScroller = function( _percent ) { + return this.each(function() { var timeboxparent = $(this); - if( !$(this).hasClass('xdsoft_scroller_box') ){ - var pointerEventToXY = function( e ){ + if( !$(this).hasClass('xdsoft_scroller_box') ) { + var pointerEventToXY = function( e ) { var out = {x:0, y:0}; - if(e.type == 'touchstart' || e.type == 'touchmove' || e.type == 'touchend' || e.type == 'touchcancel'){ + if( e.type == 'touchstart' || e.type == 'touchmove' || e.type == 'touchend' || e.type == 'touchcancel' ) { var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0]; out.x = touch.pageX; out.y = touch.pageY; @@ -41,17 +41,17 @@ scrollbar.append(scroller); timeboxparent.addClass('xdsoft_scroller_box').append(scrollbar); - scroller.on('mousedown.xdsoft_scroller',function( event ){ + scroller.on('mousedown.xdsoft_scroller',function( event ) { var pageY = event.pageY, top = parseInt(scroller.css('margin-top')), h1 = scrollbar[0].offsetHeight; $(document.body).addClass('xdsoft_noselect'); - $([document.body,window]).on('mouseup.xdsoft_scroller',function(){ + $([document.body,window]).on('mouseup.xdsoft_scroller',function() { $([document.body,window]).off('mouseup.xdsoft_scroller',arguments.callee) .off('mousemove.xdsoft_scroller',move) .removeClass('xdsoft_noselect'); }); - $(document.body).on('mousemove.xdsoft_scroller',move = function(event){ + $(document.body).on('mousemove.xdsoft_scroller',move = function(event) { var offset = event.pageY-pageY+top; if( offset<0 ) offset = 0; @@ -62,12 +62,12 @@ }); timeboxparent - .on('scroll_element.xdsoft_scroller',function( event,percent ){ + .on('scroll_element.xdsoft_scroller',function( event,percent ) { percent = percent>1?1:(percent<0||isNaN(percent))?0:percent; scroller.css('margin-top',maximumOffset*percent); timebox.css('marginTop',-parseInt((height-parentHeight)*percent)) }) - .on('resize_scroll.xdsoft_scroller',function( event,_percent ){ + .on('resize_scroll.xdsoft_scroller',function( event,_percent ) { parentHeight = timeboxparent[0].offsetHeight-2; height = timebox[0].offsetHeight; var percent = parentHeight/height, @@ -87,25 +87,25 @@ event.stopPropagation(); return false; }); - timeboxparent.on('touchstart',function( event ){ + timeboxparent.on('touchstart',function( event ) { start = pointerEventToXY(event); }); - timeboxparent.on('touchmove',function( event ){ - if( start ){ + timeboxparent.on('touchmove',function( event ) { + if( start ) { var coord = pointerEventToXY(event), top = Math.abs(parseInt(timebox.css('marginTop'))); timeboxparent.trigger('scroll_element.xdsoft_scroller',[(top-(coord.y-start.y))/(height-parentHeight)]); event.stopPropagation(); event.preventDefault(); }; }); - timeboxparent.on('touchend touchcancel',function( event ){ + timeboxparent.on('touchend touchcancel',function( event ) { start = false; }); } timeboxparent.trigger('resize_scroll.xdsoft_scroller',[_percent]); }); }; - $.fn.datetimepicker = function( opt ){ + $.fn.datetimepicker = function( opt ) { var KEY0 = 48, KEY9 = 57, _KEY0 = 96, @@ -179,13 +179,13 @@ allowTimes:[], opened:false, inline:false, - onSelectDate:function(){}, - onSelectTime:function(){}, - onChangeMonth:function(){}, - onChangeDateTime:function(){}, - onShow:function(){}, - onClose:function(){}, - onGenerate:function(){}, + onSelectDate:function() {}, + onSelectTime:function() {}, + onChangeMonth:function() {}, + onChangeDateTime:function() {}, + onShow:function() {}, + onClose:function() {}, + onGenerate:function() {}, withoutCopyright:true, inverseButton:false, hours12:false, @@ -205,10 +205,11 @@ style:'', id:'', roundTime:'round', // ceil, floor - className:'' + className:'', + weekends : [] }, options = ($.isPlainObject(opt)||!opt)?$.extend({},default_options,opt):$.extend({},default_options), - createDateTimePicker = function( input ){ + createDateTimePicker = function( input ) { var datetimepicker = $('
'), xdsoft_copyright = $(''), datepicker = $('
'), @@ -244,8 +245,8 @@ val = _xdsoft_datetime.currentTime[$(this).hasClass('xdsoft_month')?'getMonth':'getFullYear'](); select.show(); - for(var items = select.find('div.xdsoft_option'),i = 0;i=KEY0&&key<=KEY9 )||( key>=_KEY0&&key<=_KEY9 ))||(key==BACKSPACE||key==DEL): var pos = getCaretPos(this), digit = ( key!=BACKSPACE&&key!=DEL )?String.fromCharCode((_KEY0 <= key && key <= _KEY9)? key-KEY0 : key):'_'; - if( (key==BACKSPACE||key==DEL)&&pos ){ + if( (key==BACKSPACE||key==DEL)&&pos ) { pos--; digit='_'; } @@ -395,7 +396,7 @@ pos+=(key==BACKSPACE||key==DEL)?0:1; while( /[^0-9_]/.test(options.mask.substr(pos,1))&&pos0 ) pos+=(key==BACKSPACE||key==DEL)?-1:1; - if( isValidValue( options.mask,val ) ){ + if( isValidValue( options.mask,val ) ) { this.value = val; setCaretPos(this,pos); }else if( $.trim(val)=='' ) @@ -414,14 +415,14 @@ break; } } - if( options.validateOnBlur ){ + if( options.validateOnBlur ) { input .off('blur.xdsoft') - .on('blur.xdsoft', function(){ - if( options.allowBlank && !$.trim($(this).val()).length ){ + .on('blur.xdsoft', function() { + if( options.allowBlank && !$.trim($(this).val()).length ) { return true; } - else if( !Date.parseDate( $(this).val(), options.format ) ){ + else if( !Date.parseDate( $(this).val(), options.format ) ) { $(this).val((new Date()).dateFormat( options.format )); } }); @@ -433,7 +434,7 @@ datetimepicker .data('options',options) - .on('mousedown.xdsoft',function( event ){ + .on('mousedown.xdsoft',function( event ) { event.stopPropagation(); event.preventDefault(); yearselect.hide(); @@ -444,7 +445,7 @@ var scroll_element = timepicker.find('.xdsoft_time_box'); scroll_element.append(timebox); scroll_element.xdsoftScroller(); - datetimepicker.on('afterOpen.xdsoft',function(){ + datetimepicker.on('afterOpen.xdsoft',function() { scroll_element.xdsoftScroller(); }); @@ -462,9 +463,9 @@ $('body').append(datetimepicker); - var XDSoftDateTime = function(){ + var XDSoftDateTime = function() { var _this = this; - _this.now = function(){ + _this.now = function() { return new Date(); }; @@ -475,18 +476,18 @@ return !isNaN(d.getTime()); }; - _this.setCurrentTime = function( dTime){ + _this.setCurrentTime = function( dTime) { _this.currentTime = (typeof dTime == 'string')? _this.strtodatetime(dTime) : _this.isValidDate(dTime) ? dTime: _this.now(); datetimepicker.trigger('xchange.xdsoft'); }; - _this.getCurrentTime = function( dTime){ + _this.getCurrentTime = function( dTime) { return _this.currentTime; }; - _this.nextMonth = function(){ + _this.nextMonth = function() { var month = _this.currentTime.getMonth()+1; - if( month==12 ){ + if( month==12 ) { _this.currentTime.setFullYear(_this.currentTime.getFullYear()+1); month = 0; } @@ -496,9 +497,9 @@ return month; }; - _this.prevMonth = function(){ + _this.prevMonth = function() { var month = _this.currentTime.getMonth()-1; - if( month==-1 ){ + if( month==-1 ) { _this.currentTime.setFullYear(_this.currentTime.getFullYear()-1); month = 11; } @@ -508,28 +509,28 @@ return month; }; - _this.strtodatetime = function( sDateTime ){ + _this.strtodatetime = function( sDateTime ) { var currentTime = sDateTime?Date.parseDate(sDateTime, options.format):new Date; if( !_this.isValidDate(currentTime) ) currentTime = new Date; return currentTime; }; - _this.strtodate = function( sDate ){ + _this.strtodate = function( sDate ) { var currentTime = sDate?Date.parseDate(sDate, options.formatDate):new Date; if( !_this.isValidDate(currentTime) ) currentTime = new Date; return currentTime; }; - _this.strtotime = function( sTime ){ + _this.strtotime = function( sTime ) { var currentTime = sTime?Date.parseDate(sTime, options.formatTime):new Date; if( !_this.isValidDate(currentTime) ) currentTime = new Date; return currentTime; }; - _this.str = function(){ + _this.str = function() { return _this.currentTime.dateFormat(options.format); }; }, @@ -537,22 +538,22 @@ mounth_picker .find('.xdsoft_prev,.xdsoft_next') - .on('mousedown.xdsoft',function(){ + .on('mousedown.xdsoft',function() { var $this = $(this), timer = 0, stop = false; - (function(v){ + (function(v) { var month = _xdsoft_datetime.currentTime.getMonth(); - if( $this.hasClass( options.next ) ){ + if( $this.hasClass( options.next ) ) { _xdsoft_datetime.nextMonth(); - }else if( $this.hasClass( options.prev ) ){ + }else if( $this.hasClass( options.prev ) ) { _xdsoft_datetime.prevMonth(); } !stop&&(timer = setTimeout(arguments.callee,v?v:100)); })(500); - $([document.body,window]).on('mouseup.xdsoft',function(){ + $([document.body,window]).on('mouseup.xdsoft',function() { clearTimeout(timer); stop = true; $([document.body,window]).off('mouseup.xdsoft',arguments.callee); @@ -561,25 +562,25 @@ timepicker .find('.xdsoft_prev,.xdsoft_next') - .on('mousedown.xdsoft',function(){ + .on('mousedown.xdsoft',function() { var $this = $(this), timer = 0, stop = false, period = 110; - (function(v){ + (function(v) { var pheight = timeboxparent[0].offsetHeight-2, height = timebox[0].offsetHeight, top = Math.abs(parseInt(timebox.css('marginTop'))); - if( $this.hasClass(options.next) && (height-pheight)- options.timeHeightInTimePicker>=top ){ + if( $this.hasClass(options.next) && (height-pheight)- options.timeHeightInTimePicker>=top ) { timebox.css('marginTop','-'+(top+options.timeHeightInTimePicker)+'px') - }else if( $this.hasClass(options.prev) && top-options.timeHeightInTimePicker>=0 ){ + }else if( $this.hasClass(options.prev) && top-options.timeHeightInTimePicker>=0 ) { timebox.css('marginTop','-'+(top-options.timeHeightInTimePicker)+'px') } timeboxparent.trigger('scroll_element.xdsoft_scroller',[Math.abs(parseInt(timebox.css('marginTop'))/(height-pheight))]); period= ( period>10 )?10:period-10; !stop&&(timer = setTimeout(arguments.callee,v?v:period)); })(500); - $([document.body,window]).on('mouseup.xdsoft',function(){ + $([document.body,window]).on('mouseup.xdsoft',function() { clearTimeout(timer); stop = true; $([document.body,window]) @@ -589,7 +590,7 @@ // base handler - generating a calendar and timepicker datetimepicker - .on('xchange.xdsoft',function( event ){ + .on('xchange.xdsoft',function( event ) { var table = '', start = new Date(_xdsoft_datetime.currentTime.getFullYear(),_xdsoft_datetime.currentTime.getMonth(),1), i = 0, @@ -602,37 +603,56 @@ table+=''; // days - for(var j = 0; j<7; j++){ + for(var j = 0; j<7; j++) { table+=''; } table+=''; table+=''; var maxDate = false, minDate = false; - if( options.maxDate!==false ){ + if( options.maxDate!==false ) { maxDate = _xdsoft_datetime.strtodate(options.maxDate); maxDate = new Date(maxDate.getFullYear(),maxDate.getMonth(),maxDate.getDate(),23,59,59,999); } - if( options.minDate!==false ){ + if( options.minDate!==false ) { minDate = _xdsoft_datetime.strtodate(options.minDate); minDate = new Date(minDate.getFullYear(),minDate.getMonth(),minDate.getDate()); } - var d,y,m; - while( i<_xdsoft_datetime.currentTime.getDaysInMonth()||start.getDay()!=options.dayOfWeekStart||_xdsoft_datetime.currentTime.getMonth()==start.getMonth() ){ + var d,y,m,classes = []; + while( i<_xdsoft_datetime.currentTime.getDaysInMonth()||start.getDay()!=options.dayOfWeekStart||_xdsoft_datetime.currentTime.getMonth()==start.getMonth() ) { + classes = []; i++; + d = start.getDate(); y = start.getFullYear(); m = start.getMonth(); - table+=''; - if( start.getDay()==options.dayOfWeekStartPrev ) + + classes.push('xdsoft_date'); + + if( ( maxDate!==false && start > maxDate )||( minDate!==false && start < minDate ) ){ + classes.push('xdsoft_disabled'); + } + + if( _xdsoft_datetime.currentTime.getMonth()!=m ) classes.push('xdsoft_other_month'); + + if( _xdsoft_datetime.currentTime.dateFormat('d.m.Y')==start.dateFormat('d.m.Y') ) { + classes.push('xdsoft_current'); + } + + if( today.dateFormat('d.m.Y')==start.dateFormat('d.m.Y') ) { + classes.push('xdsoft_today'); + } + + if( start.getDay()==0||start.getDay()==6||~options.weekends.indexOf(start.dateFormat('d.m.Y')) ) { + classes.push('xdsoft_weekend'); + } + + table+=''; + + if( start.getDay()==options.dayOfWeekStartPrev ) { table+=''; + } + start.setDate(d+1); } table+='
'+options.i18n[options.lang].dayOfWeek[(j+options.dayOfWeekStart)>6?0:j+options.dayOfWeekStart]+'
'+d+'
'+ + '
'+d+'
'+ + '
'; @@ -646,7 +666,7 @@ var time = '', h = '', m ='', - line_time = function line_time( h,m ){ + line_time = function line_time( h,m ) { var now = new Date(); now.setHours(h); h = parseInt(now.getHours()); @@ -664,41 +684,43 @@ ((parseInt(today.getHours())==parseInt(h)&&parseInt(today.getMinutes())==parseInt(m))?' xdsoft_today ':'')+ '" data-hour="'+h+'" data-minute="'+m+'">'+now.dateFormat(options.formatTime)+''; }; - if( !options.allowTimes || !$.isArray(options.allowTimes) || !options.allowTimes.length ){ - for(var i=0,j=0;i<(options.hours12?12:24);i++){ - for(j=0;j<60;j+=options.step){ + + if( !options.allowTimes || !$.isArray(options.allowTimes) || !options.allowTimes.length ) { + for( var i=0,j=0;i<(options.hours12?12:24);i++ ) { + for( j=0;j<60;j+=options.step ) { h = (i<10?'0':'')+i; m = (j<10?'0':'')+j; line_time( h,m ); } } }else{ - for(var i=0;i'+i+''; } yearselect.children().eq(0) .html(opt); - for( i = 0,opt = '';i<= 11;i++ ){ + for( i = 0,opt = '';i<= 11;i++ ) { opt+='
'+options.i18n[options.lang].months[i]+'
'; } monthselect.children().eq(0).html(opt); $(this).trigger('generate.xdsoft'); event.stopPropagation(); }) - .on('afterOpen.xdsoft',function(){ - if( options.timepicker && timebox.find('.xdsoft_current').length ){ + .on('afterOpen.xdsoft',function() { + if( options.timepicker && timebox.find('.xdsoft_current').length ) { var pheight = timeboxparent[0].offsetHeight-2, height = timebox[0].offsetHeight, top = timebox.find('.xdsoft_current').index()*options.timeHeightInTimePicker+1; @@ -709,7 +731,7 @@ } }); calendar - .on('mousedown.xdsoft','td',function(){ + .on('mousedown.xdsoft','td',function() { var $this = $(this), currentTime = _xdsoft_datetime.currentTime; if( $this.hasClass('xdsoft_disabled') ) @@ -720,11 +742,11 @@ datetimepicker.trigger('select.xdsoft',[currentTime]); input.val( _xdsoft_datetime.str() ); - if( (options.closeOnDateSelect===true||( options.closeOnDateSelect===0&&!options.timepicker ))&&!options.inline ){ + if( (options.closeOnDateSelect===true||( options.closeOnDateSelect===0&&!options.timepicker ))&&!options.inline ) { datetimepicker.trigger('close.xdsoft'); } - if( options.onSelectDate && options.onSelectDate.call ){ + if( options.onSelectDate && options.onSelectDate.call ) { options.onSelectDate.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input')); } @@ -733,7 +755,7 @@ }); timebox - .on('mousedown.xdsoft','div',function(){ + .on('mousedown.xdsoft','div',function() { var $this = $(this), currentTime = _xdsoft_datetime.currentTime; if( $this.hasClass('xdsoft_disabled') ) @@ -746,7 +768,7 @@ !options.inline&&datetimepicker.trigger('close.xdsoft'); - if( options.onSelectTime&&options.onSelectTime.call ){ + if( options.onSelectTime&&options.onSelectTime.call ) { options.onSelectTime.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input')); } @@ -771,10 +793,10 @@ height = timebox[0].offsetHeight, top = Math.abs(parseInt(timebox.css('marginTop'))), fl = true; - if( delta<0 && (height-pheight)-options.timeHeightInTimePicker>=top ){ + if( delta<0 && (height-pheight)-options.timeHeightInTimePicker>=top ) { timebox.css('marginTop','-'+(top+options.timeHeightInTimePicker)+'px'); fl = false; - }else if( delta>0&&top-options.timeHeightInTimePicker>=0 ){ + }else if( delta>0&&top-options.timeHeightInTimePicker>=0 ) { timebox.css('marginTop','-'+(top-options.timeHeightInTimePicker)+'px'); fl = false; } @@ -784,33 +806,33 @@ }); datetimepicker - .on('changedatetime.xdsoft',function(){ + .on('changedatetime.xdsoft',function() { if( options.onChangeDateTime&&options.onChangeDateTime.call ) options.onChangeDateTime.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input')); }) - .on('generate.xdsoft',function(){ + .on('generate.xdsoft',function() { if( options.onGenerate&&options.onGenerate.call ) options.onGenerate.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input')); }); var current_time_index = 0; - input.mousewheel&&input.mousewheel(function( event, delta, deltaX, deltaY ){ + input.mousewheel&&input.mousewheel(function( event, delta, deltaX, deltaY ) { if( !options.scrollInput ) return true; - if( !options.datepicker && options.timepicker ){ + if( !options.datepicker && options.timepicker ) { current_time_index = timebox.find('.xdsoft_current').length?timebox.find('.xdsoft_current').eq(0).index():0; if( current_time_index+delta>=0&¤t_time_index+delta$('body').height() ) top = offset.top-datetimepicker[0].offsetHeight+1; @@ -822,12 +844,12 @@ }); }; datetimepicker - .on('open.xdsoft', function(){ + .on('open.xdsoft', function() { var onShow = true; - if( options.onShow&&options.onShow.call){ + if( options.onShow&&options.onShow.call) { onShow = options.onShow.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input')); } - if( onShow!==false ){ + if( onShow!==false ) { datetimepicker.show(); datetimepicker.trigger('afterOpen.xdsoft'); setPos(); @@ -835,20 +857,20 @@ .off('resize.xdsoft',setPos) .on('resize.xdsoft',setPos); - if( options.closeOnWithoutClick ){ - $([document.body,window]).on('mousedown.xdsoft',function(){ + if( options.closeOnWithoutClick ) { + $([document.body,window]).on('mousedown.xdsoft',function() { datetimepicker.trigger('close.xdsoft'); $([document.body,window]).off('mousedown.xdsoft',arguments.callee); }); } } }) - .on('close.xdsoft', function( event ){ + .on('close.xdsoft', function( event ) { var onClose = true; - if( options.onClose&&options.onClose.call ){ + if( options.onClose&&options.onClose.call ) { onClose=options.onClose.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input')); } - if( onClose!==false&&!options.opened&&!options.inline ){ + if( onClose!==false&&!options.opened&&!options.inline ) { datetimepicker.hide(); } event.stopPropagation(); @@ -866,21 +888,21 @@ input .data( 'xdsoft_datetimepicker',datetimepicker ) - .on('open.xdsoft focusin.xdsoft mousedown.xdsoft',function(event){ + .on('open.xdsoft focusin.xdsoft mousedown.xdsoft',function(event) { if( input.is(':disabled')||input.is(':hidden')||!input.is(':visible') ) return; clearTimeout(timer); - timer = setTimeout(function(){ + timer = setTimeout(function() { if( input.is(':disabled')||input.is(':hidden')||!input.is(':visible') ) return; _xdsoft_datetime.setCurrentTime((input&&input.val&&input.val())?input.val():new Date); datetimepicker.trigger('open.xdsoft'); },100); }) - .on('keydown.xdsoft',function( event ){ + .on('keydown.xdsoft',function( event ) { var val = this.value, key = event.which; - switch(true){ + switch(true) { case !!~([ENTER].indexOf(key)): var elementSelector = $("input:visible,textarea:visible"); datetimepicker.trigger('close.xdsoft'); @@ -891,16 +913,16 @@ return true; } }); - /*.on('focusout.xdsoft',function(event){ + /*.on('focusout.xdsoft',function(event) { clearTimeout(timer1); - timer1 = setTimeout(function(){ + timer1 = setTimeout(function() { //datetimepicker.trigger('close.xdsoft'); },100); });*/ }, - destroyDateTimePicker = function( input ){ + destroyDateTimePicker = function( input ) { var datetimepicker = input.data('xdsoft_datetimepicker'); - if( datetimepicker ){ + if( datetimepicker ) { var _xdsoft_datetime = _xdsoft_datetime; delete _xdsoft_datetime; datetimepicker.remove(); @@ -916,19 +938,19 @@ }; $(document) .off('keydown.xdsoftctrl keyup.xdsoftctrl') - .on('keydown.xdsoftctrl',function(e){ + .on('keydown.xdsoftctrl',function(e) { if ( e.keyCode == CTRLKEY ) ctrlDown = true; }) - .on('keyup.xdsoftctrl',function(e){ + .on('keyup.xdsoftctrl',function(e) { if ( e.keyCode == CTRLKEY ) ctrlDown = false; }); - return this.each(function(){ + return this.each(function() { var datetimepicker; - if( datetimepicker = $(this).data('xdsoft_datetimepicker') ){ - if( $.type(opt) === 'string' ){ - switch(opt){ + if( datetimepicker = $(this).data('xdsoft_datetimepicker') ) { + if( $.type(opt) === 'string' ) { + switch(opt) { case 'show': $(this).select().focus(); datetimepicker.trigger( 'open.xdsoft' ); @@ -964,7 +986,7 @@ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ -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 0) {";var regex="";var special=false;var ch='';for(var i=0;i 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 0) {";var regex="";var special=false;var ch='';for(var i=0;i 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=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||absDelta0?'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)}})); +(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||absDelta0?'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)}}));