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