Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Teemu Pääkkönen 2014-01-08 14:56:03 +02:00
commit 4e1d9cc57e

View File

@ -1,4 +1,4 @@
/** /**
* @preserve jQuery DateTimePicker plugin v2.1.1 * @preserve jQuery DateTimePicker plugin v2.1.1
* @homepage http://xdsoft.net/jqplugins/datetimepicker/ * @homepage http://xdsoft.net/jqplugins/datetimepicker/
* (c) 2013, Chupurnov Valeriy. * (c) 2013, Chupurnov Valeriy.
@ -38,6 +38,22 @@
dayOfWeek:[ dayOfWeek:[
"zo", "ma", "di", "wo", "do", "vr", "za" "zo", "ma", "di", "wo", "do", "vr", "za"
] ]
},
tr:{
months:[
"Ocak", "Şubat", "Mart", "Nisan", "Mayıs", "Haziran", "Temmuz", "Ağustos", "Eylül", "Ekim", "Kasım", "Aralık"
],
dayOfWeek:[
"Paz", "Pts", "Sal", "Çar", "Per", "Cum", "Cts"
]
},
fr:{
months:[
"Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"
],
dayOfWeek:[
"Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"
]
} }
}, },
value:'', value:'',
@ -89,7 +105,7 @@
weekends : [] weekends : []
}; };
// fix for ie8 // fix for ie8
if (!Array.prototype.indexOf) { if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(obj, start) { Array.prototype.indexOf = function(obj, start) {
for (var i = (start || 0), j = this.length; i < j; i++) { for (var i = (start || 0), j = this.length; i < j; i++) {
if (this[i] === obj) { return i; } if (this[i] === obj) { return i; }
@ -121,9 +137,9 @@
scroller = $('<div class="xdsoft_scroller"></div>'), scroller = $('<div class="xdsoft_scroller"></div>'),
maximumOffset = 100, maximumOffset = 100,
start = false; start = false;
scrollbar.append(scroller); scrollbar.append(scroller);
timeboxparent.addClass('xdsoft_scroller_box').append(scrollbar); 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, var pageY = event.pageY,
@ -144,7 +160,7 @@
timeboxparent.trigger('scroll_element.xdsoft_scroller',[maximumOffset?offset/maximumOffset:0]); timeboxparent.trigger('scroll_element.xdsoft_scroller',[maximumOffset?offset/maximumOffset:0]);
}); });
}); });
timeboxparent 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; percent = percent>1?1:(percent<0||isNaN(percent))?0:percent;
@ -225,7 +241,7 @@
scroller = $('<div class="xdsoft_scroller"></div>'), scroller = $('<div class="xdsoft_scroller"></div>'),
monthselect =$('<div class="xdsoft_select xdsoft_monthselect"><div></div></div>'), monthselect =$('<div class="xdsoft_select xdsoft_monthselect"><div></div></div>'),
yearselect =$('<div class="xdsoft_select xdsoft_yearselect"><div></div></div>'); yearselect =$('<div class="xdsoft_select xdsoft_yearselect"><div></div></div>');
//constructor lego //constructor lego
mounth_picker mounth_picker
.find('.xdsoft_month span') .find('.xdsoft_month span')
@ -233,7 +249,7 @@
mounth_picker mounth_picker
.find('.xdsoft_year span') .find('.xdsoft_year span')
.after(yearselect); .after(yearselect);
mounth_picker mounth_picker
.find('.xdsoft_month,.xdsoft_year') .find('.xdsoft_month,.xdsoft_year')
.on('mousedown.xdsoft',function(event) { .on('mousedown.xdsoft',function(event) {
@ -243,22 +259,22 @@
var select = $(this).find('.xdsoft_select').eq(0), var select = $(this).find('.xdsoft_select').eq(0),
val = 0, val = 0,
top = 0; top = 0;
if( _xdsoft_datetime.currentTime ) if( _xdsoft_datetime.currentTime )
val = _xdsoft_datetime.currentTime[$(this).hasClass('xdsoft_month')?'getMonth':'getFullYear'](); val = _xdsoft_datetime.currentTime[$(this).hasClass('xdsoft_month')?'getMonth':'getFullYear']();
select.show(); select.show();
for(var items = select.find('div.xdsoft_option'),i = 0;i<items.length;i++) { for(var items = select.find('div.xdsoft_option'),i = 0;i<items.length;i++) {
if( items.eq(i).data('value')==val ) { if( items.eq(i).data('value')==val ) {
break; break;
}else top+=items[0].offsetHeight; }else top+=items[0].offsetHeight;
} }
select.xdsoftScroller(top/(select.children()[0].offsetHeight-(select[0].offsetHeight-2))); select.xdsoftScroller(top/(select.children()[0].offsetHeight-(select[0].offsetHeight-2)));
event.stopPropagation(); event.stopPropagation();
return false; return false;
}); });
mounth_picker mounth_picker
.find('.xdsoft_select') .find('.xdsoft_select')
.xdsoftScroller() .xdsoftScroller()
@ -271,44 +287,45 @@
_xdsoft_datetime.currentTime[$(this).parent().parent().hasClass('xdsoft_monthselect')?'setMonth':'setFullYear']($(this).data('value')); _xdsoft_datetime.currentTime[$(this).parent().parent().hasClass('xdsoft_monthselect')?'setMonth':'setFullYear']($(this).data('value'));
$(this).parent().parent().hide(); $(this).parent().parent().hide();
datetimepicker.trigger('xchange.xdsoft'); datetimepicker.trigger('xchange.xdsoft');
options.onChangeMonth&&options.onChangeMonth.call&&options.onChangeMonth.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
}); });
// set options // set options
datetimepicker.setOptions = function( _options ) { datetimepicker.setOptions = function( _options ) {
options = $.extend({},options,_options); options = $.extend({},options,_options);
if( (options.open||options.opened)&&(!options.inline) ) { if( (options.open||options.opened)&&(!options.inline) ) {
input.trigger('open.xdsoft'); input.trigger('open.xdsoft');
} }
if( options.inline ) { if( options.inline ) {
datetimepicker.addClass('xdsoft_inline'); datetimepicker.addClass('xdsoft_inline');
input.after(datetimepicker).hide(); input.after(datetimepicker).hide();
datetimepicker.trigger('afterOpen.xdsoft'); datetimepicker.trigger('afterOpen.xdsoft');
} }
if( options.inverseButton ) { if( options.inverseButton ) {
options.next = 'xdsoft_prev'; options.next = 'xdsoft_prev';
options.prev = 'xdsoft_next'; options.prev = 'xdsoft_next';
} }
if( !options.datepicker && options.timepicker ) if( !options.datepicker && options.timepicker )
datepicker.removeClass('active'); datepicker.removeClass('active');
if( options.datepicker && !options.timepicker ) if( options.datepicker && !options.timepicker )
timepicker.removeClass('active'); timepicker.removeClass('active');
if( options.value ) if( options.value )
input&&input.val&&input.val(options.value); input&&input.val&&input.val(options.value);
if( isNaN(options.dayOfWeekStart)||parseInt(options.dayOfWeekStart)<0||parseInt(options.dayOfWeekStart)>6 ) if( isNaN(options.dayOfWeekStart)||parseInt(options.dayOfWeekStart)<0||parseInt(options.dayOfWeekStart)>6 )
options.dayOfWeekStart = 0; options.dayOfWeekStart = 0;
else else
options.dayOfWeekStart = parseInt(options.dayOfWeekStart); options.dayOfWeekStart = parseInt(options.dayOfWeekStart);
if( !options.timepickerScrollbar ) if( !options.timepickerScrollbar )
scrollbar.hide(); scrollbar.hide();
var tmpDate = [],timeOffset; var tmpDate = [],timeOffset;
if( options.minDate && ( tmpDate = /^-(.*)$/.exec(options.minDate) ) && (tmpDate=Date.parseDate(tmpDate[1], options.formatDate)) ) { if( options.minDate && ( tmpDate = /^-(.*)$/.exec(options.minDate) ) && (tmpDate=Date.parseDate(tmpDate[1], options.formatDate)) ) {
timeOffset = tmpDate.getTime()+-1*(tmpDate.getTimezoneOffset())*60000; timeOffset = tmpDate.getTime()+-1*(tmpDate.getTimezoneOffset())*60000;
@ -322,7 +339,7 @@
mounth_picker mounth_picker
.find('.xdsoft_today_button') .find('.xdsoft_today_button')
.css('visibility',!options.todayButton?'hidden':'visible'); .css('visibility',!options.todayButton?'hidden':'visible');
if( options.mask ) { if( options.mask ) {
var e, var e,
getCaretPos = function ( input ) { getCaretPos = function ( input ) {
@ -379,9 +396,9 @@
case ( $.type(options.mask) == 'string' ): case ( $.type(options.mask) == 'string' ):
if( !isValidValue( options.mask,input.val() ) ) if( !isValidValue( options.mask,input.val() ) )
input.val(options.mask.replace(/[0-9]/g,'_')); input.val(options.mask.replace(/[0-9]/g,'_'));
input.on('keydown.xdsoft',function( event ) { input.on('keydown.xdsoft',function( event ) {
var val = this.value, var val = this.value,
key = event.which; key = event.which;
switch(true) { switch(true) {
case (( key>=KEY0&&key<=KEY9 )||( key>=_KEY0&&key<=_KEY9 ))||(key==BACKSPACE||key==DEL): case (( key>=KEY0&&key<=KEY9 )||( key>=_KEY0&&key<=_KEY9 ))||(key==BACKSPACE||key==DEL):
@ -393,14 +410,14 @@
} }
while( /[^0-9_]/.test(options.mask.substr(pos,1))&&pos<options.mask.length&&pos>0 ) while( /[^0-9_]/.test(options.mask.substr(pos,1))&&pos<options.mask.length&&pos>0 )
pos+=( key==BACKSPACE||key==DEL )?-1:1; pos+=( key==BACKSPACE||key==DEL )?-1:1;
val = val.substr(0,pos)+digit+val.substr(pos+1); val = val.substr(0,pos)+digit+val.substr(pos+1);
if( $.trim(val)=='' ) if( $.trim(val)=='' )
val = options.mask.replace(/[0-9]/g,'_'); val = options.mask.replace(/[0-9]/g,'_');
else else
if( pos==options.mask.length ) if( pos==options.mask.length )
break; break;
pos+=(key==BACKSPACE||key==DEL)?0:1; pos+=(key==BACKSPACE||key==DEL)?0:1;
while( /[^0-9_]/.test(options.mask.substr(pos,1))&&pos<options.mask.length&&pos>0 ) while( /[^0-9_]/.test(options.mask.substr(pos,1))&&pos<options.mask.length&&pos>0 )
pos+=(key==BACKSPACE||key==DEL)?-1:1; pos+=(key==BACKSPACE||key==DEL)?-1:1;
@ -428,18 +445,20 @@
.off('blur.xdsoft') .off('blur.xdsoft')
.on('blur.xdsoft', function() { .on('blur.xdsoft', function() {
if( options.allowBlank && !$.trim($(this).val()).length ) { if( options.allowBlank && !$.trim($(this).val()).length ) {
return true; $(this).val(null);
} }
else if( !Date.parseDate( $(this).val(), options.format ) ) { else if( !Date.parseDate( $(this).val(), options.format ) ) {
$(this).val((new Date()).dateFormat( options.format )); $(this).val((new Date()).dateFormat( options.format ));
} }
datetimepicker.data('xdsoft_datetime').setCurrentTime($(this).val());
datetimepicker.trigger('changedatetime.xdsoft');
}); });
} }
options.dayOfWeekStartPrev = (options.dayOfWeekStart==0)?6:options.dayOfWeekStart-1; options.dayOfWeekStartPrev = (options.dayOfWeekStart==0)?6:options.dayOfWeekStart-1;
datetimepicker datetimepicker
.trigger('xchange.xdsoft'); .trigger('xchange.xdsoft');
}; };
datetimepicker datetimepicker
.data('options',options) .data('options',options)
.on('mousedown.xdsoft',function( event ) { .on('mousedown.xdsoft',function( event ) {
@ -449,50 +468,50 @@
monthselect.hide(); monthselect.hide();
return false; return false;
}); });
var scroll_element = timepicker.find('.xdsoft_time_box'); var scroll_element = timepicker.find('.xdsoft_time_box');
scroll_element.append(timebox); scroll_element.append(timebox);
scroll_element.xdsoftScroller(); scroll_element.xdsoftScroller();
datetimepicker.on('afterOpen.xdsoft',function() { datetimepicker.on('afterOpen.xdsoft',function() {
scroll_element.xdsoftScroller(); scroll_element.xdsoftScroller();
}); });
datetimepicker datetimepicker
.append(datepicker) .append(datepicker)
.append(timepicker); .append(timepicker);
if( options.withoutCopyright!==true ) if( options.withoutCopyright!==true )
datetimepicker datetimepicker
.append(xdsoft_copyright); .append(xdsoft_copyright);
datepicker datepicker
.append(mounth_picker) .append(mounth_picker)
.append(calendar); .append(calendar);
$('body').append(datetimepicker); $('body').append(datetimepicker);
var XDSoftDateTime = function() { var XDSoftDateTime = function() {
var _this = this; var _this = this;
_this.now = function() { _this.now = function() {
return new Date(); return new Date();
}; };
_this.currentTime = this.now(); _this.currentTime = this.now();
_this.isValidDate = function (d) { _this.isValidDate = function (d) {
if ( Object.prototype.toString.call(d) !== "[object Date]" ) if ( Object.prototype.toString.call(d) !== "[object Date]" )
return false; return false;
return !isNaN(d.getTime()); 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(); _this.currentTime = (typeof dTime == 'string')? _this.strtodatetime(dTime) : _this.isValidDate(dTime) ? dTime: _this.now();
datetimepicker.trigger('xchange.xdsoft'); datetimepicker.trigger('xchange.xdsoft');
}; };
_this.getCurrentTime = function( dTime) { _this.getCurrentTime = function( dTime) {
return _this.currentTime; return _this.currentTime;
}; };
_this.nextMonth = function() { _this.nextMonth = function() {
var month = _this.currentTime.getMonth()+1; var month = _this.currentTime.getMonth()+1;
if( month==12 ) { if( month==12 ) {
@ -504,7 +523,7 @@
datetimepicker.trigger('xchange.xdsoft'); datetimepicker.trigger('xchange.xdsoft');
return month; return month;
}; };
_this.prevMonth = function() { _this.prevMonth = function() {
var month = _this.currentTime.getMonth()-1; var month = _this.currentTime.getMonth()-1;
if( month==-1 ) { if( month==-1 ) {
@ -516,31 +535,31 @@
datetimepicker.trigger('xchange.xdsoft'); datetimepicker.trigger('xchange.xdsoft');
return month; return month;
}; };
_this.strtodatetime = function( sDateTime ) { _this.strtodatetime = function( sDateTime ) {
var currentTime = sDateTime?Date.parseDate(sDateTime, options.format):new Date; var currentTime = sDateTime?Date.parseDate(sDateTime, options.format):new Date;
if( !_this.isValidDate(currentTime) ) if( !_this.isValidDate(currentTime) )
currentTime = new Date; currentTime = new Date;
return currentTime; return currentTime;
}; };
_this.strtodate = function( sDate ) { _this.strtodate = function( sDate ) {
var currentTime = sDate?Date.parseDate(sDate, options.formatDate):new Date; var currentTime = sDate?Date.parseDate(sDate, options.formatDate):new Date;
if( !_this.isValidDate(currentTime) ) if( !_this.isValidDate(currentTime) )
currentTime = new Date; currentTime = new Date;
return currentTime; return currentTime;
}; };
_this.strtotime = function( sTime ) { _this.strtotime = function( sTime ) {
var currentTime = sTime?Date.parseDate(sTime, options.formatTime):new Date; var currentTime = sTime?Date.parseDate(sTime, options.formatTime):new Date;
if( !_this.isValidDate(currentTime) ) if( !_this.isValidDate(currentTime) )
currentTime = new Date; currentTime = new Date;
return currentTime; return currentTime;
}; };
_this.str = function() { _this.str = function() {
return _this.currentTime.dateFormat(options.format); return _this.currentTime.dateFormat(options.format);
}; };
}, },
_xdsoft_datetime = new XDSoftDateTime; _xdsoft_datetime = new XDSoftDateTime;
mounth_picker mounth_picker
@ -569,7 +588,7 @@
} }
!stop&&(timer = setTimeout(arguments_callee1,v?v:100)); !stop&&(timer = setTimeout(arguments_callee1,v?v:100));
})(500); })(500);
$([document.body,window]).on('mouseup.xdsoft',function arguments_callee2() { $([document.body,window]).on('mouseup.xdsoft',function arguments_callee2() {
clearTimeout(timer); clearTimeout(timer);
stop = true; stop = true;
@ -604,25 +623,25 @@
.off('mouseup.xdsoft',arguments_callee5); .off('mouseup.xdsoft',arguments_callee5);
}); });
}); });
// base handler - generating a calendar and timepicker // base handler - generating a calendar and timepicker
datetimepicker datetimepicker
.on('xchange.xdsoft',function( event ) { .on('xchange.xdsoft',function( event ) {
var table = '', var table = '',
start = new Date(_xdsoft_datetime.currentTime.getFullYear(),_xdsoft_datetime.currentTime.getMonth(),1), start = new Date(_xdsoft_datetime.currentTime.getFullYear(),_xdsoft_datetime.currentTime.getMonth(),1),
i = 0, i = 0,
today = new Date; today = new Date;
while( start.getDay()!=options.dayOfWeekStart ) while( start.getDay()!=options.dayOfWeekStart )
start.setDate(start.getDate()-1); start.setDate(start.getDate()-1);
//generate calendar //generate calendar
table+='<table><thead><tr>'; table+='<table><thead><tr>';
// days // days
for(var j = 0; j<7; j++) { for(var j = 0; j<7; j++) {
table+='<th>'+options.i18n[options.lang].dayOfWeek[(j+options.dayOfWeekStart)>6?0:j+options.dayOfWeekStart]+'</th>'; table+='<th>'+options.i18n[options.lang].dayOfWeek[(j+options.dayOfWeekStart)>6?0:j+options.dayOfWeekStart]+'</th>';
} }
table+='</tr></thead>'; table+='</tr></thead>';
table+='<tbody><tr>'; table+='<tbody><tr>';
var maxDate = false, minDate = false; var maxDate = false, minDate = false;
@ -638,46 +657,46 @@
while( i<_xdsoft_datetime.currentTime.getDaysInMonth()||start.getDay()!=options.dayOfWeekStart||_xdsoft_datetime.currentTime.getMonth()==start.getMonth() ) { while( i<_xdsoft_datetime.currentTime.getDaysInMonth()||start.getDay()!=options.dayOfWeekStart||_xdsoft_datetime.currentTime.getMonth()==start.getMonth() ) {
classes = []; classes = [];
i++; i++;
d = start.getDate(); y = start.getFullYear(); m = start.getMonth(); d = start.getDate(); y = start.getFullYear(); m = start.getMonth();
classes.push('xdsoft_date'); classes.push('xdsoft_date');
if( ( maxDate!==false && start > maxDate )||( minDate!==false && start < minDate ) ){ if( ( maxDate!==false && start > maxDate )||( minDate!==false && start < minDate ) ){
classes.push('xdsoft_disabled'); classes.push('xdsoft_disabled');
} }
if( _xdsoft_datetime.currentTime.getMonth()!=m ) classes.push('xdsoft_other_month'); if( _xdsoft_datetime.currentTime.getMonth()!=m ) classes.push('xdsoft_other_month');
if( (options.defaultSelect||datetimepicker.data('changed')) && _xdsoft_datetime.currentTime.dateFormat('d.m.Y')==start.dateFormat('d.m.Y') ) { if( (options.defaultSelect||datetimepicker.data('changed')) && _xdsoft_datetime.currentTime.dateFormat('d.m.Y')==start.dateFormat('d.m.Y') ) {
classes.push('xdsoft_current'); classes.push('xdsoft_current');
} }
if( today.dateFormat('d.m.Y')==start.dateFormat('d.m.Y') ) { if( today.dateFormat('d.m.Y')==start.dateFormat('d.m.Y') ) {
classes.push('xdsoft_today'); classes.push('xdsoft_today');
} }
if( start.getDay()==0||start.getDay()==6||~options.weekends.indexOf(start.dateFormat('d.m.Y')) ) { if( start.getDay()==0||start.getDay()==6||~options.weekends.indexOf(start.dateFormat('d.m.Y')) ) {
classes.push('xdsoft_weekend'); classes.push('xdsoft_weekend');
} }
table+='<td data-date="'+d+'" data-month="'+m+'" data-year="'+y+'"'+' class="xdsoft_date '+ classes.join(' ')+'">'+ table+='<td data-date="'+d+'" data-month="'+m+'" data-year="'+y+'"'+' class="xdsoft_date '+ classes.join(' ')+'">'+
'<div>'+d+'</div>'+ '<div>'+d+'</div>'+
'</td>'; '</td>';
if( start.getDay()==options.dayOfWeekStartPrev ) { if( start.getDay()==options.dayOfWeekStartPrev ) {
table+='</tr>'; table+='</tr>';
} }
start.setDate(d+1); start.setDate(d+1);
} }
table+='</tbody></table>'; table+='</tbody></table>';
calendar.html(table); calendar.html(table);
mounth_picker.find('.xdsoft_label span').eq(0).text(options.i18n[options.lang].months[_xdsoft_datetime.currentTime.getMonth()]); mounth_picker.find('.xdsoft_label span').eq(0).text(options.i18n[options.lang].months[_xdsoft_datetime.currentTime.getMonth()]);
mounth_picker.find('.xdsoft_label span').eq(1).text(_xdsoft_datetime.currentTime.getFullYear()); mounth_picker.find('.xdsoft_label span').eq(1).text(_xdsoft_datetime.currentTime.getFullYear());
// generate timebox // generate timebox
var time = '', var time = '',
h = '', h = '',
@ -688,7 +707,7 @@
h = parseInt(now.getHours()); h = parseInt(now.getHours());
now.setMinutes(m); now.setMinutes(m);
m = parseInt(now.getMinutes()); m = parseInt(now.getMinutes());
classes = []; classes = [];
if( (options.maxTime!==false&&_xdsoft_datetime.strtotime(options.maxTime).getTime()<now.getTime())||(options.minTime!==false&&_xdsoft_datetime.strtotime(options.minTime).getTime()>now.getTime())) if( (options.maxTime!==false&&_xdsoft_datetime.strtotime(options.maxTime).getTime()<now.getTime())||(options.minTime!==false&&_xdsoft_datetime.strtotime(options.minTime).getTime()>now.getTime()))
classes.push('xdsoft_disabled'); classes.push('xdsoft_disabled');
@ -698,7 +717,7 @@
classes.push('xdsoft_today'); classes.push('xdsoft_today');
time+= '<div class="xdsoft_time '+classes.join(' ')+'" data-hour="'+h+'" data-minute="'+m+'">'+now.dateFormat(options.formatTime)+'</div>'; time+= '<div class="xdsoft_time '+classes.join(' ')+'" data-hour="'+h+'" data-minute="'+m+'">'+now.dateFormat(options.formatTime)+'</div>';
}; };
if( !options.allowTimes || !$.isArray(options.allowTimes) || !options.allowTimes.length ) { if( !options.allowTimes || !$.isArray(options.allowTimes) || !options.allowTimes.length ) {
for( var i=0,j=0;i<(options.hours12?12:24);i++ ) { for( var i=0,j=0;i<(options.hours12?12:24);i++ ) {
for( j=0;j<60;j+=options.step ) { for( j=0;j<60;j+=options.step ) {
@ -714,18 +733,18 @@
line_time( h,m ); line_time( h,m );
} }
} }
timebox.html(time); timebox.html(time);
var opt = '', var opt = '',
i = 0; i = 0;
for( i = parseInt(options.yearStart,10);i<= parseInt(options.yearEnd,10);i++ ) { for( i = parseInt(options.yearStart,10);i<= parseInt(options.yearEnd,10);i++ ) {
opt+='<div class="xdsoft_option '+(_xdsoft_datetime.currentTime.getFullYear()==i?'xdsoft_current':'')+'" data-value="'+i+'">'+i+'</div>'; opt+='<div class="xdsoft_option '+(_xdsoft_datetime.currentTime.getFullYear()==i?'xdsoft_current':'')+'" data-value="'+i+'">'+i+'</div>';
} }
yearselect.children().eq(0) yearselect.children().eq(0)
.html(opt); .html(opt);
for( i = 0,opt = '';i<= 11;i++ ) { for( i = 0,opt = '';i<= 11;i++ ) {
opt+='<div class="xdsoft_option '+(_xdsoft_datetime.currentTime.getMonth()==i?'xdsoft_current':'')+'" data-value="'+i+'">'+options.i18n[options.lang].months[i]+'</div>'; opt+='<div class="xdsoft_option '+(_xdsoft_datetime.currentTime.getMonth()==i?'xdsoft_current':'')+'" data-value="'+i+'">'+options.i18n[options.lang].months[i]+'</div>';
} }
@ -752,29 +771,29 @@
currentTime = _xdsoft_datetime.currentTime; currentTime = _xdsoft_datetime.currentTime;
if( $this.hasClass('xdsoft_disabled') ) if( $this.hasClass('xdsoft_disabled') )
return false; return false;
currentTime.setFullYear( $this.data('year') ); currentTime.setFullYear( $this.data('year') );
currentTime.setMonth( $this.data('month') ); currentTime.setMonth( $this.data('month') );
currentTime.setDate( $this.data('date') ); currentTime.setDate( $this.data('date') );
datetimepicker.trigger('select.xdsoft',[currentTime]); datetimepicker.trigger('select.xdsoft',[currentTime]);
input.val( _xdsoft_datetime.str() ); input.val( _xdsoft_datetime.str() );
if( (timerclick>1||(options.closeOnDateSelect===true||( options.closeOnDateSelect===0&&!options.timepicker )))&&!options.inline ) { if( (timerclick>1||(options.closeOnDateSelect===true||( options.closeOnDateSelect===0&&!options.timepicker )))&&!options.inline ) {
datetimepicker.trigger('close.xdsoft'); 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')); options.onSelectDate.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
} }
datetimepicker.data('changed',true); datetimepicker.data('changed',true);
datetimepicker.trigger('xchange.xdsoft'); datetimepicker.trigger('xchange.xdsoft');
datetimepicker.trigger('changedatetime.xdsoft'); datetimepicker.trigger('changedatetime.xdsoft');
setTimeout(function(){ setTimeout(function(){
timerclick = 0; timerclick = 0;
},200); },200);
}); });
timebox timebox
.on('click.xdsoft','div',function() { .on('click.xdsoft','div',function() {
var $this = $(this), var $this = $(this),
@ -784,11 +803,11 @@
currentTime.setHours($this.data('hour')); currentTime.setHours($this.data('hour'));
currentTime.setMinutes($this.data('minute')); currentTime.setMinutes($this.data('minute'));
datetimepicker.trigger('select.xdsoft',[currentTime]); datetimepicker.trigger('select.xdsoft',[currentTime]);
datetimepicker.data('input').val( _xdsoft_datetime.str() ); datetimepicker.data('input').val( _xdsoft_datetime.str() );
!options.inline&&datetimepicker.trigger('close.xdsoft'); !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')); options.onSelectTime.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
} }
@ -796,7 +815,7 @@
datetimepicker.trigger('xchange.xdsoft'); datetimepicker.trigger('xchange.xdsoft');
datetimepicker.trigger('changedatetime.xdsoft'); datetimepicker.trigger('changedatetime.xdsoft');
}); });
datetimepicker.mousewheel&&datepicker.mousewheel(function(event, delta, deltaX, deltaY) { datetimepicker.mousewheel&&datepicker.mousewheel(function(event, delta, deltaX, deltaY) {
if( !options.scrollMonth ) if( !options.scrollMonth )
return true; return true;
@ -806,7 +825,7 @@
_xdsoft_datetime.prevMonth(); _xdsoft_datetime.prevMonth();
return false; return false;
}); });
datetimepicker.mousewheel&&timeboxparent.unmousewheel().mousewheel(function(event, delta, deltaX, deltaY) { datetimepicker.mousewheel&&timeboxparent.unmousewheel().mousewheel(function(event, delta, deltaX, deltaY) {
if( !options.scrollTime ) if( !options.scrollTime )
return true; return true;
@ -825,7 +844,7 @@
event.stopPropagation(); event.stopPropagation();
return fl; return fl;
}); });
datetimepicker datetimepicker
.on('changedatetime.xdsoft',function() { .on('changedatetime.xdsoft',function() {
if( options.onChangeDateTime&&options.onChangeDateTime.call ) if( options.onChangeDateTime&&options.onChangeDateTime.call )
@ -835,7 +854,7 @@
if( options.onGenerate&&options.onGenerate.call ) if( options.onGenerate&&options.onGenerate.call )
options.onGenerate.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input')); options.onGenerate.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
}); });
var current_time_index = 0; 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 ) if( !options.scrollInput )
@ -861,7 +880,7 @@
left = offset.left-datetimepicker[0].offsetWidth+datetimepicker.data('input')[0].offsetWidth; left = offset.left-datetimepicker[0].offsetWidth+datetimepicker.data('input')[0].offsetWidth;
datetimepicker.css({ datetimepicker.css({
left:left, left:left,
top:top top:top
}); });
}; };
datetimepicker datetimepicker
@ -877,7 +896,7 @@
$(window) $(window)
.off('resize.xdsoft',setPos) .off('resize.xdsoft',setPos)
.on('resize.xdsoft',setPos); .on('resize.xdsoft',setPos);
if( options.closeOnWithoutClick ) { if( options.closeOnWithoutClick ) {
$([document.body,window]).on('mousedown.xdsoft',function arguments_callee6() { $([document.body,window]).on('mousedown.xdsoft',function arguments_callee6() {
datetimepicker.trigger('close.xdsoft'); datetimepicker.trigger('close.xdsoft');
@ -897,23 +916,23 @@
event.stopPropagation(); event.stopPropagation();
}) })
.data('input',input); .data('input',input);
var timer = 0, var timer = 0,
timer1 = 0; timer1 = 0;
datetimepicker.data('xdsoft_datetime',_xdsoft_datetime); datetimepicker.data('xdsoft_datetime',_xdsoft_datetime);
datetimepicker.setOptions(options); datetimepicker.setOptions(options);
var ct = options.value?options.value:(input&&input.val&&input.val())?input.val():''; var ct = options.value?options.value:(input&&input.val&&input.val())?input.val():'';
if( ct && _xdsoft_datetime.isValidDate(ct = Date.parseDate(ct, options.format)) ) { if( ct && _xdsoft_datetime.isValidDate(ct = Date.parseDate(ct, options.format)) ) {
datetimepicker.data('changed',true); datetimepicker.data('changed',true);
}else }else
ct = ''; ct = '';
_xdsoft_datetime.setCurrentTime( ct?ct:new Date ); _xdsoft_datetime.setCurrentTime( ct?ct:new Date );
datetimepicker.trigger('afterOpen.xdsoft'); datetimepicker.trigger('afterOpen.xdsoft');
input input
.data( 'xdsoft_datetimepicker',datetimepicker ) .data( 'xdsoft_datetimepicker',datetimepicker )
.on('open.xdsoft focusin.xdsoft mousedown.xdsoft',function(event) { .on('open.xdsoft focusin.xdsoft mousedown.xdsoft',function(event) {
@ -928,7 +947,7 @@
},100); },100);
}) })
.on('keydown.xdsoft',function( event ) { .on('keydown.xdsoft',function( event ) {
var val = this.value, var val = this.value,
key = event.which; key = event.which;
switch(true) { switch(true) {
case !!~([ENTER].indexOf(key)): case !!~([ENTER].indexOf(key)):
@ -964,7 +983,7 @@
$(document) $(document)
.off('keydown.xdsoftctrl keyup.xdsoftctrl') .off('keydown.xdsoftctrl keyup.xdsoftctrl')
.on('keydown.xdsoftctrl',function(e) { .on('keydown.xdsoftctrl',function(e) {
if ( e.keyCode == CTRLKEY ) if ( e.keyCode == CTRLKEY )
ctrlDown = true; ctrlDown = true;
}) })
.on('keyup.xdsoftctrl',function(e) { .on('keyup.xdsoftctrl',function(e) {
@ -990,7 +1009,7 @@
this.value = this.defaultValue; this.value = this.defaultValue;
if(!this.value || !datetimepicker.data('xdsoft_datetime').isValidDate(Date.parseDate(this.value, options.format))) if(!this.value || !datetimepicker.data('xdsoft_datetime').isValidDate(Date.parseDate(this.value, options.format)))
datetimepicker.data('changed',false); datetimepicker.data('changed',false);
datetimepicker.data('xdsoft_datetime').setCurrentTime(this.value); datetimepicker.data('xdsoft_datetime').setCurrentTime(this.value);
break; break;
} }
}else{ }else{