PageSourceSearch

https://www.academiamusical.com.pt/wp-content/plugins/hurrytimer-pro/assets/js/hurrytimer.js?ver=2.18.0

js academiamusical.com.pt collected 2026-10-02 13:35:49 UTC 34,751 bytes, 978 lines download raw bytes

1'use strict';
2
3function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
4
5function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
6
7function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
8
9function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10
11function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
12
13function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
14
15var HurrytimerAction = /*#__PURE__*/function () {
16  function HurrytimerAction(elementRef, config) {
17    _classCallCheck(this, HurrytimerAction);
18
19    this.elementRef = elementRef;
20    this.config = config;
21  }
22
23  _createClass(HurrytimerAction, [{
24    key: "hasMessageAction",
25    value: function hasMessageAction() {
26      var _iterator = _createForOfIteratorHelper(this.config.actions),
27          _step;
28
29      try {
30        for (_iterator.s(); !(_step = _iterator.n()).done;) {
31          var action = _step.value;
32
33          if (action['id'] == hurrytimer_ajax_object.actionsOptions.displayMessage) {
34            return true;
35          }
36        }
37      } catch (err) {
38        _iterator.e(err);
39      } finally {
40        _iterator.f();
41      }
42
43      return false;
44    }
45    /**
46     * Hide campaign.
47     */
48
49  }, {
50    key: "hide",
51    value: function hide() {
52      // We don't hide campaign if there is a message to display.
53      if (this.hasMessageAction()) {
54        return;
55      }
56
57      var stickyBar = this.elementRef.closest('.hurrytimer-sticky');
58
59      if (stickyBar.length) {
60        stickyBar.addClass('hurryt-loading');
61      } else {
62        this.elementRef.addClass('hurryt-loading');
63      }
64    }
65    /**
66     * Redirect to the given url.
67     * @param url
68     */
69
70  }, {
71    key: "hideAddToCartButton",
72    value:
73    /**
74     * Hide "Add to cart" button.
75     * @return void
76     */
77    function hideAddToCartButton() {
78      var $addToCartForm = jQuery('.single_add_to_cart_button').closest('form.cart');
79
80      if ($addToCartForm.length) {
81        $addToCartForm.remove();
82      }
83    }
84    /**
85     * Display message by replacing campaign content with the given message.
86     * @param message
87     */
88
89  }, {
90    key: "displayMessage",
91    value: function displayMessage(message) {
92      var messageHtml = "<div class=\"hurrytimer-campaign-message\" data-id=\"".concat(this.config.id, "\">").concat(message, "</div>");
93      this.elementRef.find('.hurrytimer-campaign-message').remove();
94      var stickyBar = this.elementRef.closest('.hurrytimer-sticky');
95
96      if (stickyBar.length) {
97        this.elementRef.addClass('hurryt-loading');
98        stickyBar.find('.hurrytimer-sticky-inner').append(messageHtml);
99      } else {
100        this.elementRef.addClass('hurryt-loading');
101        this.elementRef.after(messageHtml);
102      }
103    }
104  }, {
105    key: "expireCoupon",
106    value: function expireCoupon(code, message) {
107      // Remove coupon if applied but expired and the checkout form has not been placed yet.
108      jQuery('form.checkout').on('checkout_place_order', function (event) {
109        validate_expired_coupon_checkout(event);
110      });
111      document.addEventListener("DOMContentLoaded", function () {
112        validate_expired_coupon_checkout();
113      });
114
115      function validate_expired_coupon_checkout(event) {
116        // Get applied coupons
117        var appliedCoupons = jQuery('.woocommerce-checkout-review-order-table').find('.cart-discount');
118        var isCouponExpired = false;
119        appliedCoupons.each(function () {
120          var couponCode = jQuery(this).find('.woocommerce-remove-coupon').data('coupon');
121
122          if (couponCode && typeof couponCode === 'string' && couponCode.trim().toLowerCase() === code.trim().toLowerCase()) {
123            isCouponExpired = true;
124            return false;
125          }
126        });
127
128        if (isCouponExpired) {
129          var errorHtml = '<ul class="woocommerce-error" role="alert"><li>' + message + '</li></ul>';
130          var noticeGroup = jQuery('.woocommerce-NoticeGroup-checkout');
131
132          if (noticeGroup.length) {
133            noticeGroup.html(errorHtml);
134          } else {
135            var noticeGroupHtml = "<div class=\"woocommerce-NoticeGroup woocommerce-NoticeGroup-checkout\">".concat(errorHtml, "</div>");
136            jQuery('form.checkout').before(noticeGroupHtml);
137            jQuery('html, body').animate({
138              scrollTop: jQuery('.woocommerce-NoticeGroup-checkout').offset().top - 100
139            });
140          }
141
142          var container = jQuery('.woocommerce-checkout-review-order');
143          container.addClass('processing').block({
144            message: null,
145            overlayCSS: {
146              background: '#fff',
147              opacity: 0.6
148            }
149          });
150          jQuery.ajax({
151            type: 'POST',
152            url: wc_checkout_params.wc_ajax_url.toString().replace('%%endpoint%%', 'remove_coupon'),
153            data: {
154              security: wc_checkout_params.remove_coupon_nonce,
155              coupon: code
156            },
157            success: function success(response) {
158              container.removeClass('processing').unblock();
159
160              if (response) {
161                jQuery(document.body).trigger('removed_coupon_in_checkout', [code]);
162                jQuery(document.body).trigger('update_checkout', {
163                  update_shipping_method: false
164                });
165              }
166            },
167            error: function error(jqXHR) {
168              if (wc_checkout_params.debug_mode) {
169                console.log(jqXHR.responseText);
170              }
171            }
172          });
173
174          if (event) {
175            event.preventDefault();
176          }
177
178          return false;
179        }
180      } // WC 7.5.x
181
182
183      var originalFetch = window.fetch;
184
185      window.fetch = function (url, options) {
186        if (url.indexOf('wc-ajax=apply_coupon') !== -1) {
187          var body = options.body;
188          var searchParams = new URLSearchParams(body);
189          var couponCode = searchParams.get('coupon_code');
190
191          if (typeof couponCode === 'string' && couponCode.trim().toLowerCase() === code.trim().toLowerCase()) {
192            jQuery('.woocommerce-error').remove();
193            var $target = jQuery('.woocommerce-notices-wrapper:first') || jQuery('.cart
193-empty').closest('.woocommerce') || jQuery('.woocommerce-cart-form');
194            $target.prepend("<ul class=\"woocommerce-error\" role=\"alert\"><li>".concat(message, "</li></ul>"));
195            jQuery('.checkout_coupon').removeClass('processing').unblock();
196            jQuery('.woocommerce-cart-form').removeClass('processing').unblock();
197            return Promise.reject(new Error(message));
198          }
199        } else if (url.indexOf('/wc/store/v1/batch') !== -1) {
200          var body = options.body;
201          var requests = JSON.parse(body).requests || [];
202          var abortController = new AbortController();
203          options.signal = abortController.signal;
204          requests.forEach(function (req) {
205            if (req.path === '/wc/store/v1/cart/apply-coupon') {
206              var couponCode = req.body.code;
207
208              if (couponCode && typeof couponCode === 'string' && couponCode.trim().toLowerCase() === code.trim().toLowerCase()) {
209                abortController.abort();
210                throw new Error(message);
211              }
212            }
213          });
214        }
215
216        return originalFetch.apply(this, [url, options]);
217      }; // WC 7.4.x
218
219
220      jQuery.ajaxPrefilter(function (opts, originOpts, jqXHR) {
221        if (opts.url.indexOf('wc-ajax=apply_coupon') === -1) return;
222        if (!originOpts.data.coupon_code || typeof originOpts.data.coupon_code !== 'string' || typeof code !== 'string' || originOpts.data.coupon_code.trim().toLowerCase() !== code.trim().toLowerCase()) return;
223        jqXHR.abort();
224        jQuery('.woocommerce-error').remove();
225        var $target = jQuery('.woocommerce-notices-wrapper:first') || jQuery('.cart
225-empty').closest('.woocommerce') || jQuery('.woocommerce-cart-form');
226        $target.prepend("<ul class=\"woocommerce-error\" role=\"alert\"><li>".concat(message, "</li></ul>"));
227        jQuery('.checkout_coupon').removeClass('processing').unblock();
228        jQuery('.woocommerce-cart-form').removeClass('processing').unblock();
229      });
230    }
231  }], [{
232    key: "redirect",
233    value: function redirect(url) {
234      document.body.style.opacity = '0';
235      document.body.style.display = 'none';
236
237      if (url.trim().length === 0) {
238        return;
239      }
240
241      if (hurrytimer_ajax_object.redirect_no_back) {
242        window.location.replace(url);
243      } else {
244        window.location.href = url;
245      }
246    }
247  }]);
248
249  return HurrytimerAction;
250}();
251"use strict";
252
253function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
254
255function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
256
257function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
258
259function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
260
261function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
262
263function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
264
265function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
266
267function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
268
269function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
270
271function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
272
273function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
274
275/*
276 * global hurrytimer_ajax_object
277 */
278var HurrytimerCampaign = /*#__PURE__*/function () {
279  function HurrytimerCampaign(elementRef, config, state) {
280    _classCallCheck(this, HurrytimerCampaign);
281
282    this.config = config;
283    this.elementRef = elementRef;
284    this.actionsOptions = hurrytimer_ajax_object.actionsOptions;
285    this.restartOptions = hurrytimer_ajax_object.restartOptions;
286    this.recurTimeoutId = -1;
287    this.recurIntervalId = -1;
288    this.retryCount = 0;
289    this.startEventDispatched = false;
290    this.state = state;
291    this.restartIntervalId = -1;
292    this.currentEndDate = null;
293    this.dateRangeIndex = 0;
294  }
295  /**
296   * @param endDateInMS
297   * @return void
298   */
299
300
301  _createClass(HurrytimerCampaign, [{
302    key: "setCookie",
303    value: function setCookie(endDateInMS) {
304      var options = {
305        expires: 365
306      };
307
308      if (hurrytimer_ajax_object.COOKIEPATH) {
309        options.path = hurrytimer_ajax_object.COOKIEPATH;
310      }
311
312      if (hurrytimer_ajax_object.COOKIE_DOMAIN) {
313        options.domain = hurrytimer_ajax_object.COOKIE_DOMAIN;
314      }
315
316      Cookies.set(this.config.cookieName, endDateInMS, options);
317
318      if (this.config.reset_token) {
319        Cookies.set("".concat(this.config.cookieName, "_reset_token"), this.config.reset_token, {
320          expires: 365
321        });
322      }
323    }
324    /**
325     * Returns end date for the given duration.
326     * @return {Date}
327     */
328
329  }, {
330    key: "getEndDate",
331    value: function getEndDate() {
332      // Evergreen or recurring
333      if (this.config.isRegular) {
334        return new Date(this.config.endDate);
335      }
336
337      var date = new Date(parseInt(this.config.endDate));
338
339      if (!this.isValidDate(date) || !this.config.endDate || this.should_reset() || this.allowRestart() || this.config.reload_reset) {
340        if (_typeof(date) === 'object' && date.setTime != undefined) {
341          this.unDismissStickyBar();
342          date.setTime(this.calculateDate().getTime());
343        }
344      }
345
346      this.setCookie(date.getTime());
347      this.updateTimestamp(date.getTime());
348      this.currentEndDate = date;
349      return date;
350    }
351    /**
352     * Check if the given date is valid.
353     * @param {*} d
354     */
355
356  }, {
357    key: "isValidDate",
358    value: function isValidDate(d) {
359      return Object.prototype.toString.call(d) === '[object Date]' && !isNaN(d.getTime());
360    }
361    /**
362     * This is useful to force timestamp update when the page is cached.
363     */
364
365  }, {
366    key: "updateTimestamp",
367    value: function updateTimestamp(endDateTimeTS) {
368      if (jQuery.ajax === undefined) return;
369      var args = {
370        url: hurrytimer_ajax_object.ajax_url,
371        async: true,
372        type: 'POST',
373        data: {
374          nonce: hurrytimer_ajax_object.ajax_nonce,
375          timestamp: endDateTimeTS,
376          cid: this.config.id,
377          action: 'hurryt/update_timestamp'
378        }
379      };
380      jQuery.ajax(args);
381    }
382    /**
383     * Returns true if the campaign should reset.
384     *
385     * @return {number}
386     */
387
388  }, {
389    key: "should_reset",
390    value: function should_reset() {
391      return this.config.should_reset;
392    }
393    /**
394     * Remove sticky bar dismiss if available for current given campaign.
395     */
396
397  }, {
398    key: "unDismissStickyBar",
399    value: function unDismissStickyBar() {
400      Cookies.remove("_ht_CDT-".concat(this.config.id, "_dismissed"));
401    }
402    /**
403     * Returns true if the campaign will restart.
404     * @return {boolean}
405     */
406
407  }, {
408    key: "allowRestart",
409    value: function allowRestart() {
410      if (this.config.isRegular) return false;
411      return this.isExpired() && (this.allowRestartImmediately() || this.allowRestartAfterReload() || this.durationSinceExpiryIsOver());
412    }
413    /**
414     * Campaign expired.
415     */
416
417  }, {
418    key: "isExpired",
419    value: function isExpired() {
420      var today = new Date();
421      return this.config.endDate < today;
422    }
423  }, {
424    key: "duratinSinceExpiration",
425    value: function duratinSinceExpiration() {
426      var endDate = this.currentEndDate || this.config.endDate;
427
428      if (!endDate) {
429        return 0;
430      }
431
432      var now = new Date();
433      var diff = now.getTime() - endDate;
434      return diff / 1000;
435    }
436  }, {
437    key: "durationSinceExpiryIsOver",
438    value: function durationSinceExpiryIsOver() {
439      return this.shouldRestartAfterDuration() && this.duratinSinceExpiration() >= this.config.restart_duration;
440    }
441    /**
442     * Restart on refresh.
443     *
444     * @returns {boolean}
445     */
446
447  }, {
448    key: "allowRestartAfterReload",
449    value: function allowRestartAfterReload() {
450      return parseInt(this.config.restart) === parseInt(this.restartOptions.afterReload);
451    }
452    /**
453     * Restart immediatly.
454     *
455     * @returns {boolean}
456     */
457
458  }, {
459    key: "allowRestartImmediately",
460    value: function allowRestartImmediately() {
461      return parseInt(this.config.restart) === parseInt(this.restartOptions.immediately);
462    }
463  }, {
464    key: "shouldRestartAfterDuration",
465    value: function shouldRestartAfterDuration() {
466      return this.config.restart == this.restartOptions.after_duration;
467    }
468    /**
469     * Returns true if the campaign has an action.
470     */
471
472  }, {
473    key: "hasAction",
474    value: function hasAction() {
475      return this.config.actions.length;
476    }
477    /**
478     * Calculate date based on the given duration.
479     * @return {Date}
480     */
481
482  }, {
483    key: "calculateDate",
484    value: function calculateDate() {
485      var date = new Date(); // removeIf(!pro)
486      // If endTime is set, calculate end date based on that time and day
487
488      if (this.config.evergreenEndType === 'time') {
489        var _this$config$evergree = this.config.evergreenEndTime.split(':').map(Number),
490            _this$config$evergree2 = _slicedToArray(_this$config$evergree, 2),
491            hours = _this$config$evergree2[0],
492            minutes = _this$config$evergree2[1];
493
494        date.setHours(hours, minutes, 0, 0); // If the end time has already passed today, add the specified days
495
496        if (date.getTime() <= new Date().getTime()) {
497          // If it's day 0 and time has passed, move to the next occurrence
498          if (this.config.evergreenEndDay === 0) {
499            date.setDate(date.getDate() + 1);
500          } else {
501            date.setDate(date.getDate() + this.config.evergreenEndDay);
502          }
503        } else {
504          // If the end time hasn't passed yet, add the specified days minus 1
505          // (since we want to end on the specified day)
506          date.setDate(date.getDate() + Math.max(0, this.config.evergreenEndDay - 1));
507        }
508
509        return date;
510      } // endRemoveIf(!pro)
511      // Fallback to original duration-based calculation
512
513
514      date.setSeconds(date.getSeconds() + this.config.duration);
515      return date;
516    }
517    /**
518     * Run registered actions.
519     */
520
521  }, {
522    key: "executeActions",
523    value: function executeActions() {
524      if (parseInt(hurrytimer_ajax_object.disable_actions) === 1) {
525        return false;
526      } // No action, abort.
527
528
529      if (this.hasAction()) {
530        var _iterator = _createForOfIteratorHelper(this.config.actions),
531            _step;
532
533        try {
534          for (_iterator.s(); !(_step = _iterator.n()).done;) {
535            var action = _step.value;
536            var actionManager = new HurrytimerAction(this.elementRef, this.config);
537
538            if (this.config.run_in_background) {
539              if (action['id'] == this.actionsOptions.expire_coupon) {
540                actionManager.expireCoupon(action['coupon'], hurrytimer_ajax_object.expire_coupon_message.replace('%s', action['coupon']));
541              }
542            } else {
543              switch (action['id']) {
544                case this.actionsOptions.redirect:
545                  HurrytimerAction.redirect(action['redirectUrl']);
546                  break;
547
548                case this.actionsOptions.displayMessage:
549                  actionManager.displayMessage(action['message']);
550                  break;
551
552                case this.actionsOptions.hideAddToCartButton:
553                  actionManager.hideAddToCartButton();
554                  break;
555
556                case this.actionsOptions.hide:
557                  actionManager.hide();
558                  break;
559              }
560            }
561          }
562        } catch (err) {
563          _iterator.e(err);
564        } finally {
565          _iterator.f();
566        }
567      }
568    }
569  }, {
570    key: "maybeShowCampaign",
571    value: function maybeShowCampaign() {
572      if (this.elementRef.length && !this.config.run_in_background) {
573        // Remove message tag if present.
574        var $message = this.elementRef.parent().find(".hurrytimer-campaign-message[data-id=\"".concat(this.config.id, "\"]"));
575
576        if ($message.length) {
577          $message.remove();
578        }
579
580        this.elementRef.removeClass('hurryt-loading');
581      }
582
583      var stickyBar = this.elementRef.closest('.hurrytimer-sticky');
584
585      if (stickyBar.length) {
586        // Remove message tag if present.
587        var _$message = this.elementRef.find('.hurrytimer-campaign-message');
588
589        if (_$message.length) {
590          _$message.remove();
591        }
592
593        stickyBar.removeClass('hurryt-loading');
594      }
595    }
596    /**
597     * Maybe run countdown timer.
598     */
599
600  }, {
601    key: "waitThenRun",
602    value: function waitThenRun() {
603      var _this = this;
604
605      this.restartIntervalId = setInterval(function () {
606        if (_this.durationSinceExpiryIsOver()) {
607          clearInterval(_this.restartIntervalId);
608
609          _this.run();
610        }
611      }, 1000);
612    }
613  }, {
614    key: "run",
615    value: function run() {
616      var _this2 = this;
617
618      this.triggerInitEvent(); // Apply per-deadline headline on initial run for multi-deadline campaigns
619
620      if (this.config.dateRanges && this.config.dateRanges.length > 0) {
621        var currentEntry = this.config.dateRanges[this.dateRangeIndex];
622
623        if (currentEntry && currentEntry.headline) {
624          this.updateDeadlineHeadline(currentEntry.headline);
625        }
626      }
627
628      this.elementRef.countdown(this.getEndDate(), function (e) {
629        return _this2.onCountdownUpdate(e);
630      });
631      var stickyBar = this.elementRef.closest('.hurrytimer-sticky');
632      this.handleStickyBar(stickyBar);
633    }
634    /**
635     * Handle sticky bar visibility.
636     * @param {*} stickyBar
637     */
638
639  }, {
640    key: "handleStickyBar",
641    value: function handleStickyBar(stickyBar) {
642      var _this3 = this;
643
644      if (stickyBar.length === 0) return;
645      var dismissCookie = Cookies.get("_ht_CDT-".concat(this.config.id, "_dismissed")); // Stick bar hasn't been dismissed.
646
647      if (dismissCookie == undefined) {
648        stickyBar.on('click', '.hurrytimer-sticky-close', function () {
649          return _this3.onStickyBarDismiss(stickyBar);
650        });
651      } else {
652        this.hideStickyBar(stickyBar);
653      }
654    }
655    /**
656     * Hide Sticky Bar
657     * @param {*} stickyBar
658     */
659
660  }, {
661    key: "hideStickyBar",
662    value: function hideStickyBar(stickyBar) {
663      if (stickyBar.length === 0) return;
664      var isTopPinned = stickyBar.css('top') === '0px';
665      stickyBar.remove();
666
667      if (isTopPinned) {
668        jQuery('body').css('margin-top', 0);
669      } else {
670        jQuery('body').css('margin-bottom', 0);
671      }
672    }
673    /**
674     * Handle sticky bar dismiss.
675     */
676
677  }, {
678    key: "onStickyBarDismiss",
679    value: function onStickyBarDismiss(stickyBar) {
680      this.hideStickyBar(stickyBar);
681      Cookies.set("_ht_CDT-".concat(this.config.id, "_dismissed"), '1', {
682        expires: +this.config.sticky_bar_hide_timeout
683      });
684    }
685    /**
686     * Countdown timer start callback.
687     * @param event
688     */
689
690  }, {
691    key: "onCountdownUpdate",
692    value: function onCountdownUpdate(event) {
693      this.render(event);
694      this.maybeShowCampaign();
695
696      if (event.elapsed && event.type === 'finish') {
697        // Date ranges: advance to next deadline before executing final actions
698        if (this.config.dateRanges && this.advanceToNextDateRange()) {
699          return; // moved to next deadline, don't execute final actions
700        }
701
702        this.executeActions();
703        this.triggerFinishEvent();
704        this.maybeRecur();
705
706        if (this.allowRestartImmediately()) {
707          this.run();
708        }
709
710        if (this.shouldRestartAfterDuration()) {
711          this.waitThenRun();
712        }
713      }
714    }
715  }, {
716    key: "triggerFinishEvent",
717    value: function triggerFinishEvent() {
718      var params = {
719        id: this.config.id,
720        mode: this.config.mode,
721        endAt: this.config.endDate
722      };
723      this.elementRef.trigger('hurryt:finished', params);
724    }
725  }, {
726    key: "triggerInitEvent",
727    value: function triggerInitEvent() {
728      var params = {
729        id: this.config.id,
730        mode: this.config.mode,
731        endAt: this.config.endDate
732      };
733      jQuery('.hurrytimer-campaign').trigger('hurryt:init', params);
734    }
735  }, {
736    key: "triggerStartEvent",
737    value: function triggerStartEvent() {
738      if (!this.startEventDispatched) {
739        var params = {
740          id: this.config.id,
741          mode: this.config.mode,
742          endAt: this.config.endDate
743        };
744        this.elementRef.trigger('hurryt:started', params);
745        this.startEventDispatched = true;
746      }
747    }
748    /**
749     * Render countdown timer.
750     * @param event
751     */
752
753  }, {
754    key: "render",
755    value: function render(event) {
756      if (hurrytimer_ajax_object.run_in_background) {
757        this.elementRef.html('');
758      } else {
759        this.elementRef.find('.hurrytimer-timer').html(event.strftime(this.config.template));
760      }
761
762      this.triggerStartEvent();
763    }
764    /**
765     * Calculate the remaining time until the next recurrence.
766     * 
767     * @return int
768     */
769
770  }, {
771    key: "willRecurNow",
772    value: function willRecurNow() {
773      var now = new Date();
774      var prev_recurrence_time = this.getEndDate().getTime() + this.config.timeToNextRecurrence * 1000;
775      return now.getTime() >= prev_recurrence_time;
776    }
777    /**
778     * Run the next recurrence if available.
779     */
780
781  }, {
782    key: "maybeRecur",
783    value: function maybeRecur() {
784      var _this4 = this;
785
786      // Not a recurring campaign.
787      if (!this.config.recurr) return; // the jQuery ajax function is required to fetch the next recurrence.
788
789      if (jQuery.ajax === undefined) return;
790      clearTimeout(this.recurTimeoutId);
791      clearInterval(this.recurIntervalId);
792      this.recurIntervalId = setInterval(function () {
793        if (!_this4.willRecurNow()) {
794          return;
795        }
796
797        clearInterval(_this4.recurIntervalId);
798        jQuery.ajax({
799          url: hurrytimer_ajax_object.ajax_url,
800          data: {
801            action: 'next_recurrence',
802            nonce: hurrytimer_ajax_object.ajax_nonce,
803            id: _this4.config.id
804          },
805          error: function error() {
806            if (_this4.retryCount === 10) return;
807            _this4.retryCount++;
808            setTimeout(function () {
809              _this4.maybeRecur();
810            }, 1000);
811          },
812          success: function success(_ref) {
813            var data = _ref.data;
814            _this4.retryCount = 0;
815            if (!data) return;
816
817            if (isNaN(data.endTimestamp)) {
818              return;
819            }
820
821            _this4.config.endDate = data.endTimestamp; // TODO: Handle lateness:
822            // retry for one minute if the received end date is still expired.
823
824            _this4.run();
825          }
826        });
827      }, 1000);
828    }
829    /**
830     * Advance to the next deadline in a multi-deadline regular campaign.
831     * Returns true if there was a next deadline to advance to, false otherwise.
832     *
833     * @return {boolean}
834     */
835
836  }, {
837    key: "advanceToNextDateRange",
838    value: function advanceToNextDateRange() {
839      if (!this.config.dateRanges || !this.config.dateRanges.length) {
840        return false;
841      }
842
843      this.dateRangeIndex++;
844
845      if (this.dateRangeIndex >= this.config.dateRanges.length) {
846        return false; // No more deadlines, let final actions execute
847      }
848
849      var nextEntry = this.config.dateRanges[this.dateRangeIndex]; // Set the next deadline and restart countdown immediately
850
851      this.config.endDate = nextEntry.end;
852      this.startEventDispatched = false; // Update headline: use per-deadline headline or revert to default
853
854      this.updateDeadlineHeadline(nextEntry.headline);
855      this.run();
856      return true;
857    }
858    /**
859     * Update the headline for the current deadline.
860     * If headline is empty, restores the default headline from Appearance.
861     *
862     * @param {string} headline
863     */
864
865  }, {
866    key: "updateDeadlineHeadline",
867    value: function updateDeadlineHeadline(headline) {
868      var wrapper = this.elementRef.closest('.hurrytimer-campaign, .hurrytimer-sticky');
869      var headlineEl = wrapper.length ? wrapper.find('.hurrytimer-headline') : this.elementRef.parent().find('.hurrytimer-headline');
870      if (!headlineEl.length) return; // Store the original headline on first call
871
872      if (typeof this._defaultHeadline === 'undefined') {
873        this._defaultHeadline = headlineEl.html();
874      }
875
876      if (headline && headline.trim() !== '') {
877        headlineEl.html(headline);
878      } else {
879        headlineEl.html(this._defaultHeadline);
880      }
881    }
882  }]);
883
884  return HurrytimerCampaign;
885}();
886'use strict';
887
888function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
889
890(function ($) {
891  // TODO: delete `state`.
892  var state = {
893    reseting: []
894  };
895  var $body = $('body');
896
897  function onElementInserted(containerSelector, elementSelector, callback) {
898    var onMutationsObserved = function onMutationsObserved(mutations) {
899      mutations.forEach(function (mutation) {
900        if (mutation.addedNodes.length) {
901          var elements = $(mutation.addedNodes).find(elementSelector);
902
903          for (var i = 0, len = elements.length; i < len; i++) {
904            callback(elements[i]);
905          }
906        }
907      });
908    };
909
910    var target = $(containerSelector)[0];
911    var config = {
912      childList: true,
913      subtree: true
914    };
915    var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
916    var observer = new MutationObserver(onMutationsObserved);
917    observer.observe(target, config);
918  }
919
920  document.addEventListener('DOMContentLoaded', function () {
921    var initialElements = document.querySelectorAll('.hurrytimer-campaign');
922    initialElements.forEach(initCallback);
923    onElementInserted('body', '.hurrytimer-campaign', initCallback);
924  });
925
926  function initCallback(e) {
927    if ($(e).parents('div[data-elementor-type=popup]').length === 0) {
928      runCampaign($(e));
929    }
930  }
931
932  $(document).on('elementor/popup/show', function (event, id) {
933    // Run only campaigns within a Elementor popup.
934    $(".elementor-".concat(id, " .hurrytimer-campaign")).each(function () {
935      runCampaign($(this));
936    });
937  });
938  /**
939   *
940   * @param $campaign jQuery
941   */
942
943  function runCampaign($campaign) {
944    // TODO: Inject config object in the <head> tag or inline.
945    var config = $campaign.data('config');
946    if (config === undefined) return; // Check if the config object is corrupt.
947
948    if (_typeof(config) !== 'object') {
949      config = JSON.parse(config.replace(/\s+/g, " "));
950    }
951
952    $campaign.removeAttr('data-config');
953    $campaign.trigger('hurryt:pre-init', {
954      id: config.id,
955      mode: config.mode,
956      endAt: config.endAt
957    });
958    var $sticky = $campaign.closest('.hurrytimer-sticky'); // Display sticky bar if present.
959
960    if ($sticky.length) {
961      $body.append($sticky);
962      $(window).resize(function () {
963        if ($sticky.css('top') === '0px') {
964          // Pin at the top.
965          $body.css('margin-top', $sticky.outerHeight());
966        } else {
967          // Pin at the bottom.
968          $body.css('margin-bottom', $sticky.outerHeight());
969        }
970      });
971      setTimeout(function () {
972        $(window).trigger('resize');
973      });
974    }
975
976    new HurrytimerCampaign($campaign, config, state).run();
977  }
978})(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.