我的一位朋友有一个Drupal 6网站,用户可以在此选择未来的交付日期。最近,有几位顾客选择了周末和假期作为交货日期,我的朋友希望阻止他们这样做。
这是我们目前用来阻止周末的代码。有人可以帮助修改它以阻止圣诞节和除夕吗?
非常感谢!
drupal_add_js("
Drupal.behaviors.date_popup = function (context) {
for (var id in Drupal.settings.datePopup) {
$('#'+ id).bind('focus', Drupal.settings.datePopup[id], function(e) {
if (!$(this).hasClass('date-popup-init')) {
var datePopup = e.data;
// CUSTOM
datePopup.settings.beforeShowDay = function(date) {
var day = date.getDay();
return [(day != 0 && day != 6), ''];
}
// Explicitely filter the methods we accept.
switch (datePopup.func) {
case 'datepicker':
$(this)
.datepicker(datePopup.settings)
.addClass('date-popup-init')
$(this).click(function(){
$(this).focus();
});
break;
case 'timeEntry':
$(this)
.timeEntry(datePopup.settings)
.addClass('date-popup-init')
$(this).click(function(){
$(this).focus();
});
break;
}
}
});
}
};
",'inline');

更新:
我最终做了以下工作,这符合我们的需求:
drupal_add_js("
Drupal.behaviors.date_popup = function (context) {
for (var id in Drupal.settings.datePopup) {
$('#'+ id).bind('focus', Drupal.settings.datePopup[id], function(e) {
if (!$(this).hasClass('date-popup-init')) {
var datePopup = e.data;
// CUSTOM
datePopup.settings.beforeShowDay = function(date) {
var day = date.getDay(), Sunday = 0, Monday = 1, Tuesday = 2, Wednesday = 3, Thursday = 4, Friday = 5, Saturday = 6;
var closedDates = [[12, 31, 2015], [12, 25, 2015]];
var closedDays = [[Saturday], [Sunday]];
for (var i = 0; i < closedDays.length; i++) {
if (day == closedDays[i][0]) {
return [false];
}
}
for (i = 0; i < closedDates.length; i++) {
if (date.getMonth() == closedDates[i][0] - 1 &&
date.getDate() == closedDates[i][1] &&
date.getFullYear() == closedDates[i][2]) {
return [false];
}
}
return [true];
}
// Explicitely filter the methods we accept.
switch (datePopup.func) {
case 'datepicker':
$(this)
.datepicker(datePopup.settings)
.addClass('date-popup-init')
$(this).click(function(){
$(this).focus();
});
break;
case 'timeEntry':
$(this)
.timeEntry(datePopup.settings)
.addClass('date-popup-init')
$(this).click(function(){
$(this).focus();
});
break;
}
}
});
}
};
",'inline');
&#13;