From 29f07a3c6fd1d6000dd479248d935f7033e3300d Mon Sep 17 00:00:00 2001 From: Aether Date: Thu, 8 Feb 2018 02:11:47 +0800 Subject: [PATCH 1/4] UPDATE: disable date in range --- src/js/calendar.js | 60 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/src/js/calendar.js b/src/js/calendar.js index 5d5c787..dbe5e75 100644 --- a/src/js/calendar.js +++ b/src/js/calendar.js @@ -306,7 +306,8 @@ dayIndex = 0 + (p.params.firstDay - 1), today = new Date().setHours(0,0,0,0), minDate = p.params.minDate ? new Date(p.params.minDate).getTime() : null, - maxDate = p.params.maxDate ? new Date(p.params.maxDate).getTime() : null; + maxDate = p.params.maxDate ? new Date(p.params.maxDate).getTime() : null, + disabled; if (p.value && p.value.length) { for (i = 0; i < p.value.length; i++) { @@ -350,6 +351,11 @@ if ((minDate && dayDate < minDate) || (maxDate && dayDate > maxDate)) { addClass += ' picker-calendar-day-disabled'; } + if (p.params.disabled) { + if (p.dateInRange(dayDate, p.params.disabled)) { + addClass += ' picker-calendar-day-disabled'; + } + } dayDate = new Date(dayDate); var dayYear = dayDate.getFullYear(); @@ -579,6 +585,57 @@ p.prevYear = function () { p.setYearMonth(p.currentYear - 1); }; + + // Scan Dates Range + p.dateInRange = function (dayDate, range) { + var match = false; + var i; + if (!range) return false; + if ($.isArray(range)) { + for (i = 0; i < range.length; i ++) { + if (range[i].from || range[i].to) { + if (range[i].from && range[i].to) { + if ((dayDate <= new Date(range[i].to).getTime()) && (dayDate >= new Date(range[i].from).getTime())) { + match = true; + } + } + else if (range[i].from) { + if (dayDate >= new Date(range[i].from).getTime()) { + match = true; + } + } + else if (range[i].to) { + if (dayDate <= new Date(range[i].to).getTime()) { + match = true; + } + } + } else if (dayDate === new Date(range[i]).getTime()) { + match = true; + } + } + } + else if (range.from || range.to) { + if (range.from && range.to) { + if ((dayDate <= new Date(range.to).getTime()) && (dayDate >= new Date(range.from).getTime())) { + match = true; + } + } + else if (range.from) { + if (dayDate >= new Date(range.from).getTime()) { + match = true; + } + } + else if (range.to) { + if (dayDate <= new Date(range.to).getTime()) { + match = true; + } + } + } + else if (typeof range === 'function') { + match = range(new Date(dayDate)); + } + return match; + }; // HTML Layout @@ -847,6 +904,7 @@ direction: 'horizontal', // or 'vertical' minDate: null, maxDate: null, + disabled: null, touchMove: true, animate: true, closeOnSelect: true, From 7419c9f301e6b1a38c13cc0b2ea851f1df13d271 Mon Sep 17 00:00:00 2001 From: Aether Date: Thu, 8 Feb 2018 02:12:19 +0800 Subject: [PATCH 2/4] UPDATE: identify weekend properly --- src/js/calendar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/calendar.js b/src/js/calendar.js index dbe5e75..4f2f7f8 100644 --- a/src/js/calendar.js +++ b/src/js/calendar.js @@ -344,7 +344,7 @@ // Selected if (currentValues.indexOf(dayDate) >= 0) addClass += ' picker-calendar-day-selected'; // Weekend - if (p.params.weekendDays.indexOf(col - 1) >= 0) { + if (col>5) { addClass += ' picker-calendar-day-weekend'; } // Disabled From 1011485010ecd73828d9a3b6caa909d8a3e1be84 Mon Sep 17 00:00:00 2001 From: Aether Date: Thu, 8 Feb 2018 19:26:54 +0800 Subject: [PATCH 3/4] UPDATE disable date --- src/js/calendar.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/js/calendar.js b/src/js/calendar.js index 4f2f7f8..a83b1bf 100644 --- a/src/js/calendar.js +++ b/src/js/calendar.js @@ -351,8 +351,9 @@ if ((minDate && dayDate < minDate) || (maxDate && dayDate > maxDate)) { addClass += ' picker-calendar-day-disabled'; } + // Disable certain date in range or list. if (p.params.disabled) { - if (p.dateInRange(dayDate, p.params.disabled)) { + if ( p.params.disabled.includes(formatDate(dayDate)) ) { addClass += ' picker-calendar-day-disabled'; } } From 97c1ea9b567ec68a47f3781ab98d9add92d3fc76 Mon Sep 17 00:00:00 2001 From: Aether Date: Thu, 8 Feb 2018 19:31:50 +0800 Subject: [PATCH 4/4] UPDATE disable date - delete useless code --- src/js/calendar.js | 51 ---------------------------------------------- 1 file changed, 51 deletions(-) diff --git a/src/js/calendar.js b/src/js/calendar.js index a83b1bf..a3dd11b 100644 --- a/src/js/calendar.js +++ b/src/js/calendar.js @@ -586,57 +586,6 @@ p.prevYear = function () { p.setYearMonth(p.currentYear - 1); }; - - // Scan Dates Range - p.dateInRange = function (dayDate, range) { - var match = false; - var i; - if (!range) return false; - if ($.isArray(range)) { - for (i = 0; i < range.length; i ++) { - if (range[i].from || range[i].to) { - if (range[i].from && range[i].to) { - if ((dayDate <= new Date(range[i].to).getTime()) && (dayDate >= new Date(range[i].from).getTime())) { - match = true; - } - } - else if (range[i].from) { - if (dayDate >= new Date(range[i].from).getTime()) { - match = true; - } - } - else if (range[i].to) { - if (dayDate <= new Date(range[i].to).getTime()) { - match = true; - } - } - } else if (dayDate === new Date(range[i]).getTime()) { - match = true; - } - } - } - else if (range.from || range.to) { - if (range.from && range.to) { - if ((dayDate <= new Date(range.to).getTime()) && (dayDate >= new Date(range.from).getTime())) { - match = true; - } - } - else if (range.from) { - if (dayDate >= new Date(range.from).getTime()) { - match = true; - } - } - else if (range.to) { - if (dayDate <= new Date(range.to).getTime()) { - match = true; - } - } - } - else if (typeof range === 'function') { - match = range(new Date(dayDate)); - } - return match; - }; // HTML Layout