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