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 /** 294 * @param endDateInMS 295 * @return void 296 */ 297 298 299 _createClass(HurrytimerCampaign, [{ 300 key: "setCookie", 301 value: function setCookie(endDateInMS) { 302 var options = { 303 expires: 365 304 }; 305 306 if (hurrytimer_ajax_object.COOKIEPATH) { 307 options.path = hurrytimer_ajax_object.COOKIEPATH; 308 } 309 310 if (hurrytimer_ajax_object.COOKIE_DOMAIN) { 311 options.domain = hurrytimer_ajax_object.COOKIE_DOMAIN; 312 } 313 314 Cookies.set(this.config.cookieName, endDateInMS, options); 315 316 if (this.config.reset_token) { 317 Cookies.set("".concat(this.config.cookieName, "_reset_token"), this.config.reset_token, { 318 expires: 365 319 }); 320 } 321 } 322 /** 323 * Returns end date for the given duration. 324 * @return {Date} 325 */ 326 327 }, { 328 key: "getEndDate", 329 value: function getEndDate() { 330 // Evergreen or recurring 331 if (this.config.isRegular) { 332 return new Date(this.config.endDate); 333 } 334 335 var date = new Date(parseInt(this.config.endDate)); 336 337 if (!this.isValidDate(date) || !this.config.endDate || this.should_reset() || this.allowRestart() || this.config.reload_reset) { 338 if (_typeof(date) === 'object' && date.setTime != undefined) { 339 this.unDismissStickyBar(); 340 date.setTime(this.calculateDate().getTime()); 341 } 342 } 343 344 this.setCookie(date.getTime()); 345 this.updateTimestamp(date.getTime()); 346 this.currentEndDate = date; 347 return date; 348 } 349 /** 350 * Check if the given date is valid. 351 * @param {*} d 352 */ 353 354 }, { 355 key: "isValidDate", 356 value: function isValidDate(d) { 357 return Object.prototype.toString.call(d) === '[object Date]' && !isNaN(d.getTime()); 358 } 359 /** 360 * This is useful to force timestamp update when the page is cached. 361 */ 362 363 }, { 364 key: "updateTimestamp", 365 value: function updateTimestamp(endDateTimeTS) { 366 if (jQuery.ajax === undefined) return; 367 var args = { 368 url: hurrytimer_ajax_object.ajax_url, 369 async: true, 370 type: 'POST', 371 data: { 372 nonce: hurrytimer_ajax_object.ajax_nonce, 373 timestamp: endDateTimeTS, 374 cid: this.config.id, 375 action: 'hurryt/update_timestamp' 376 } 377 }; 378 jQuery.ajax(args); 379 } 380 /** 381 * Returns true if the campaign should reset. 382 * 383 * @return {number} 384 */ 385 386 }, { 387 key: "should_reset", 388 value: function should_reset() { 389 return this.config.should_reset; 390 } 391 /** 392 * Remove sticky bar dismiss if available for current given campaign. 393 */ 394 395 }, { 396 key: "unDismissStickyBar", 397 value: function unDismissStickyBar() { 398 Cookies.remove("_ht_CDT-".concat(this.config.id, "_dismissed")); 399 } 400 /** 401 * Returns true if the campaign will restart. 402 * @return {boolean} 403 */ 404 405 }, { 406 key: "allowRestart", 407 value: function allowRestart() { 408 if (this.config.isRegular) return false; 409 return this.isExpired() && (this.allowRestartImmediately() || this.allowRestartAfterReload() || this.durationSinceExpiryIsOver()); 410 } 411 /** 412 * Campaign expired. 413 */ 414 415 }, { 416 key: "isExpired", 417 value: function isExpired() { 418 var today = new Date(); 419 return this.config.endDate < today; 420 } 421 }, { 422 key: "duratinSinceExpiration", 423 value: function duratinSinceExpiration() { 424 var endDate = this.currentEndDate || this.config.endDate; 425 426 if (!endDate) { 427 return 0; 428 } 429 430 var now = new Date(); 431 var diff = now.getTime() - endDate; 432 return diff / 1000; 433 } 434 }, { 435 key: "durationSinceExpiryIsOver", 436 value: function durationSinceExpiryIsOver() { 437 return this.shouldRestartAfterDuration() && this.duratinSinceExpiration() >= this.config.restart_duration; 438 } 439 /** 440 * Restart on refresh. 441 * 442 * @returns {boolean} 443 */ 444 445 }, { 446 key: "allowRestartAfterReload", 447 value: function allowRestartAfterReload() { 448 return parseInt(this.config.restart) === parseInt(this.restartOptions.afterReload); 449 } 450 /** 451 * Restart immediatly. 452 * 453 * @returns {boolean} 454 */ 455 456 }, { 457 key: "allowRestartImmediately", 458 value: function allowRestartImmediately() { 459 return parseInt(this.config.restart) === parseInt(this.restartOptions.immediately); 460 } 461 }, { 462 key: "shouldRestartAfterDuration", 463 value: function shouldRestartAfterDuration() { 464 return this.config.restart == this.restartOptions.after_duration; 465 } 466 /** 467 * Returns true if the campaign has an action. 468 */ 469 470 }, { 471 key: "hasAction", 472 value: function hasAction() { 473 return this.config.actions.length; 474 } 475 /** 476 * Calculate date based on the given duration. 477 * @return {Date} 478 */ 479 480 }, { 481 key: "calculateDate", 482 value: function calculateDate() { 483 var date = new Date(); // Fallback to original duration-based calculation 484 485 486 date.setSeconds(date.getSeconds() + this.config.duration); 487 return date; 488 } 489 /** 490 * Run registered actions. 491 */ 492 493 }, { 494 key: "executeActions", 495 value: function executeActions() { 496 if (parseInt(hurrytimer_ajax_object.disable_actions) === 1) { 497 return false;
498 } // No action, abort. 499 500 501 if (this.hasAction()) { 502 var _iterator = _createForOfIteratorHelper(this.config.actions), 503 _step; 504 505 try { 506 for (_iterator.s(); !(_step = _iterator.n()).done;) { 507 var action = _step.value; 508 var actionManager = new HurrytimerAction(this.elementRef, this.config); 509 510 if (this.config.run_in_background) { 511 if (action['id'] == this.actionsOptions.expire_coupon) { 512 actionManager.expireCoupon(action['coupon'], hurrytimer_ajax_object.expire_coupon_message.replace('%s', action['coupon'])); 513 } 514 } else { 515 switch (action['id']) { 516 case this.actionsOptions.redirect: 517 HurrytimerAction.redirect(action['redirectUrl']); 518 break; 519 520 case this.actionsOptions.displayMessage: 521 actionManager.displayMessage(action['message']); 522 break; 523 524 case this.actionsOptions.hideAddToCartButton: 525 actionManager.hideAddToCartButton(); 526 break; 527 528 case this.actionsOptions.hide: 529 actionManager.hide(); 530 break; 531 } 532 } 533 } 534 } catch (err) { 535 _iterator.e(err); 536 } finally { 537 _iterator.f(); 538 } 539 } 540 } 541 }, { 542 key: "maybeShowCampaign", 543 value: function maybeShowCampaign() { 544 if (this.elementRef.length && !this.config.run_in_background) { 545 // Remove message tag if present. 546 var $message = this.elementRef.parent().find(".hurrytimer-campaign-message[data-id=\"".concat(this.config.id, "\"]")); 547 548 if ($message.length) { 549 $message.remove(); 550 } 551 552 this.elementRef.removeClass('hurryt-loading'); 553 } 554 555 var stickyBar = this.elementRef.closest('.hurrytimer-sticky'); 556 557 if (stickyBar.length) { 558 // Remove message tag if present. 559 var _$message = this.elementRef.find('.hurrytimer-campaign-message'); 560 561 if (_$message.length) { 562 _$message.remove(); 563 } 564 565 stickyBar.removeClass('hurryt-loading'); 566 } 567 } 568 /** 569 * Maybe run countdown timer. 570 */ 571 572 }, { 573 key: "waitThenRun", 574 value: function waitThenRun() { 575 var _this = this; 576 577 this.restartIntervalId = setInterval(function () { 578 if (_this.durationSinceExpiryIsOver()) { 579 clearInterval(_this.restartIntervalId); 580 581 _this.run(); 582 } 583 }, 1000); 584 } 585 }, { 586 key: "run", 587 value: function run() { 588 var _this2 = this; 589 590 this.triggerInitEvent(); this.elementRef.countdown(this.getEndDate(), function (e) { 591 return _this2.onCountdownUpdate(e); 592 }); 593 var stickyBar = this.elementRef.closest('.hurrytimer-sticky'); 594 this.handleStickyBar(stickyBar); 595 } 596 /** 597 * Handle sticky bar visibility. 598 * @param {*} stickyBar 599 */ 600 601 }, { 602 key: "handleStickyBar", 603 value: function handleStickyBar(stickyBar) { 604 var _this3 = this; 605 606 if (stickyBar.length === 0) return; 607 var dismissCookie = Cookies.get("_ht_CDT-".concat(this.config.id, "_dismissed")); // Stick bar hasn't been dismissed. 608 609 if (dismissCookie == undefined) { 610 stickyBar.on('click', '.hurrytimer-sticky-close', function () { 611 return _this3.onStickyBarDismiss(stickyBar); 612 }); 613 } else { 614 this.hideStickyBar(stickyBar); 615 } 616 } 617 /** 618 * Hide Sticky Bar 619 * @param {*} stickyBar 620 */ 621 622 }, { 623 key: "hideStickyBar", 624 value: function hideStickyBar(stickyBar) { 625 if (stickyBar.length === 0) return; 626 var isTopPinned = stickyBar.css('top') === '0px'; 627 stickyBar.remove(); 628 629 if (isTopPinned) { 630 jQuery('body').css('margin-top', 0); 631 } else { 632 jQuery('body').css('margin-bottom', 0); 633 } 634 } 635 /** 636 * Handle sticky bar dismiss. 637 */ 638 639 }, { 640 key: "onStickyBarDismiss", 641 value: function onStickyBarDismiss(stickyBar) { 642 this.hideStickyBar(stickyBar); 643 Cookies.set("_ht_CDT-".concat(this.config.id, "_dismissed"), '1', { 644 expires: +this.config.sticky_bar_hide_timeout 645 }); 646 } 647 /** 648 * Countdown timer start callback. 649 * @param event 650 */ 651 652 }, { 653 key: "onCountdownUpdate", 654 value: function onCountdownUpdate(event) { 655 this.render(event); 656 this.maybeShowCampaign(); 657 658 if (event.elapsed && event.type === 'finish') { 659 this.executeActions(); 660 this.triggerFinishEvent(); 661 this.maybeRecur(); 662 663 if (this.allowRestartImmediately()) { 664 this.run(); 665 } 666 667 if (this.shouldRestartAfterDuration()) { 668 this.waitThenRun(); 669 } 670 } 671 } 672 }, { 673 key: "triggerFinishEvent", 674 value: function triggerFinishEvent() { 675 var params = { 676 id: this.config.id, 677 mode: this.config.mode, 678 endAt: this.config.endDate 679 }; 680 this.elementRef.trigger('hurryt:finished', params); 681 } 682 }, { 683 key: "triggerInitEvent", 684 value: function triggerInitEvent() { 685 var params = { 686 id: this.config.id, 687 mode: this.config.mode, 688 endAt: this.config.endDate 689 }; 690 jQuery('.hurrytimer-campaign').trigger('hurryt:init', params); 691 } 692 }, { 693 key: "triggerStartEvent", 694 value: function triggerStartEvent() { 695 if (!this.startEventDispatched) { 696 var params = { 697 id: this.config.id, 698 mode: this.config.mode, 699 endAt: this.config.endDate 700 }; 701 this.elementRef.trigger('hurryt:started', params); 702 this.startEventDispatched = true; 703 } 704 } 705 /**
706 * Render countdown timer. 707 * @param event 708 */ 709 710 }, { 711 key: "render", 712 value: function render(event) { 713 if (hurrytimer_ajax_object.run_in_background) { 714 this.elementRef.html(''); 715 } else { 716 this.elementRef.find('.hurrytimer-timer').html(event.strftime(this.config.template)); 717 } 718 719 this.triggerStartEvent(); 720 } 721 /** 722 * Calculate the remaining time until the next recurrence. 723 * 724 * @return int 725 */ 726 727 }, { 728 key: "willRecurNow", 729 value: function willRecurNow() { 730 var now = new Date(); 731 var prev_recurrence_time = this.getEndDate().getTime() + this.config.timeToNextRecurrence * 1000; 732 return now.getTime() >= prev_recurrence_time; 733 } 734 /** 735 * Run the next recurrence if available. 736 */ 737 738 }, { 739 key: "maybeRecur", 740 value: function maybeRecur() { 741 var _this4 = this; 742 743 // Not a recurring campaign. 744 if (!this.config.recurr) return; // the jQuery ajax function is required to fetch the next recurrence. 745 746 if (jQuery.ajax === undefined) return; 747 clearTimeout(this.recurTimeoutId); 748 clearInterval(this.recurIntervalId); 749 this.recurIntervalId = setInterval(function () { 750 if (!_this4.willRecurNow()) { 751 return; 752 } 753 754 clearInterval(_this4.recurIntervalId); 755 jQuery.ajax({ 756 url: hurrytimer_ajax_object.ajax_url, 757 data: { 758 action: 'next_recurrence', 759 nonce: hurrytimer_ajax_object.ajax_nonce, 760 id: _this4.config.id 761 }, 762 error: function error() { 763 if (_this4.retryCount === 10) return; 764 _this4.retryCount++; 765 setTimeout(function () { 766 _this4.maybeRecur(); 767 }, 1000); 768 }, 769 success: function success(_ref) { 770 var data = _ref.data; 771 _this4.retryCount = 0; 772 if (!data) return; 773 774 if (isNaN(data.endTimestamp)) { 775 return; 776 } 777 778 _this4.config.endDate = data.endTimestamp; // TODO: Handle lateness: 779 // retry for one minute if the received end date is still expired. 780 781 _this4.run(); 782 } 783 }); 784 }, 1000); 785 } }]); 786 787 return HurrytimerCampaign; 788}(); 789'use strict'; 790 791function _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); } 792 793(function ($) { 794 // TODO: delete `state`. 795 var state = { 796 reseting: [] 797 }; 798 var $body = $('body'); 799 800 function onElementInserted(containerSelector, elementSelector, callback) { 801 var onMutationsObserved = function onMutationsObserved(mutations) { 802 mutations.forEach(function (mutation) { 803 if (mutation.addedNodes.length) { 804 var elements = $(mutation.addedNodes).find(elementSelector); 805 806 for (var i = 0, len = elements.length; i < len; i++) { 807 callback(elements[i]); 808 } 809 } 810 }); 811 }; 812 813 var target = $(containerSelector)[0]; 814 var config = { 815 childList: true, 816 subtree: true 817 }; 818 var MutationObserver = window.MutationObserver || window.WebKitMutationObserver; 819 var observer = new MutationObserver(onMutationsObserved); 820 observer.observe(target, config); 821 } 822 823 document.addEventListener('DOMContentLoaded', function () { 824 var initialElements = document.querySelectorAll('.hurrytimer-campaign'); 825 initialElements.forEach(initCallback); 826 onElementInserted('body', '.hurrytimer-campaign', initCallback); 827 }); 828 829 function initCallback(e) { 830 if ($(e).parents('div[data-elementor-type=popup]').length === 0) { 831 runCampaign($(e)); 832 } 833 } 834 835 $(document).on('elementor/popup/show', function (event, id) { 836 // Run only campaigns within a Elementor popup. 837 $(".elementor-".concat(id, " .hurrytimer-campaign")).each(function () { 838 runCampaign($(this)); 839 }); 840 }); 841 /** 842 * 843 * @param $campaign jQuery 844 */ 845 846 function runCampaign($campaign) { 847 // TODO: Inject config object in the <head> tag or inline. 848 var config = $campaign.data('config'); 849 if (config === undefined) return; // Check if the config object is corrupt. 850 851 if (_typeof(config) !== 'object') { 852 config = JSON.parse(config.replace(/\s+/g, " ")); 853 } 854 855 $campaign.removeAttr('data-config'); 856 $campaign.trigger('hurryt:pre-init', { 857 id: config.id, 858 mode: config.mode, 859 endAt: config.endAt 860 });
861 var $sticky = $campaign.closest('.hurrytimer-sticky'); // Display sticky bar if present. 862 863 if ($sticky.length) { 864 $body.append($sticky); 865 $(window).resize(function () { 866 if ($sticky.css('top') === '0px') { 867 // Pin at the top. 868 $body.css('margin-top', $sticky.outerHeight()); 869 } else { 870 // Pin at the bottom. 871 $body.css('margin-bottom', $sticky.outerHeight()); 872 } 873 }); 874 setTimeout(function () { 875 $(window).trigger('resize'); 876 }); 877 } 878 879 new HurrytimerCampaign($campaign, config, state).run(); 880 } 881})(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.