Fix bug with defaultDate option

This commit is contained in:
Valeriy 2015-04-22 11:24:52 +05:00
parent ba7d4ef6f5
commit 0b9de1cac0
5 changed files with 109 additions and 105 deletions

View File

@ -1,6 +1,6 @@
{
"name":"datetimepicker",
"version":"2.4.1",
"version":"2.4.2",
"main": [
"jquery.datetimepicker.js",
"jquery.datetimepicker.css"

View File

@ -1,6 +1,6 @@
{
"name": "datetimepicker",
"version": "2.4.1",
"version": "2.4.2",
"title": "jQuery Date and Time picker",
"description": "jQuery plugin for date, time, or datetime manipulation in form",
"keywords": [

View File

@ -77,7 +77,8 @@ $('.some_class').datetimepicker();
$('#default_datetimepicker').datetimepicker({
formatTime:'H:i',
formatDate:'d.m.Y',
defaultDate:'8.12.1986', // it's my birthday
//defaultDate:'8.12.1986', // it's my birthday
defaultDate:'+03.01.1970', // it's my birthday
defaultTime:'10:00',
timepickerScrollbar:false
});
@ -133,7 +134,7 @@ $('#destroy').click(function(){
}
});
var logic = function( currentDateTime ){
if( currentDateTime.getDay()==6 ){
if (currentDateTime && currentDateTime.getDay() == 6){
this.setOptions({
minTime:'11:00'
});

View File

@ -1,9 +1,9 @@
/**
* @preserve jQuery DateTimePicker plugin v2.4.1
* @preserve jQuery DateTimePicker plugin v2.4.2
* @homepage http://xdsoft.net/jqplugins/datetimepicker/
* (c) 2014, Chupurnov Valeriy.
*/
/*global document,window,jQuery,setTimeout,clearTimeout*/
/*global document,window,jQuery,setTimeout,clearTimeout,HighlightedDate,getCurrentValue*/
(function ($) {
'use strict';
var default_options = {
@ -445,7 +445,7 @@
monthChangeSpinner: true,
closeOnDateSelect: false,
closeOnTimeSelect: false,
closeOnTimeSelect: true,
closeOnWithoutClick: true,
closeOnInputClick: true,
@ -831,6 +831,48 @@
});
datetimepicker.setOptions = function (_options) {
var highlightedDates = {},
getCaretPos = function (input) {
try {
if (document.selection && document.selection.createRange) {
var range = document.selection.createRange();
return range.getBookmark().charCodeAt(2) - 2;
}
if (input.setSelectionRange) {
return input.selectionStart;
}
} catch (e) {
return 0;
}
},
setCaretPos = function (node, pos) {
node = (typeof node === "string" || node instanceof String) ? document.getElementById(node) : node;
if (!node) {
return false;
}
if (node.createTextRange) {
var textRange = node.createTextRange();
textRange.collapse(true);
textRange.moveEnd('character', pos);
textRange.moveStart('character', pos);
textRange.select();
return true;
}
if (node.setSelectionRange) {
node.setSelectionRange(pos, pos);
return true;
}
return false;
},
isValidValue = function (mask, value) {
var reg = mask
.replace(/([\[\]\/\{\}\(\)\-\.\+]{1})/g, '\\$1')
.replace(/_/g, '{digit+}')
.replace(/([0-9]{1})/g, '{digit$1}')
.replace(/\{digit([0-9]{1})\}/g, '[0-$1_]{1}')
.replace(/\{digit[\+]\}/g, '[0-9_]{1}');
return (new RegExp(reg)).test(value);
};
options = $.extend(true, {}, options, _options);
if (_options.allowTimes && $.isArray(_options.allowTimes) && _options.allowTimes.length) {
@ -842,13 +884,13 @@
}
if (_options.highlightedDates && $.isArray(_options.highlightedDates) && _options.highlightedDates.length) {
var highlightedDates = new Object();
$.each(_options.highlightedDates, function (index, value) {
var splitData = $.map(value.split(','), $.trim),
exDesc,
hDate = new HighlightedDate(Date.parseDate(splitData[0], options.formatDate), splitData[1], splitData[2]), // date, desc, style
keyDate = hDate.date.dateFormat(options.formatDate);
if(keyDate in highlightedDates) {
var exDesc = highlightedDates[keyDate].desc;
if (highlightedDates[keyDate] !== undefined) {
exDesc = highlightedDates[keyDate].desc;
if (exDesc && exDesc.length && hDate.desc && hDate.desc.length) {
highlightedDates[keyDate].desc = exDesc + "\n" + hDate.desc;
}
@ -861,20 +903,23 @@
}
if (_options.highlightedPeriods && $.isArray(_options.highlightedPeriods) && _options.highlightedPeriods.length) {
var highlightedDates = $.extend(true, [], options.highlightedDates);
highlightedDates = $.extend(true, [], options.highlightedDates);
$.each(_options.highlightedPeriods, function (index, value) {
var splitData = $.map(value.split(','), $.trim),
dateTest = Date.parseDate(splitData[0], options.formatDate), // start date
dateEnd = Date.parseDate(splitData[1], options.formatDate),
desc = splitData[2],
hDate,
keyDate,
exDesc,
style = splitData[3];
while (dateTest <= dateEnd) {
var hDate = new HighlightedDate(dateTest, desc, style),
hDate = new HighlightedDate(dateTest, desc, style);
keyDate = dateTest.dateFormat(options.formatDate);
dateTest.setDate(dateTest.getDate() + 1);
if(keyDate in highlightedDates) {
var exDesc = highlightedDates[keyDate].desc;
if (highlightedDates[keyDate] !== undefined) {
exDesc = highlightedDates[keyDate].desc;
if (exDesc && exDesc.length && hDate.desc && hDate.desc.length) {
highlightedDates[keyDate].desc = exDesc + "\n" + hDate.desc;
}
@ -958,48 +1003,6 @@
.css('visibility', !options.nextButton ? 'hidden' : 'visible');
if (options.mask) {
var e,
getCaretPos = function (input) {
try {
if (document.selection && document.selection.createRange) {
var range = document.selection.createRange();
return range.getBookmark().charCodeAt(2) - 2;
}
if (input.setSelectionRange) {
return input.selectionStart;
}
} catch (e) {
return 0;
}
},
setCaretPos = function (node, pos) {
node = (typeof node === "string" || node instanceof String) ? document.getElementById(node) : node;
if (!node) {
return false;
}
if (node.createTextRange) {
var textRange = node.createTextRange();
textRange.collapse(true);
textRange.moveEnd('character', pos);
textRange.moveStart('character', pos);
textRange.select();
return true;
}
if (node.setSelectionRange) {
node.setSelectionRange(pos, pos);
return true;
}
return false;
},
isValidValue = function (mask, value) {
var reg = mask
.replace(/([\[\]\/\{\}\(\)\-\.\+]{1})/g, '\\$1')
.replace(/_/g, '{digit+}')
.replace(/([0-9]{1})/g, '{digit$1}')
.replace(/\{digit([0-9]{1})\}/g, '[0-$1_]{1}')
.replace(/\{digit[\+]\}/g, '[0-9_]{1}');
return (new RegExp(reg)).test(value);
};
input.off('keydown.xdsoft');
if (options.mask === true) {
@ -1085,7 +1088,7 @@
// parse the numbers as 0312 => 03:12
if (!options.datepicker && options.timepicker && splittedHours >= 0 && splittedHours < 24 && splittedMinutes >= 0 && splittedMinutes < 60) {
$(this).val([splittedHours, splittedMinutes].map(function (item) {
return item > 9 ? item : '0' + item
return item > 9 ? item : '0' + item;
}).join(':'));
} else {
$(this).val((_xdsoft_datetime.now()).dateFormat(options.format));
@ -1149,7 +1152,7 @@
time;
if (!norecursion && options.defaultDate) {
date = _this.strToDate(options.defaultDate);
date = _this.strToDateTime(options.defaultDate);
d.setFullYear(date.getFullYear());
d.setMonth(date.getMonth());
d.setDate(date.getDate());
@ -1164,7 +1167,6 @@
d.setHours(time.getHours());
d.setMinutes(time.getMinutes());
}
return d;
};
@ -1266,7 +1268,7 @@
}
if (tmpDate && tmpDate[2]) {
timeOffset = tmpDate[2].getTime() - (tmpDate[2].getTimezoneOffset()) * 60000;
currentTime = new Date((_xdsoft_datetime.now()).getTime() + parseInt(tmpDate[1] + '1', 10) * timeOffset);
currentTime = new Date((_this.now(true)).getTime() + parseInt(tmpDate[1] + '1', 10) * timeOffset);
} else {
currentTime = sDateTime ? Date.parseDate(sDateTime, options.format) : _this.now();
}
@ -1283,7 +1285,7 @@
return sDate;
}
var currentTime = sDate ? Date.parseDate(sDate, options.formatDate) : _this.now(true);
var currentTime = sDate ? Date.parse(sDate, options.formatDate) : _this.now(true);
if (!_this.isValidDate(currentTime)) {
currentTime = _this.now(true);
}
@ -1401,6 +1403,7 @@
today = _xdsoft_datetime.now(),
maxDate = false,
minDate = false,
hDate,
d,
y,
m,
@ -1480,12 +1483,12 @@
classes.push('xdsoft_today');
}
if (start.getDay() === 0 || start.getDay() === 6 || ~options.weekends.indexOf(start.dateFormat(options.formatDate))) {
if (start.getDay() === 0 || start.getDay() === 6 || options.weekends.indexOf(start.dateFormat(options.formatDate)) !== -1) {
classes.push('xdsoft_weekend');
}
if (start.dateFormat(options.formatDate) in options.highlightedDates) {
var hDate = options.highlightedDates[start.dateFormat(options.formatDate)];
if (options.highlightedDates[start.dateFormat(options.formatDate)] !== undefined) {
hDate = options.highlightedDates[start.dateFormat(options.formatDate)];
classes.push(hDate.style === undefined ? 'xdsoft_highlighted_default' : hDate.style);
description = hDate.desc === undefined ? '' : hDate.desc;
}
@ -1525,12 +1528,12 @@
h = '';
m = '';
line_time = function line_time(h, m) {
var now = _xdsoft_datetime.now();
var now = _xdsoft_datetime.now(), optionDateTime, current_time;
now.setHours(h);
h = parseInt(now.getHours(), 10);
now.setMinutes(m);
m = parseInt(now.getMinutes(), 10);
var optionDateTime = new Date(_xdsoft_datetime.currentTime);
optionDateTime = new Date(_xdsoft_datetime.currentTime);
optionDateTime.setHours(h);
optionDateTime.setMinutes(m);
classes = [];
@ -1538,7 +1541,7 @@
classes.push('xdsoft_disabled');
}
var current_time = new Date(_xdsoft_datetime.currentTime);
current_time = new Date(_xdsoft_datetime.currentTime);
current_time.setHours(parseInt(_xdsoft_datetime.currentTime.getHours(), 10));
current_time.setMinutes(Math[options.roundTime](_xdsoft_datetime.currentTime.getMinutes() / options.step) * options.step);
@ -1582,7 +1585,7 @@
yearselect.children().eq(0)
.html(opt);
for (i = parseInt(options.monthStart), opt = ''; i <= parseInt(options.monthEnd); i += 1) {
for (i = parseInt(options.monthStart, 10), opt = ''; i <= parseInt(options.monthEnd, 10); i += 1) {
opt += '<div class="xdsoft_option ' + (_xdsoft_datetime.currentTime.getMonth() === i ? 'xdsoft_current' : '') + '" data-value="' + i + '">' + options.i18n[options.lang].months[i] + '</div>';
}
monthselect.children().eq(0).html(opt);
@ -1823,7 +1826,6 @@
datetimepicker.setOptions(options);
function getCurrentValue() {
var ct = false, time;
if (options.startDate) {
@ -1833,7 +1835,7 @@
if (ct) {
ct = _xdsoft_datetime.strToDateTime(ct);
} else if (options.defaultDate) {
ct = _xdsoft_datetime.strToDate(options.defaultDate);
ct = _xdsoft_datetime.strToDateTime(options.defaultDate);
if (options.defaultTime) {
time = _xdsoft_datetime.strtotime(options.defaultTime);
ct.setHours(time.getHours());
@ -1914,7 +1916,7 @@
}
});
return this.each(function () {
var datetimepicker = $(this).data('xdsoft_datetimepicker');
var datetimepicker = $(this).data('xdsoft_datetimepicker'), $input;
if (datetimepicker) {
if ($.type(opt) === 'string') {
switch (opt) {
@ -1939,7 +1941,7 @@
datetimepicker.data('xdsoft_datetime').setCurrentTime(this.value);
break;
case 'validate':
var $input = datetimepicker.data('input');
$input = datetimepicker.data('input');
$input.trigger('blur.xdsoft');
break;
}
@ -1962,10 +1964,11 @@
}(jQuery));
function HighlightedDate(date, desc, style) {
"use strict";
this.date = date;
this.desc = desc;
this.style = style;
};
}
(function () {

View File

@ -1,6 +1,6 @@
{
"name": "jquery-datetimepicker",
"version": "2.4.0",
"version": "2.4.2",
"description": "jQuery Plugin DateTimePicker it is DatePicker and TimePicker in one",
"main": "jquery.datetimepicker.js",
"scripts": {