price-display-assets-eb73bec9c47859c4afe4.js 3.6 KB

1
  1. (()=>{var t={90906:(t,e,o)=>{"use strict";function a(t,e){for(var o=0;o<e.length;o++){var a=e[o];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,a.key,a)}}o.r(e);var i=function(){function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this._handlePostcodeChanged=this._handlePostcodeChanged.bind(this),this._showStatePrice=this._showStatePrice.bind(this),this.defaultPriceElm=document.querySelector("[data-default-price-value]"),this.defaultPrice=this.defaultPriceElm.getAttribute("data-default-price-value"),this.elementToShowPrices=document.querySelectorAll("[data-state-price-display]"),this.stateInfoUrl=$(".details-price").data("state-info-url"),this.statePrices=e}var e,o;return e=t,(o=[{key:"init",value:function(){0!==this.statePrices.length&&window.addEventListener("Postcode.Changed",this._handlePostcodeChanged)}},{key:"_handlePostcodeChanged",value:function(t){this._isValidPostcode(t.detail.postcode)&&""!==t.detail.postcode?this._fetchStateInfoForPostcode(t.detail.postcode):""===t.detail.postcode&&this._showStatePrice("default")}},{key:"_fetchStateInfoForPostcode",value:function(t){var e=this;fetch("".concat(this.stateInfoUrl,"?postcode=").concat(t)).then((function(t){return t.ok?t.json():t.json().then((function(t){throw Error(t.error)}))})).then((function(t){e._showStatePrice(t.stateAbbr.toLowerCase())})).catch((function(t){console.log(t.message),e._showStatePrice("default")}))}},{key:"_showStatePrice",value:function(t){var e=this.statePrices.filter((function(e){return e.state.toLowerCase()===t.toLowerCase()})),o=this.defaultPrice;if(e.length>0&&(o=e[0].price),this.elementToShowPrices.length>0)for(var a=0;a<this.elementToShowPrices.length;a++)this.elementToShowPrices[a].innerHTML=o}},{key:"_isValidPostcode",value:function(t){return/^((0[289][0-9]{2})|([1345689][0-9]{3})|(2[0-8][0-9]{2})|(290[0-9])|(291[0-4])|(7[0-4][0-9]{2})|(7[8-9][0-9]{2}))*$/.test(t)}}])&&a(e.prototype,o),t}();!function(t){t((function(){t('.details-price [data-toggle="popover"]').popover({html:!0,content:function(){var e=t(this).attr("data-popover-content");return t(e).children(".popover-body").html()},title:function(){var e=t(this).attr("data-popover-content");return t(e).children(".popover-heading").html()}})})),t((function(){t("[scroll-to-options-fitted]").click((function(){t("#fitted-options-tab").click(),t("#fitted-options .multi-collapse ").hasClass("show")||t(".features-toggle-collapse").click(),t("html, body").animate({scrollTop:t(".features").offset().top-120},300)})),"undefined"!=typeof statePrices&&Array.isArray(statePrices)&&statePrices.length>0&&new i(statePrices).init()}));var e=function(){var e=JSON.parse(unescape(decodeURIComponent(localStorage.getItem("cmp.ret.enq.details"))));e&&t(".price-link, .features-item-value.features-item-value-price > a:not(.partner-tools-finance-item)").each((function(){t(this).attr("data-target-original-url")||t(this).attr("data-target-original-url",t(this).attr("data-target-url")),t(this).attr("data-target-url","".concat(t(this).attr("data-target-original-url"),"/").concat(e.Postcode))}))};t((function(){t(document).ready((function(){e()}))})),t((function(){window.addEventListener("storage",(function(t){e()}))}))}(jQuery)},29411:(t,e,o)=>{"use strict";o.r(e)}},e={};function o(a){var i=e[a];if(void 0!==i)return i.exports;var r=e[a]={exports:{}};return t[a](r,r.exports,o),r.exports}o.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o(90906),o(29411)})();