PageSourceSearch

http://brassmusic.com.au/wp-content/plugins/conditional-checkout-f…/assets/js/fme-ccfw-datepicker.js?ver=2.1.2

js brassmusic.com.au collected 2026-10-08 06:55:55 UTC 7,129 bytes, 239 lines download raw bytes

1/**
2 * jQuery UI datepicker init for FME date_picker fields (A2 advanced settings).
3 */
4(function ($) {
5  'use strict';
6
7  function parseConfig($input) {
8    var raw = $input.attr('data-fme-datepicker-config');
9    if (!raw) {
10      return {};
11    }
12    try {
13      return JSON.parse(raw);
14    } catch (e) {
15      return {};
16    }
17  }
18
19  function buildBeforeShowDay(config) {
20    var disabledDays = config.disabledDays || [];
21    var disabledDates = config.disabledDates || [];
22
23    if (!disabledDays.length && !disabledDates.length) {
24      return null;
25    }
26
27    return function (date) {
28      var day = date.getDay();
29      if (disabledDays.indexOf(day) !== -1) {
30        return [false, ''];
31      }
32
33      if (disabledDates.length) {
34        var y = date.getFullYear();
35        var m = ('0' + (date.getMonth() + 1)).slice(-2);
36        var d = ('0' + date.getDate()).slice(-2);
37        var iso = y + '-' + m + '-' + d;
38        if (disabledDates.indexOf(iso) !== -1) {
39          return [false, ''];
40        }
41      }
42
43      return [true, ''];
44    };
45  }
46
47  function buildYearRangeBeforeShow(config) {
48    var minYear = config.yearRangeMinYear;
49    var maxYear = config.yearRangeMaxYear;
50    if (!minYear || !maxYear) {
51      return null;
52    }
53
54    return function (input, inst) {
55      var now = new Date();
56      var currentYear = now.getFullYear();
57      var currentMonth = now.getMonth();
58      var targetYear = currentYear;
59      var targetMonth = currentMonth;
60
61      if (currentYear < minYear) {
62        targetYear = minYear;
63        targetMonth = 0;
64      } else if (currentYear > maxYear) {
65        targetYear = maxYear;
66        targetMonth = 11;
67      }
68
69      inst.drawYear = targetYear;
70      inst.selectedYear = targetYear;
71      inst.drawMonth = targetMonth;
72      inst.selectedMonth = targetMonth;
73    };
74  }
75
76  function isDateBeforeEffectiveBound(date, bound, dateFormat) {
77    if (bound === undefined || bound === null || bound === '') {
78      return false;
79    }
80    if (bound === 0 || bound === '0') {
81      var today = new Date();
82      today.setHours(0, 0, 0, 0);
83      return date.getTime() < today.getTime();
84    }
85    if (window.fmeCcfwDatepickerConfig && typeof window.fmeCcfwDatepickerConfig.resolveDefaultDateOffset === 'function') {
86      var resolved = window.fmeCcfwDatepickerConfig.resolveDefaultDateOffset(String(bound), null, dateFormat || 'yy-mm-dd');
87      if (resolved) {
88        var parts = resolved.split('-');
89        if (parts.length === 3) {
90          var boundDate = new Date(parseInt(parts[0], 10), parseInt(parts[1], 10) - 1, parseInt(parts[2], 10));
91          boundDate.setHours(0, 0, 0, 0);
92          return date.getTime() < boundDate.getTime();
93        }
94      }
95    }
96    return false;
97  }
98
99  function isDateAfterEffectiveBound(date, bound, dateFormat, minDate) {
100    if (bound === undefined || bound === null || bound === '') {
101      return false;
102    }
103    if (window.fmeCcfwDatepickerConfig && typeof window.fmeCcfwDatepickerConfig.resolveDefaultDateOffset === 'function') {
104      var resolved = window.fmeCcfwDatepickerConfig.resolveDefaultDateOffset(String(bound), minDate, dateFormat || 'yy-mm-dd');
105      if (resolved) {
106        var parts = resolved.split('-');
107        if (parts.length === 3) {
108          var boundDate = new Date(parseInt(parts[0], 10), parseInt(parts[1], 10) - 1, parseInt(parts[2], 10));
109          boundDate.setHours(23, 59, 59, 999);
110          return date.getTime() > boundDate.getTime();
111        }
112      }
113    }
114    return false;
115  }
116
117  function wrapBeforeShowDayWithEffectiveBounds(beforeShowDay, config) {
118    var effectiveMinDate = config.effectiveMinDate;
119    var effectiveMaxDate = config.effectiveMaxDate;
120    var dateFormat = config.dateFormat || 'yy-mm-dd';
121    var minDate = config.minDate;
122
123    if (
124      (effectiveMinDate === undefined || effectiveMinDate === null || effectiveMinDate === '')
125      && (effectiveMaxDate === undefined || effectiveMaxDate === null || effectiveMaxDate === '')
126    ) {
127      return beforeShowDay;
128    }
129
130    return function (date) {
131      if (typeof beforeShowDay === 'function') {
132        var result = beforeShowDay(date);
133        if (!result[0]) {
134          return result;
135        }
136      }
137
138      if (isDateBeforeEffectiveBound(date, effectiveMinDate, dateFormat)) {
139        return [false, ''];
140      }
141
142      if (isDateAfterEffectiveBound(date, effectiveMaxDate, dateFormat, minDate)) {
143        return [false, ''];
144      }
145
146      return [true, ''];
147    };
148  }
149
150  window.fmeCcfwInitDatepicker = function ($input, config) {
151    if (!$input || !$input.length || typeof $.fn.datepicker !== 'function') {
152      return false;
153    }
154
155    if ($input.hasClass('hasDatepicker')) {
156      return true;
157    }
158
159    config = config || parseConfig($input);
160    if (window.fmeCcfwDatepickerConfig && typeof window.fmeCcfwDatepickerConfig.sanitizeConfig === 'function') {
161      config = window.fmeCcfwDatepickerConfig.sanitizeConfig(config);
162    }
163    var options = {
164      dateFormat: config.dateFormat || 'yy-mm-dd',
165      numberOfMonths: parseInt(config.numberOfMonths, 10) || 1,
166    };
167
168    if (config.changeYear) {
169      options.changeYear = true;
170    }
171    if (config.yearRange) {
172      options.yearRange = config.yearRange;
173    }
174    if (config.defaultDate !== undefined && config.defaultDate !== '') {
175      options.defaultDate = config.defaultDate;
176    }
177    if (config.minDate !== undefined && config.minDate !== '') {
178      options.minDate = config.minDate;
179    }
180    if (config.maxDate !== undefined && config.maxDate !== '') {
181      options.maxDate = config.maxDate;
182    }
183
184    var beforeShowDay = wrapBeforeShowDayWithEffectiveBounds(buildBeforeShowDay(config), config);
185    if (beforeShowDay) {
186      options.beforeShowDay = beforeShowDay;
187    }
188
189    var yearRangeBeforeShow = buildYearRangeBeforeShow(config);
190    if (yearRangeBeforeShow) {
191      options.beforeShow = yearRangeBeforeShow;
192    }
193
194    $input.datepicker(options);
195
196    if (window.fmeCcfwDatepickerConfig && typeof window.fmeCcfwDatepickerConfig.applyDefaultDateToInput === 'function') {
197      window.fmeCcfwDatepickerConfig.applyDefaultDateToInput($input, config);
198    }
199
200    return true;
201  };
202
203  window.fmeCcfwInitDatepickersInContext = function (context) {
204    var initialized = 0;
205    $(context || document).find('input.fme-ccfw-date-picker').each(function () {
206      if (window.fmeCcfwInitDatepicker($(this))) {
207        initialized++;
208      }
209    });
210    return initialized;
211  };
212
213  function scheduleDatepickerInit(context, attempt) {
214    attempt = attempt || 0;
215
216    if (typeof $.fn.datepicker === 'function') {
217      window.fmeCcfwInitDatepickersInContext(context || document);
218      return;
219    }
220
221    if (attempt < 30) {
222      setTimeout(function () {
223        scheduleDatepickerInit(context, attempt + 1);
224      }, 100);
225    }
226  }
227
228  window.fmeCcfwScheduleDatepickerInit = scheduleDatepickerInit;
229
230  $(document).ready(function () {
231    scheduleDatepickerInit(document);
232  });
233
234  $(document.body).on('updated_checkout', function () {
235    setTimeout(function () {
236      scheduleDatepickerInit(document);
237    }, 150);
238  });
239})(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.