1(function ($) { 2 "use strict"; 3 4 $(document).ready(function () { 5 initDateRestrict(); 6 function initDateRestrict() { 7 $("input.wpcf7-date_restrict").each(function () { 8 if (!$(this).hasClass('hasDatepicker')) { 9 readnumber_cf7_restrict_date($(this)); 10 } 11 }); 12 } 13 $(window).on('elementor/popup/show', function (event, id, obj) { 14 initDateRestrict(); 15 }); 16 $("body").on("change", "input.wpcf7-date_restrict", function (e) { 17 $("input.wpcf7-date_restrict").each(function (index) { 18 readnumber_cf7_restrict_date($(this)); 19 }); 20 }) 21 function cover_format(date_format = "") { 22 return date_format.replaceAll('y', 'yy').toUpperCase(); 23 } 24 function readnumber_cf7_restrict_date(el) { 25 var min = el.data("min"); 26 var max = el.data("max"); 27 var weekdays_data = el.data("weekdays"); 28 var special_data = el.data("special"); 29 var format_data = el.data("format"); 30 var sync_min = el.data("sync_min"); 31 var sync_max = el.data("sync_max"); 32 var sync_min_number = el.data("sync_min_number"); 33 var sync_max_number = el.data("sync_max_number"); 34 var current_date = new Date(); 35 var minDate = ""; 36 var maxDate = ""; 37 var format = "yy-mm-dd"; 38 var weekdays = [0, 1, 2, 3, 4, 5, 6]; 39 var special = []; 40 if (min !== undefined && min != "") { 41 if (min.includes("current_date", 0)) { 42 var datas_min = min.split("|"); 43 if (datas_min.length > 3) { 44 switch (datas_min[3]) { 45 case 'd': 46 if (datas_min[1] == "+") { 47 minDate = new Date(current_date.getFullYear(), current_date.getMonth(), current_date.getDate() + parseInt(datas_min[2])); 48 } else { 49 minDate = new Date(current_date.getFullYear(), current_date.getMonth(), current_date.getDate() - parseInt(datas_min[2])); 50 } 51 break; 52 case 'm': 53 if (datas_min[1] == "+") { 54 minDate = new Date(current_date.getFullYear(), current_date.getMonth() + parseInt(datas_min[2]), current_date.getDate()); 55 } else { 56 minDate = new Date(current_date.getFullYear(), current_date.getMonth() - parseInt(datas_min[2]), current_date.getDate()); 57 } 58 break; 59 case 'y': 60 if (datas_min[1] == "+") { 61 minDate = new Date(current_date.getFullYear() + parseInt(datas_min[2]), current_date.getMonth(), current_date.getDate()); 62 } else { 63 minDate = new Date(current_date.getFullYear() - parseInt(datas_min[2]), current_date.getMonth(), current_date.getDate()); 64 } 65 break; 66 } 67 } else { 68 minDate = 0; 69 } 70 } else { 71 minDate = new Date(min); 72 } 73 } 74 if (max !== undefined && max != "") { 75 if (max.includes("current_date", 0)) { 76 var datas_max = max.split("|"); 77 if (datas_max.length > 3) { 78 switch (datas_max[3]) { 79 case 'd': 80 if (datas_max[1] == "+") { 81 maxDate = new Date(current_date.getFullYear(), current_date.getMonth(), current_date.getDate() + parseInt(datas_max[2])); 82 } else { 83 maxDate = new Date(current_date.getFullYear(), current_date.getMonth(), current_date.getDate() - parseInt(datas_max[2])); 84 } 85 break; 86 case 'm': 87 if (datas_max[1] == "+") { 88 maxDate = new Date(current_date.getFullYear(), current_date.getMonth() + parseInt(datas_max[2]), current_date.getDate()); 89 } else { 90 maxDate = new Date(current_date.getFullYear(), current_date.getMonth() - parseInt(datas_max[2]), current_date.getDate()); 91 } 92 break; 93 case 'y': 94 if (datas_max[1] == "+") { 95 maxDate = new Date(current_date.getFullYear() + parseInt(datas_max[2]), current_date.getMonth(), current_date.getDate()); 96 } else { 97 maxDate = new Date(current_date.getFullYear() - parseInt(datas_max[2]), current_date.getMonth(), current_date.getDate()); 98 } 99 break; 100 } 101 } else { 102 maxDate = 0; 103 } 104 } else { 105 maxDate = new Date(max); 106 } 107 } 108 if (weekdays_data !== undefined && weekdays_data != "allday") { 109 weekdays = []; 110 weekdays_data = weekdays_data.toString(); 111 weekdays = weekdays_data.split('|'); 112 weekdays = weekdays.map(Number); 113 } 114 if (special_data !== undefined && special_data != "") { 115 special_data = special_data.toString(); 116 if (special_data.includes("to")) { 117 var range_dates = special_data.split('to'); 118 special = getDatesBetween(range_dates[0], range_dates[1]); 119 } else { 120 special = special_data.split('|'); 121 } 122 } 123 if (format_data !== undefined && format_data != "") { 124 format = format_data; 125 } 126 el.datepicker({ 127 minDate: minDate, 128 maxDate: maxDate, 129 dateFormat: format, 130 changeMonth: true, 131 changeYear: true, 132 onSelect: function (dateStr) { 133 134 var data_fm = cover_format(format); 135 dateStr = moment(dateStr, data_fm).format('YYYY-MM-DD'); 136 dateStr = new Date(dateStr); 137 var dateStr1_max = new Date(dateStr); 138 if (sync_min !== undefined && sync_min != "" && dateStr !== undefined) { 139 $(".wpcf7-date_restrict.restrict_date_" + sync_min).datepicker('option', 'maxDate', dateStr); 140 } 141 if (sync_max !== undefined && sync_max != "" && dateStr !== undefined) { 142 if (sync_min_number != "" && sync_min_number !== undefined) { 143 dateStr = dateStr.setDate(dateStr.getDate() + parseInt(sync_min_number)); 144 dateStr = new Date(dateStr); 145 } 146 if (sync_max_number != "" && sync_max_number !== undefined) { 147 dateStr1_max.setDate(dateStr1_max.getDate() + parseInt(sync_max_number)); 148 $(".wpcf7-date_restrict.restrict_date_" + sync_max).datepicker('option', 'maxDate', dateStr1_max); 149 } 150 $(".wpcf7-date_restrict.restrict_date_" + sync_max).datepicker('option', 'minDate', dateStr); 151 } 152 $(this).change(); 153 154 }, 155 beforeShowDay: function (date) { 156 var day = date.getDay(); 157 if (jQuery.inArray(day, weekdays) > -1) { 158 //check special 159 if (special.length > 0) { 160 var sdate = moment(date).format('YYYY-MM-DD'); 161 if ($.inArray(sdate, special) !== -1) { 162 return [false]; 163 } else { 164 return [true]; 165 } 166 } else { 167 return [true]; 168 } 169 } else { 170 //check special 171 if (special.length > 0) { 172 var sdate = moment(date).format('YYYY-MM-DD'); 173 if ($.inArray(sdate, special) !== -1) { 174 return [true]; 175 } else { 176 return [false]; 177 } 178 } else { 179 return [false]; 180 } 181 } 182 } 183 }); 184 el.datepicker("refresh"); 185 } 186 function getDatesBetween(startDate, endDate) { 187 const dates = []; 188 let current = new Date(startDate); 189 const last = new Date(endDate); 190 191 while (current <= last) { 192 dates.push(current.toISOString().split('T')[0]); // format YYYY-MM-DD 193 current.setDate(current.getDate() + 1); 194 } 195 return dates; 196 } 197 }) 198})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.