Commit 9398c404 authored by Kingdutch's avatar Kingdutch Committed by ronaldtebrake
Browse files

Issue #3214965 by Kingdutch: Fix existence checks in date-picker-init.js

parent 12867543
!function(l){Drupal.behaviors.initDatepicker={attach:function(e,t){if(!function(){try{return document.createEvent("TouchEvent"),1}catch(e){return}}()){var a=l(e),i=l(".form-time"),c=l(".form-date");if(function(){var e=document.createElement("input");e.setAttribute("type","date");var t="not-a-date";return e.setAttribute("value",t),e.value!==t}()&&null!=drupalSettings.socialbase&&null!=drupalSettings.socialbase.datepicker.nativeDatePickFields){var n=drupalSettings.socialbase.datepicker.nativeDatePickFields;"undefined"!==n&&!1!==n&&c.each(function(i){l.each(n,function(e,t){var a=l(this).attr("name");"undefined"!==a&&!1!==a&&a.includes(t)&&c.splice(i,1)})})}a.find(i).once("timePicker").each(function(){i.prop("type","text"),i.timepicker({show2400:!1,scrollDefault:"now",timeFormat:"H:i",step:5}),i.on("changeTime",function(){var e=l("#edit-field-event-date-end-0-value-time");e.val()||e.val(l(this).val())})}),a.find(c).once("datePicker").each(function(){var n=l("#edit-field-event-date-0-value-date"),r=l("#edit-field-event-date-end-0-value-date");c.prop("type","text"),c.datepicker({altFormat:"yy-mm-dd",dateFormat:"yy-mm-dd",onSelect:function(e,t){if(r.val()){var a=new Date(n[0].value).getTime(),i=new Date(r[0].value).getTime();i<a&&r.val(e),i<a&&n.val(e)}else r.val(e)},beforeShowDay:function(e){var t=new Date(n.val()).getTime()-864e5,a=new Date(r.val()).getTime(),i=e.getTime();return t<=i&&i<=a?[!0,"bg-info",""]:[!0,"",""]}})})}}}}(jQuery);
\ No newline at end of file
!function(c){Drupal.behaviors.initDatepicker={attach:function(e,t){if(!function(){try{return document.createEvent("TouchEvent"),!0}catch(e){return!1}}()){var e=c(e),a=c(".form-time"),i=c(".form-date");if(function(){var e=document.createElement("input");e.setAttribute("type","date");var t="not-a-date";return e.setAttribute("value",t),e.value!==t}()&&void 0!==drupalSettings.socialbase&&void 0!==drupalSettings.socialbase.datepicker&&void 0!==drupalSettings.socialbase.datepicker.nativeDatePickFields&&Array.isArray(drupalSettings.socialbase.datepicker.nativeDatePickFields)){const n=drupalSettings.socialbase.datepicker.nativeDatePickFields;i=i.filter(function(){const e=c(this),t=e.attr("name");return!t||!n.some(e=>t.includes(e))})}e.find(a).once("timePicker").each(function(){a.prop("type","text"),a.timepicker({show2400:!1,scrollDefault:"now",timeFormat:"H:i",step:5}),a.on("changeTime",function(){var e=c("#edit-field-event-date-end-0-value-time");e.val()||e.val(c(this).val())})}),e.find(i).once("datePicker").each(function(){var n=c("#edit-field-event-date-0-value-date"),r=c("#edit-field-event-date-end-0-value-date");i.prop("type","text"),i.datepicker({altFormat:"yy-mm-dd",dateFormat:"yy-mm-dd",onSelect:function(e,t){var a,i;r.val()?(a=new Date(n[0].value).getTime(),(i=new Date(r[0].value).getTime())<a&&r.val(e),i<a&&n.val(e)):r.val(e)},beforeShowDay:function(e){var t=new Date(n.val()).getTime()-864e5,a=new Date(r.val()).getTime(),e=e.getTime();return t<=e&&e<=a?[!0,"bg-info",""]:[!0,"",""]}})})}}}}(jQuery);
\ No newline at end of file
......@@ -10,26 +10,29 @@
var $time = $('.form-time');
var $date = $('.form-date');
// We want to use the native date picker
// when the browser supports this on specific fields.
if (browserSupportsDateInput()) {
if (drupalSettings.socialbase != undefined &&
drupalSettings.socialbase.datepicker.nativeDatePickFields != undefined) {
// Get the fields which should use the native picker.
var nativePicker = drupalSettings.socialbase.datepicker.nativeDatePickFields;
if (nativePicker !== typeof undefined && nativePicker !== false) {
$date.each(function (dateIndex) {
$.each(nativePicker, function (index, value) {
var nameAttr = $(this).attr('name');
// If the name attribute contains the field name from
// the settings, remove it from the date array.
if (nameAttr !== typeof undefined && nameAttr !== false && nameAttr.includes(value)) {
$date.splice(dateIndex, 1);
}
});
});
// We want to use the native date picker when the browser supports this
// on specific fields and fields have been defined as requiring the
// native date picker.
if (
browserSupportsDateInput() &&
typeof drupalSettings.socialbase !== "undefined" &&
typeof drupalSettings.socialbase.datepicker !== "undefined" &&
typeof drupalSettings.socialbase.datepicker.nativeDatePickFields !== "undefined" &&
Array.isArray(drupalSettings.socialbase.datepicker.nativeDatePickFields)
) {
// Filter out any date elements where the name attribute contains any
// of the strings in the array of field names to exclude.
const nativeFieldNames = drupalSettings.socialbase.datepicker.nativeDatePickFields;
$date = $date.filter(function () {
const $dateEl = $(this);
const elName = $dateEl.attr('name');
// If it has no name then keep it.
if (!elName) {
return true;
}
}
// Keep it if it has no match to the configured excluded fields.
return !nativeFieldNames.some(excludedName => elName.includes(excludedName));
})
}
// TIME
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment