From 357812ec06d49436406c9fee4393d568f7740050 Mon Sep 17 00:00:00 2001 From: Ben Thomson Date: Wed, 18 May 2022 23:45:06 +0800 Subject: [PATCH 1/3] Abstract Snowboard plugin constructors and destructors Previously, Snowboard plugins had been written to append the main JavaScript constructor. While this worked, it prevented the ability to destruct the plugin during construction (ie. prevent double initialisation on plugins, for example), as the "detach" method which is fired on destruction is added *after* construction. This change abstracts the constructor and destructor to separate methods run after the true construction of the JavaScript object is complete. A bonus is that the constructor no longer needs to include "snowboard" as one of the parameters - this instead is done on the true construction. --- modules/system/assets/js/build/system.js | 2 +- .../js/snowboard/abstracts/PluginBase.js | 28 ++++++++++++++++--- .../assets/js/snowboard/ajax/Request.js | 8 +++--- .../ajax/handlers/AttributeRequest.js | 4 +-- .../snowboard/build/snowboard.base.debug.js | 2 +- .../js/snowboard/build/snowboard.base.js | 2 +- .../js/snowboard/build/snowboard.data-attr.js | 2 +- .../js/snowboard/build/snowboard.extras.js | 2 +- .../js/snowboard/build/snowboard.request.js | 2 +- .../assets/js/snowboard/extras/DataConfig.js | 5 +--- .../assets/js/snowboard/extras/Flash.js | 11 +++----- .../assets/js/snowboard/extras/Transition.js | 12 ++++---- .../assets/js/snowboard/main/PluginLoader.js | 10 ++++--- .../assets/js/snowboard/main/Snowboard.js | 2 +- .../assets/js/snowboard/utilities/Cookie.js | 4 +-- .../js/snowboard/utilities/JsonParser.js | 4 +-- .../js/snowboard/utilities/Sanitizer.js | 4 +-- .../assets/js/snowboard/utilities/Url.js | 4 +-- 18 files changed, 57 insertions(+), 51 deletions(-) diff --git a/modules/system/assets/js/build/system.js b/modules/system/assets/js/build/system.js index 04d664d396..1c9c6dba38 100644 --- a/modules/system/assets/js/build/system.js +++ b/modules/system/assets/js/build/system.js @@ -1 +1 @@ -(self.webpackChunk_wintercms_wn_system_module=self.webpackChunk_wintercms_wn_system_module||[]).push([[290,450,988],{2026:function(t,e,n){"use strict";n(6886);function r(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function o(t){for(var e=1;e{t&&this.doAjax().then((t=>{if(t.cancelled)return this.cancelled=!0,void this.complete();this.responseData=t,this.processUpdate(t).then((()=>{!1===t.X_WINTER_SUCCESS?this.processError(t):this.processResponse(t)}))}),(t=>{this.responseError=t,this.processError(t)}))})):this.doAjax().then((t=>{if(t.cancelled)return this.cancelled=!0,void this.complete();this.responseData=t,this.processUpdate(t).then((()=>{!1===t.X_WINTER_SUCCESS?this.processError(t):this.processResponse(t)}))}),(t=>{this.responseError=t,this.processError(t)})):this.cancelled=!0}else this.cancelled=!0}dependencies(){return["cookie","jsonParser"]}checkRequest(){if(this.element&&this.element instanceof Element==!1)throw new Error("The element provided must be an Element instance");if(void 0===this.handler)throw new Error("The AJAX handler name is not specified.");if(!this.handler.match(/^(?:\w+:{2})?on*/))throw new Error('Invalid AJAX handler name. The correct handler name format is: "onEvent".')}getFetch(){return this.fetchOptions=void 0!==this.options.fetchOptions&&"object"==typeof this.options.fetchOptions?this.options.fetchOptions:{method:"POST",headers:this.headers,body:this.data,redirect:"follow",mode:"same-origin"},this.snowboard.globalEvent("ajaxFetchOptions",this.fetchOptions,this),fetch(this.url,this.fetchOptions)}doClientValidation(){return!0!==this.options.browserValidate||!this.form||!1!==this.form.checkValidity()||(this.form.reportValidity(),!1)}doAjax(){if(!1===this.snowboard.globalEvent("ajaxBeforeSend",this))return Promise.resolve({cancelled:!0});const t=new Promise(((t,e)=>{this.getFetch().then((n=>{n.ok||406===n.status?n.headers.has("Content-Type")&&n.headers.get("Content-Type").includes("/json")?n.json().then((e=>{t(o(o({},e),{},{X_WINTER_SUCCESS:406!==n.status,X_WINTER_RESPONSE_CODE:n.status}))}),(t=>{e(this.renderError("Unable to parse JSON response: ".concat(t)))})):n.text().then((e=>{t(e)}),(t=>{e(this.renderError("Unable to process response: ".concat(t)))})):n.headers.has("Content-Type")&&n.headers.get("Content-Type").includes("/json")?n.json().then((t=>{e(this.renderError(t.message,t.exception,t.file,t.line,t.trace))}),(t=>{e(this.renderError("Unable to parse JSON response: ".concat(t)))})):n.text().then((t=>{e(this.renderError(t))}),(t=>{e(this.renderError("Unable to process response: ".concat(t)))}))}),(t=>{e(this.renderError("Unable to retrieve a response from the server: ".concat(t)))}))}));if(this.snowboard.globalEvent("ajaxStart",t,this),this.element){const e=new Event("ajaxPromise");e.promise=t,this.element.dispatchEvent(e)}return t}processUpdate(t){return new Promise(((e,n)=>{if("function"==typeof this.options.beforeUpdate&&!1===this.options.beforeUpdate.apply(this,[t]))return void n();const r={};if(Object.entries(t).forEach((t=>{const[e,n]=t;"X_WINTER"!==e.substr(0,8)&&(r[e]=n)})),0===Object.keys(r).length)return void(t.X_WINTER_ASSETS?this.processAssets(t.X_WINTER_ASSETS).then((()=>{e()}),(()=>{n()})):e());this.snowboard.globalPromiseEvent("ajaxBeforeUpdate",t,this).then((async()=>{t.X_WINTER_ASSETS&&await this.processAssets(t.X_WINTER_ASSETS),this.doUpdate(r).then((()=>{window.requestAnimationFrame((()=>e()))}),(()=>{n()}))}),(()=>{n()}))}))}doUpdate(t){return new Promise((e=>{const n=[];Object.entries(t).forEach((t=>{const[e,r]=t;let o=this.options.update&&this.options.update[e]?this.options.update[e]:e,i="replace";"@"===o.substr(0,1)?(i="append",o=o.substr(1)):"^"===o.substr(0,1)&&(i="prepend",o=o.substr(1));const s=document.querySelectorAll(o);s.length>0&&s.forEach((t=>{switch(i){case"append":t.innerHTML+=r;break;case"prepend":t.innerHTML=r+t.innerHTML;break;default:t.innerHTML=r}n.push(t),this.snowboard.globalEvent("ajaxUpdate",t,r,this);const e=new Event("ajaxUpdate");e.content=r,t.dispatchEvent(e)}))})),this.snowboard.globalEvent("ajaxUpdateComplete",n,this),e()}))}processResponse(t){if((!this.options.success||"function"!=typeof this.options.success||this.options.success(this.responseData,this))&&!1!==this.snowboard.globalEvent("ajaxSuccess",this.responseData,this)){if(this.element){const t=new Event("ajaxDone",{cancelable:!0});if(t.responseData=this.responseData,t.request=this,this.element.dispatchEvent(t),t.defaultPrevented)return}this.flash&&t.X_WINTER_FLASH_MESSAGES&&this.processFlashMessages(t.X_WINTER_FLASH_MESSAGES),this.redirect||t.X_WINTER_REDIRECT?this.processRedirect(this.redirect||t.X_WINTER_REDIRECT):this.complete()}}processError(t){if((!this.options.error||"function"!=typeof this.options.error||this.options.error(this.responseError,this))&&!1!==this.snowboard.globalEvent("ajaxError",this.responseError,this)){if(this.element){const t=new Event("ajaxFail",{cancelable:!0});if(t.responseError=this.responseError,t.request=this,this.element.dispatchEvent(t),t.defaultPrevented)return}t instanceof Error?this.processErrorMessage(t.message):(t.X_WINTER_ERROR_FIELDS&&this.processValidationErrors(t.X_WINTER_ERROR_FIELDS),t.X_WINTER_ERROR_MESSAGE&&this.processErrorMessage(t.X_WINTER_ERROR_MESSAGE)),this.complete()}}processRedirect(t){"function"==typeof this.options.handleRedirectResponse&&!1===this.options.handleRedirectResponse.apply(this,[t])||!1!==this.snowboard.globalEvent("ajaxRedirect",t,this)&&(window.addEventListener("popstate",(()=>{if(this.element){const t=document.createEvent("CustomEvent");t.eventName="ajaxRedirected",this.element.dispatchEvent(t)}}),{once:!0}),window.location.assign(t))}processErrorMessage(t){"function"==typeof this.options.handleErrorMessage&&!1===this.options.handleErrorMessage.apply(this,[t])||!1!==this.snowboard.globalEvent("ajaxErrorMessage",t,this)&&window.alert(t)}processFlashMessages(t){"function"==typeof this.options.handleFlashMessages&&!1===this.options.handleFlashMessages.apply(this,[t])||this.snowboard.globalEvent("ajaxFlashMessages",t,this)}processValidationErrors(t){"function"==typeof this.options.handleValidationErrors&&!1===this.options.handleValidationErrors.apply(this,[this.form,t])||this.snowboard.globalEvent("ajaxValidationErrors",this.form,t,this)}processAssets(t){return this.snowboard.globalPromiseEvent("ajaxLoadAssets",t)}async doConfirm(){if("function"==typeof this.options.handleConfirmMessage)return!1!==this.options.handleConfirmMessage.apply(this,[this.confirm]);if(0===this.snowboard.listensToEvent("ajaxConfirmMessage").length)return window.confirm(this.confirm);const t=this.snowboard.globalPromiseEvent("ajaxConfirmMessage",this.confirm,this);try{if(await t)return!0}catch(t){return!1}return!1}complete(){if(this.options.complete&&"function"==typeof this.options.complete&&this.options.complete(this.responseData,this),this.snowboard.globalEvent("ajaxDone",this.responseData,this),this.element){const t=new Event("ajaxAlways");t.request=this,t.responseData=this.responseData,t.responseError=this.responseError,this.element.dispatchEvent(t)}}get form(){return this.options.form?this.options.form:this.element?"FORM"===this.element.tagName?this.element:this.element.closest("form"):null}get context(){return{handler:this.handler,options:this.options}}get headers(){const t={"X-Requested-With":"XMLHttpRequest","X-WINTER-REQUEST-HANDLER":this.handler,"X-WINTER-REQUEST-PARTIALS":this.extractPartials(this.options.update||[])};return this.flash&&(t["X-WINTER-REQUEST-FLASH"]=1),this.xsrfToken&&(t["X-XSRF-TOKEN"]=this.xsrfToken),t}get loading(){return this.options.loading||!1}get url(){return this.options.url||window.location.href}get redirect(){return this.options.redirect&&this.options.redirect.length?this.options.redirect:null}get flash(){return this.options.flash||!1}get files(){return!0===this.options.files&&(void 0!==FormData||(this.snowboard.debug("This browser does not support file uploads"),!1))}get xsrfToken(){return this.snowboard.cookie().get("XSRF-TOKEN")}get data(){const t="object"==typeof this.options.data?this.options.data:{},e=new FormData(this.form||void 0);return Object.keys(t).length>0&&Object.entries(t).forEach((t=>{const[n,r]=t;e.append(n,r)})),e}get confirm(){return this.options.confirm||!1}extractPartials(t){return Object.keys(t).join("&")}renderError(t,e,n,r,o){const i=new Error(t);return i.exception=e||null,i.file=n||null,i.line=r||null,i.trace=o||[],i}}Snowboard.addPlugin("request",s)},8809:function(t,e,n){"use strict";n.d(e,{Z:function(){return r}});n(6886);class r extends window.Snowboard.Singleton{listens(){return{ajaxLoadAssets:"load"}}async load(t){if(t.js&&t.js.length>0)for(const e of t.js)try{await this.loadScript(e)}catch(t){return Promise.reject(t)}if(t.css&&t.css.length>0)for(const e of t.css)try{await this.loadStyle(e)}catch(t){return Promise.reject(t)}if(t.img&&t.img.length>0)for(const e of t.img)try{await this.loadImage(e)}catch(t){return Promise.reject(t)}return Promise.resolve()}loadScript(t){return new Promise(((e,n)=>{if(document.querySelector('script[src="'.concat(t,'"]')))return void e();const r=document.createElement("script");r.setAttribute("type","text/javascript"),r.setAttribute("src",t),r.addEventListener("load",(()=>{this.snowboard.globalEvent("assetLoader.loaded","script",t,r),e()})),r.addEventListener("error",(()=>{this.snowboard.globalEvent("assetLoader.error","script",t,r),n(new Error('Unable to load script file: "'.concat(t,'"')))})),document.body.append(r)}))}loadStyle(t){return new Promise(((e,n)=>{if(document.querySelector('link[rel="stylesheet"][href="'.concat(t,'"]')))return void e();const r=document.createElement("link");r.setAttribute("rel","stylesheet"),r.setAttribute("href",t),r.addEventListener("load",(()=>{this.snowboard.globalEvent("assetLoader.loaded","style",t,r),e()})),r.addEventListener("error",(()=>{this.snowboard.globalEvent("assetLoader.error","style",t,r),n(new Error('Unable to load stylesheet file: "'.concat(t,'"')))})),document.head.append(r)}))}loadImage(t){return new Promise(((e,n)=>{const r=new Image;r.addEventListener("load",(()=>{this.snowboard.globalEvent("assetLoader.loaded","image",t,r),e()})),r.addEventListener("error",(()=>{this.snowboard.globalEvent("assetLoader.error","image",t,r),n(new Error('Unable to load image file: "'.concat(t,'"')))})),r.src=t}))}}},9553:function(t,e,n){"use strict";n.d(e,{Z:function(){return r}});class r extends Snowboard.Singleton{dependencies(){return["request"]}listens(){return{ajaxStart:"ajaxStart",ajaxDone:"ajaxDone"}}ajaxStart(t,e){if(e.element)if("FORM"===e.element.tagName){const t=e.element.querySelectorAll("[data-attach-loading]");t.length>0&&t.forEach((t=>{t.classList.add(this.getLoadingClass(t))}))}else void 0!==e.element.dataset.attachLoading&&e.element.classList.add(this.getLoadingClass(e.element))}ajaxDone(t,e){if(e.element)if("FORM"===e.element.tagName){const t=e.element.querySelectorAll("[data-attach-loading]");t.length>0&&t.forEach((t=>{t.classList.remove(this.getLoadingClass(t))}))}else void 0!==e.element.dataset.attachLoading&&e.element.classList.remove(this.getLoadingClass(e.element))}getLoadingClass(t){return void 0!==t.dataset.attachLoading&&""!==t.dataset.attachLoading?t.dataset.attachLoading:"wn-loading"}}},5763:function(t,e,n){"use strict";n.d(e,{Z:function(){return r}});n(5940);class r extends Snowboard.PluginBase{constructor(t,e,n){if(super(t),e instanceof Snowboard.PluginBase==!1)throw new Error("You must provide a Snowboard plugin to enable data configuration");if(n instanceof HTMLElement==!1)throw new Error("Data configuration can only be extracted from HTML elements");this.instance=e,this.element=n,this.refresh()}get(t){return void 0===t?this.instanceConfig:void 0!==this.instanceConfig[t]?this.instanceConfig[t]:void 0}set(t,e,n){if(void 0===t)throw new Error("You must provide a configuration key to set");this.instanceConfig[t]=e,!0===n&&(this.element.dataset[t]=e)}refresh(){this.acceptedConfigs=this.getAcceptedConfigs(),this.instanceConfig=this.processConfig()}getAcceptedConfigs(){return void 0!==this.instance.acceptAllDataConfigs&&!0===this.instance.acceptAllDataConfigs||void 0!==this.instance.defaults&&"function"==typeof this.instance.defaults&&"object"==typeof this.instance.defaults()&&Object.keys(this.instance.defaults())}getDefaults(){return void 0!==this.instance.defaults&&"function"==typeof this.instance.defaults&&"object"==typeof this.instance.defaults()?this.instance.defaults():{}}processConfig(){const t=this.getDefaults();if(!1===this.acceptedConfigs)return t;for(const e in this.element.dataset)(!0===this.acceptedConfigs||this.acceptedConfigs.includes(e))&&(t[e]=this.coerceValue(this.element.dataset[e]));return t}coerceValue(t){const e=String(t);if("null"===e)return null;if("undefined"!==e){if(e.startsWith("base64:")){const t=e.replace(/^base64:/,""),n=atob(t);return this.coerceValue(n)}if(["true","yes"].includes(e.toLowerCase()))return!0;if(["false","no"].includes(e.toLowerCase()))return!1;if(/^[-+]?[0-9]+(\.[0-9]+)?$/.test(e))return Number(e);try{return this.snowboard.jsonParser().parse(e)}catch(t){return""===e||e}}}}},2270:function(t,e,n){"use strict";n.d(e,{Z:function(){return r}});class r extends Snowboard.PluginBase{constructor(t,e,n,r){if(super(t),this.message=e,this.type=n||"default",this.duration=Number(r||7),this.duration<0)throw new Error("Flash duration must be a positive number, or zero");this.clear(),this.timer=null,this.flashTimer=null,this.create()}dependencies(){return["transition"]}destructor(){null!==this.timer&&window.clearTimeout(this.timer),this.flashTimer&&this.flashTimer.remove(),this.flash&&(this.flash.remove(),this.flash=null,this.flashTimer=null),super.destructor()}create(){this.snowboard.globalEvent("flash.create",this),this.flash=document.createElement("DIV"),this.flash.innerHTML=this.message,this.flash.classList.add("flash-message",this.type),this.flash.removeAttribute("data-control"),this.flash.addEventListener("click",(()=>this.remove())),this.flash.addEventListener("mouseover",(()=>this.stopTimer())),this.flash.addEventListener("mouseout",(()=>this.startTimer())),this.duration>0?(this.flashTimer=document.createElement("DIV"),this.flashTimer.classList.add("flash-timer"),this.flash.appendChild(this.flashTimer)):this.flash.classList.add("no-timer"),document.body.appendChild(this.flash),this.snowboard.transition(this.flash,"show",(()=>{this.startTimer()}))}remove(){this.snowboard.globalEvent("flash.remove",this),this.stopTimer(),this.snowboard.transition(this.flash,"hide",(()=>{this.flash.remove(),this.flash=null,this.destructor()}))}clear(){document.querySelectorAll("body > div.flash-message").forEach((t=>t.remove()))}startTimer(){0!==this.duration&&(this.timerTrans=this.snowboard.transition(this.flashTimer,"timeout",null,"".concat(this.duration,".0s"),!0),this.timer=window.setTimeout((()=>this.remove()),1e3*this.duration))}stopTimer(){this.timerTrans&&this.timerTrans.cancel(),this.timer&&window.clearTimeout(this.timer)}}},6277:function(t,e,n){"use strict";n.d(e,{Z:function(){return r}});n(1515);class r extends Snowboard.Singleton{dependencies(){return["request"]}listens(){return{ready:"ready",ajaxStart:"ajaxStart"}}ready(){this.counter=0,this.createStripe()}ajaxStart(t){this.show(),t.catch((()=>{this.hide()})).finally((()=>{this.hide()}))}createStripe(){this.indicator=document.createElement("DIV"),this.stripe=document.createElement("DIV"),this.stripeLoaded=document.createElement("DIV"),this.indicator.classList.add("stripe-loading-indicator","loaded"),this.stripe.classList.add("stripe"),this.stripeLoaded.classList.add("stripe-loaded"),this.indicator.appendChild(this.stripe),this.indicator.appendChild(this.stripeLoaded),document.body.appendChild(this.indicator)}show(){this.counter+=1;const t=this.stripe.cloneNode(!0);this.indicator.appendChild(t),this.stripe.remove(),this.stripe=t,this.counter>1||(this.indicator.classList.remove("loaded"),document.body.classList.add("wn-loading"))}hide(t){this.counter-=1,!0===t&&(this.counter=0),this.counter<=0&&(this.indicator.classList.add("loaded"),document.body.classList.remove("wn-loading"))}}},8032:function(t,e,n){"use strict";n.d(e,{Z:function(){return r}});class r extends Snowboard.Singleton{listens(){return{ready:"ready"}}ready(){let t=!1;if(document.querySelectorAll('link[rel="stylesheet"]').forEach((e=>{e.href.endsWith("/modules/system/assets/css/snowboard.extras.css")&&(t=!0)})),!t){const t=document.createElement("link");t.setAttribute("rel","stylesheet"),t.setAttribute("href",this.snowboard.url().to("/modules/system/assets/css/snowboard.extras.css")),document.head.appendChild(t)}}}},8269:function(t,e,n){"use strict";n.d(e,{Z:function(){return r}});n(6886);class r extends Snowboard.PluginBase{constructor(t,e,n,r,o,i){if(super(t),e instanceof HTMLElement==!1)throw new Error("A HTMLElement must be provided for transitioning");if(this.element=e,"string"!=typeof n)throw new Error("Transition name must be specified as a string");if(this.transition=n,r&&"function"!=typeof r)throw new Error("Callback must be a valid function");this.callback=r,this.duration=o?this.parseDuration(o):null,this.trailTo=!0===i,this.doTransition()}eventClasses(){for(var t=arguments.length,e=new Array(t),n=0;n{const[n,r]=t;-1!==e.indexOf(n)&&o.push(r)})),o}doTransition(){null!==this.duration&&(this.element.style.transitionDuration=this.duration),this.resetClasses(),this.eventClasses("in","active").forEach((t=>{this.element.classList.add(t)})),window.requestAnimationFrame((()=>{"0s"!==window.getComputedStyle(this.element)["transition-duration"]?(this.element.addEventListener("transitionend",(()=>this.onTransitionEnd()),{once:!0}),window.requestAnimationFrame((()=>{this.element.classList.remove(this.eventClasses("in")[0]),this.element.classList.add(this.eventClasses("out")[0])}))):(this.resetClasses(),this.callback&&this.callback.apply(this.element),this.destructor())}))}onTransitionEnd(){this.eventClasses("active",this.trailTo?"":"out").forEach((t=>{this.element.classList.remove(t)})),this.callback&&this.callback.apply(this.element),null!==this.duration&&(this.element.style.transitionDuration=null),this.destructor()}cancel(){this.element.removeEventListener("transitionend",(()=>this.onTransitionEnd),{once:!0}),this.resetClasses(),null!==this.duration&&(this.element.style.transitionDuration=null),this.destructor()}resetClasses(){this.eventClasses().forEach((t=>{this.element.classList.remove(t)}))}parseDuration(t){const e=/^([0-9]+(\.[0-9]+)?)(m?s)?$/.exec(t),n=Number(e[1]),r="s"===e[3]?"sec":"msec";return"".concat("sec"===r?1e3*n:Math.floor(n),"ms")}}},1705:function(t,e,n){"use strict";n.d(e,{Z:function(){return p}});n(6886);class r{constructor(t){this.snowboard=t}dependencies(){return[]}listens(){return{}}destructor(){this.detach(),delete this.snowboard}}class o extends r{}class i{constructor(t,e,n){this.name=t,this.snowboard=e,this.instance=n,this.instances=[],this.singleton=n.prototype instanceof o,this.initialised=n.prototype instanceof r,this.mocks={},this.originalFunctions={}}hasMethod(t){return!this.isFunction()&&"function"==typeof this.instance.prototype[t]}callMethod(){if(this.isFunction())return null;for(var t=arguments.length,e=new Array(t),n=0;n!this.snowboard.getPluginNames().includes(t)));throw new Error('The "'.concat(this.name,'" plugin requires the following plugins: ').concat(t.join(", ")))}if(this.isSingleton())return 0===this.instances.length&&this.initialiseSingleton(),Object.keys(this.mocks).length>0&&(Object.entries(this.originalFunctions).forEach((t=>{const[e,n]=t;this.instances[0][e]=n})),Object.entries(this.mocks).forEach((e=>{const[n,r]=e;this.instances[0][n]=function(){for(var e=arguments.length,n=new Array(e),o=0;o0&&(Object.entries(this.originalFunctions).forEach((t=>{const[e,n]=t;this.instance.prototype[e]=n})),Object.entries(this.mocks).forEach((e=>{const[n,r]=e;this.instance.prototype[n]=function(){for(var e=arguments.length,n=new Array(e),o=0;othis.instances.splice(this.instances.indexOf(o),1),this.instances.push(o),o}getInstances(){return this.isFunction()?[]:this.instances}isFunction(){return"function"==typeof this.instance&&this.instance.prototype instanceof r==!1}isSingleton(){return this.instance.prototype instanceof o==!0}isInitialised(){return this.initialised}initialiseSingleton(){if(!this.isSingleton())return;const t=new this.instance(this.snowboard);t.detach=()=>this.instances.splice(this.instances.indexOf(t),1),this.instances.push(t),this.initialised=!0}getDependencies(){return this.isFunction()||"function"!=typeof this.instance.prototype.dependencies?[]:this.instance.prototype.dependencies().map((t=>t.toLowerCase()))}dependenciesFulfilled(){const t=this.getDependencies();let e=!0;return t.forEach((t=>{this.snowboard.hasPlugin(t)||(e=!1)})),e}mock(t,e){var n=this;if(!this.isFunction()){if(!this.instance.prototype[t])throw new Error('Function "'.concat(t,'" does not exist and cannot be mocked'));this.mocks[t]=e,this.originalFunctions[t]=this.instance.prototype[t],this.isSingleton()&&0===this.instances.length&&(this.initialiseSingleton(),this.instances[0][t]=function(){for(var t=arguments.length,r=new Array(t),o=0;o{const[e,n]=t;void 0!==this.defaults[e]&&(this.defaults[e]=n)}))}getDefaults(){const t={};return Object.entries(this.defaults).forEach((e=>{const[n,r]=e;null!==this.defaults[n]&&(t[n]=r)})),t}get(t){if(void 0===t){const t=s.Z.get();return Object.entries(t).forEach((e=>{const[n,r]=e;this.snowboard.globalEvent("cookie.get",n,r,(e=>{t[n]=e}))})),t}let e=s.Z.get(t);return this.snowboard.globalEvent("cookie.get",t,e,(t=>{e=t})),e}set(t,e,n){let r=e;return this.snowboard.globalEvent("cookie.set",t,e,(t=>{r=t})),s.Z.set(t,r,c(c({},this.getDefaults()),n))}remove(t,e){s.Z.remove(t,c(c({},this.getDefaults()),e))}}class h extends o{constructor(t){super(t),window.wnJSON=t=>this.parse(t),window.ocJSON=window.wnJSON}parse(t){const e=this.parseString(t);return JSON.parse(e)}parseString(t){let e=t.trim();if(!e.length)throw new Error("Broken JSON object.");let n="",r=null,o=null,i="";for(;e&&","===e[0];)e=e.substr(1);if('"'===e[0]||"'"===e[0]){if(e[e.length-1]!==e[0])throw new Error("Invalid string JSON object.");i='"';for(let t=1;t="0"&&t[e]<="9"){n="";for(let r=e;r="0"&&t[r]<="9"))return{originLength:n.length,body:n};n+=t[r]}throw new Error("Broken JSON number body near ".concat(n))}if("{"===t[e]||"["===t[e]){const r=[t[e]];n=t[e];for(let o=e+1;o=0?e-5:0,50)))}parseKey(t,e,n){let r="";for(let o=e;o="a"&&t[0]<="z"||t[0]>="A"&&t[0]<="Z"||"_"===t[0]||(t[0]>="0"&&t[0]<="9"||("$"===t[0]||t.charCodeAt(0)>255)))}isBlankChar(t){return" "===t||"\n"===t||"\t"===t}}class f extends o{constructor(t){super(t),window.wnSanitize=t=>this.sanitize(t),window.ocSanitize=window.wnSanitize}sanitize(t,e){const n=(new DOMParser).parseFromString(t,"text/html"),r=void 0===e||"boolean"!=typeof e||e;return this.sanitizeNode(n.getRootNode()),r?n.body.innerHTML:n.innerHTML}sanitizeNode(t){if("SCRIPT"===t.tagName)return void t.remove();this.trimAttributes(t);Array.from(t.children).forEach((t=>{this.sanitizeNode(t)}))}trimAttributes(t){if(t.attributes)for(let e=0;e{this.autoInitSingletons&&this.initialiseSingletons(),this.globalEvent("ready"),this.domReady=!0}))}initialiseSingletons(){Object.values(this.plugins).forEach((t=>{t.isSingleton()&&t.dependenciesFulfilled()&&t.initialiseSingleton()}))}addPlugin(t,e){var n=this;const o=t.toLowerCase();if(this.hasPlugin(o))throw new Error('A plugin called "'.concat(t,'" is already registered.'));if("function"!=typeof e&&e instanceof r==!1)throw new Error("The provided plugin must extend the PluginBase class, or must be a callback function.");if(void 0!==this[t]||void 0!==this[o])throw new Error("The given name is already in use for a property or method of the Snowboard class.");this.plugins[o]=new i(o,this,e);const s=function(){return n.plugins[o].getInstance(...arguments)};this[t]=s,this[o]=s,this.debug('Plugin "'.concat(t,'" registered')),Object.values(this.getPlugins()).forEach((t=>{if(t.isSingleton()&&!t.isInitialised()&&t.dependenciesFulfilled()&&t.hasMethod("listens")&&Object.keys(t.callMethod("listens")).includes("ready")&&this.domReady){const e=t.callMethod("listens").ready;t.callMethod(e)}}))}removePlugin(t){const e=t.toLowerCase();this.hasPlugin(e)?(this.plugins[e].getInstances().forEach((t=>{t.destructor()})),delete this.plugins[e],delete this[e],delete this[t],this.debug('Plugin "'.concat(t,'" removed'))):this.debug('Plugin "'.concat(t,'" already removed'))}hasPlugin(t){const e=t.toLowerCase();return void 0!==this.plugins[e]}getPlugins(){return this.plugins}getPluginNames(){return Object.keys(this.plugins)}getPlugin(t){if(!this.hasPlugin(t))throw new Error('No plugin called "'.concat(t,'" has been registered.'));return this.plugins[t]}listensToEvent(t){const e=[];return Object.entries(this.plugins).forEach((n=>{const[r,o]=n;if(o.isFunction())return;if(!o.dependenciesFulfilled())return;if(!o.hasMethod("listens"))return;"string"==typeof o.callMethod("listens")[t]&&e.push(r)})),e}ready(t){this.domReady&&t(),this.on("ready",t)}on(t,e){this.listeners[t]||(this.listeners[t]=[]),this.listeners[t].includes(e)||this.listeners[t].push(e)}off(t,e){if(!this.listeners[t])return;const n=this.listeners[t].indexOf(e);-1!==n&&this.listeners[t].splice(n,1)}globalEvent(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r{const r=this.getPlugin(e);if(r.isFunction())return;r.isSingleton()&&0===r.getInstances().length&&r.initialiseSingleton();const o=r.callMethod("listens")[t];r.getInstances().forEach((r=>{if(!i){if(!r[o])throw new Error('Missing "'.concat(o,'" method in "').concat(e,'" plugin'));!1===r[o](...n)&&(i=!0,this.debug('Global event "'.concat(t,'" cancelled by "').concat(e,'" plugin')))}}))})),!i&&this.listeners[t]&&this.listeners[t].length>0&&(this.debug("Found ".concat(this.listeners[t].length,' ad-hoc listener(s) for global event "').concat(t,'"')),this.listeners[t].forEach((e=>{i||!1===e(...n)&&(i=!0,this.debug('Global event "'.concat(t," cancelled by an ad-hoc listener.")))}))),!i}globalPromiseEvent(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r{const r=this.getPlugin(e);if(r.isFunction())return;r.isSingleton()&&0===r.getInstances().length&&r.initialiseSingleton();const o=r.callMethod("listens")[t];r.getInstances().forEach((t=>{const e=t[o](...n);e instanceof Promise!=!1&&i.push(e)}))})),this.listeners[t]&&this.listeners[t].length>0&&(this.debug("Found ".concat(this.listeners[t].length,' ad-hoc listener(s) for global promise event "').concat(t,'"')),this.listeners[t].forEach((t=>{const e=t(...n);e instanceof Promise!=!1&&i.push(e)}))),0===i.length?Promise.resolve():Promise.all(i)}debug(t){if(this.debugEnabled){console.groupCollapsed("%c[Snowboard]","color: rgb(45, 167, 199); font-weight: normal;",t);for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r{t+=1,console.log("%c".concat(t,":"),"color: rgb(88, 88, 88); font-weight: normal;",e)})),console.groupEnd(),console.groupCollapsed("%cTrace","color: rgb(45, 167, 199); font-weight: bold;"),console.trace(),console.groupEnd()}else console.trace();console.groupEnd()}}}},4136:function(t,e,n){"use strict";var r=n(2270),o=n(8269),i=n(9553),s=n(6277),a=n(8032),c=n(8809),l=n(5763);if(void 0===window.Snowboard)throw new Error("Snowboard must be loaded in order to use the extra plugins.");(t=>{t.addPlugin("assetLoader",c.Z),t.addPlugin("dataConfig",l.Z),t.addPlugin("extrasStyles",a.Z),t.addPlugin("transition",o.Z),t.addPlugin("flash",r.Z),t.addPlugin("attachLoading",i.Z),t.addPlugin("stripeLoader",s.Z)})(window.Snowboard)},2165:function(t,e,n){"use strict";var r=n(1705);(t=>{const e=new r.Z(!0,!0);t.snowboard=e,t.Snowboard=e,t.SnowBoard=e})(window)},7111:function(t,e,n){var r=n(9859),o=n(6733),i=n(9821),s=r.TypeError;t.exports=function(t){if(o(t))return t;throw s(i(t)+" is not a function")}},7988:function(t,e,n){var r=n(9859),o=n(2359),i=n(9821),s=r.TypeError;t.exports=function(t){if(o(t))return t;throw s(i(t)+" is not a constructor")}},8505:function(t,e,n){var r=n(9859),o=n(6733),i=r.String,s=r.TypeError;t.exports=function(t){if("object"==typeof t||o(t))return t;throw s("Can't set "+i(t)+" as a prototype")}},9736:function(t,e,n){var r=n(95),o=n(2391),i=n(1787),s=r("unscopables"),a=Array.prototype;null==a[s]&&i.f(a,s,{configurable:!0,value:o(null)}),t.exports=function(t){a[s][t]=!0}},6637:function(t,e,n){"use strict";var r=n(966).charAt;t.exports=function(t,e,n){return e+(n?r(t,e).length:1)}},1176:function(t,e,n){var r=n(9859),o=n(5052),i=r.String,s=r.TypeError;t.exports=function(t){if(o(t))return t;throw s(i(t)+" is not an object")}},9540:function(t,e,n){var r=n(905),o=n(3231),i=n(9646),s=function(t){return function(e,n,s){var a,c=r(e),l=i(c),u=o(s,l);if(t&&n!=n){for(;l>u;)if((a=c[u++])!=a)return!0}else for(;l>u;u++)if((t||u in c)&&c[u]===n)return t||u||0;return!t&&-1}};t.exports={includes:s(!0),indexOf:s(!1)}},7079:function(t,e,n){var r=n(5968),o=r({}.toString),i=r("".slice);t.exports=function(t){return i(o(t),8,-1)}},1589:function(t,e,n){var r=n(9859),o=n(1601),i=n(6733),s=n(7079),a=n(95)("toStringTag"),c=r.Object,l="Arguments"==s(function(){return arguments}());t.exports=o?s:function(t){var e,n,r;return void 0===t?"Undefined":null===t?"Null":"string"==typeof(n=function(t,e){try{return t[e]}catch(t){}}(e=c(t),a))?n:l?s(e):"Object"==(r=s(e))&&i(e.callee)?"Arguments":r}},7081:function(t,e,n){var r=n(8270),o=n(4826),i=n(7933),s=n(1787);t.exports=function(t,e,n){for(var a=o(e),c=s.f,l=i.f,u=0;u0&&r[0]<4?1:+(r[0]+r[1])),!o&&s&&(!(r=s.match(/Edge\/(\d+)/))||r[1]>=74)&&(r=s.match(/Chrome\/(\d+)/))&&(o=+r[1]),t.exports=o},3837:function(t){t.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]},3103:function(t,e,n){var r=n(9859),o=n(7933).f,i=n(5762),s=n(7487),a=n(2079),c=n(7081),l=n(6541);t.exports=function(t,e){var n,u,h,f,d,p=t.target,g=t.global,v=t.stat;if(n=g?r:v?r[p]||a(p,{}):(r[p]||{}).prototype)for(u in e){if(f=e[u],h=t.noTargetGet?(d=o(n,u))&&d.value:n[u],!l(g?u:p+(v?".":"#")+u,t.forced)&&void 0!==h){if(typeof f==typeof h)continue;c(f,h)}(t.sham||h&&h.sham)&&i(f,"sham",!0),s(n,u,f,t)}}},4229:function(t){t.exports=function(t){try{return!!t()}catch(t){return!0}}},4954:function(t,e,n){"use strict";n(7950);var r=n(5968),o=n(7487),i=n(3466),s=n(4229),a=n(95),c=n(5762),l=a("species"),u=RegExp.prototype;t.exports=function(t,e,n,h){var f=a(t),d=!s((function(){var e={};return e[f]=function(){return 7},7!=""[t](e)})),p=d&&!s((function(){var e=!1,n=/a/;return"split"===t&&((n={}).constructor={},n.constructor[l]=function(){return n},n.flags="",n[f]=/./[f]),n.exec=function(){return e=!0,null},n[f](""),!e}));if(!d||!p||n){var g=r(/./[f]),v=e(f,""[t],(function(t,e,n,o,s){var a=r(t),c=e.exec;return c===i||c===u.exec?d&&!s?{done:!0,value:g(e,n,o)}:{done:!0,value:a(n,e,o)}:{done:!1}}));o(String.prototype,t,v[0]),o(u,f,v[1])}h&&c(u[f],"sham",!0)}},3171:function(t,e,n){var r=n(7188),o=Function.prototype,i=o.apply,s=o.call;t.exports="object"==typeof Reflect&&Reflect.apply||(r?s.bind(i):function(){return s.apply(i,arguments)})},7188:function(t,e,n){var r=n(4229);t.exports=!r((function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")}))},266:function(t,e,n){var r=n(7188),o=Function.prototype.call;t.exports=r?o.bind(o):function(){return o.apply(o,arguments)}},1805:function(t,e,n){var r=n(7400),o=n(8270),i=Function.prototype,s=r&&Object.getOwnPropertyDescriptor,a=o(i,"name"),c=a&&"something"===function(){}.name,l=a&&(!r||r&&s(i,"name").configurable);t.exports={EXISTS:a,PROPER:c,CONFIGURABLE:l}},5968:function(t,e,n){var r=n(7188),o=Function.prototype,i=o.bind,s=o.call,a=r&&i.bind(s,s);t.exports=r?function(t){return t&&a(t)}:function(t){return t&&function(){return s.apply(t,arguments)}}},1333:function(t,e,n){var r=n(9859),o=n(6733),i=function(t){return o(t)?t:void 0};t.exports=function(t,e){return arguments.length<2?i(r[t]):r[t]&&r[t][e]}},5300:function(t,e,n){var r=n(7111);t.exports=function(t,e){var n=t[e];return null==n?void 0:r(n)}},17:function(t,e,n){var r=n(5968),o=n(2991),i=Math.floor,s=r("".charAt),a=r("".replace),c=r("".slice),l=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,u=/\$([$&'`]|\d{1,2})/g;t.exports=function(t,e,n,r,h,f){var d=n+t.length,p=r.length,g=u;return void 0!==h&&(h=o(h),g=l),a(f,g,(function(o,a){var l;switch(s(a,0)){case"$":return"$";case"&":return t;case"`":return c(e,0,n);case"'":return c(e,d);case"<":l=h[c(a,1,-1)];break;default:var u=+a;if(0===u)return o;if(u>p){var f=i(u/10);return 0===f?o:f<=p?void 0===r[f-1]?s(a,1):r[f-1]+s(a,1):o}l=r[u-1]}return void 0===l?"":l}))}},9859:function(t,e,n){var r=function(t){return t&&t.Math==Math&&t};t.exports=r("object"==typeof globalThis&&globalThis)||r("object"==typeof window&&window)||r("object"==typeof self&&self)||r("object"==typeof n.g&&n.g)||function(){return this}()||Function("return this")()},8270:function(t,e,n){var r=n(5968),o=n(2991),i=r({}.hasOwnProperty);t.exports=Object.hasOwn||function(t,e){return i(o(t),e)}},5977:function(t){t.exports={}},3777:function(t,e,n){var r=n(1333);t.exports=r("document","documentElement")},4394:function(t,e,n){var r=n(7400),o=n(4229),i=n(2635);t.exports=!r&&!o((function(){return 7!=Object.defineProperty(i("div"),"a",{get:function(){return 7}}).a}))},9337:function(t,e,n){var r=n(9859),o=n(5968),i=n(4229),s=n(7079),a=r.Object,c=o("".split);t.exports=i((function(){return!a("z").propertyIsEnumerable(0)}))?function(t){return"String"==s(t)?c(t,""):a(t)}:a},8511:function(t,e,n){var r=n(5968),o=n(6733),i=n(5353),s=r(Function.toString);o(i.inspectSource)||(i.inspectSource=function(t){return s(t)}),t.exports=i.inspectSource},6407:function(t,e,n){var r,o,i,s=n(8694),a=n(9859),c=n(5968),l=n(5052),u=n(5762),h=n(8270),f=n(5353),d=n(4399),p=n(5977),g="Object already initialized",v=a.TypeError,b=a.WeakMap;if(s||f.state){var m=f.state||(f.state=new b),y=c(m.get),w=c(m.has),E=c(m.set);r=function(t,e){if(w(m,t))throw new v(g);return e.facade=t,E(m,t,e),e},o=function(t){return y(m,t)||{}},i=function(t){return w(m,t)}}else{var x=d("state");p[x]=!0,r=function(t,e){if(h(t,x))throw new v(g);return e.facade=t,u(t,x,e),e},o=function(t){return h(t,x)?t[x]:{}},i=function(t){return h(t,x)}}t.exports={set:r,get:o,has:i,enforce:function(t){return i(t)?o(t):r(t,{})},getterFor:function(t){return function(e){var n;if(!l(e)||(n=o(e)).type!==t)throw v("Incompatible receiver, "+t+" required");return n}}}},6733:function(t){t.exports=function(t){return"function"==typeof t}},2359:function(t,e,n){var r=n(5968),o=n(4229),i=n(6733),s=n(1589),a=n(1333),c=n(8511),l=function(){},u=[],h=a("Reflect","construct"),f=/^\s*(?:class|function)\b/,d=r(f.exec),p=!f.exec(l),g=function(t){if(!i(t))return!1;try{return h(l,u,t),!0}catch(t){return!1}},v=function(t){if(!i(t))return!1;switch(s(t)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return p||!!d(f,c(t))}catch(t){return!0}};v.sham=!0,t.exports=!h||o((function(){var t;return g(g.call)||!g(Object)||!g((function(){t=!0}))||t}))?v:g},6541:function(t,e,n){var r=n(4229),o=n(6733),i=/#|\.prototype\./,s=function(t,e){var n=c[a(t)];return n==u||n!=l&&(o(e)?r(e):!!e)},a=s.normalize=function(t){return String(t).replace(i,".").toLowerCase()},c=s.data={},l=s.NATIVE="N",u=s.POLYFILL="P";t.exports=s},5052:function(t,e,n){var r=n(6733);t.exports=function(t){return"object"==typeof t?null!==t:r(t)}},4231:function(t){t.exports=!1},9395:function(t,e,n){var r=n(9859),o=n(1333),i=n(6733),s=n(1321),a=n(6969),c=r.Object;t.exports=a?function(t){return"symbol"==typeof t}:function(t){var e=o("Symbol");return i(e)&&s(e.prototype,c(t))}},693:function(t,e,n){"use strict";var r,o,i,s=n(4229),a=n(6733),c=n(2391),l=n(7567),u=n(7487),h=n(95),f=n(4231),d=h("iterator"),p=!1;[].keys&&("next"in(i=[].keys())?(o=l(l(i)))!==Object.prototype&&(r=o):p=!0),null==r||s((function(){var t={};return r[d].call(t)!==t}))?r={}:f&&(r=c(r)),a(r[d])||u(r,d,(function(){return this})),t.exports={IteratorPrototype:r,BUGGY_SAFARI_ITERATORS:p}},5495:function(t){t.exports={}},9646:function(t,e,n){var r=n(4237);t.exports=function(t){return r(t.length)}},4226:function(t,e,n){var r=n(9859);t.exports=r.Promise},3839:function(t,e,n){var r=n(6358),o=n(4229);t.exports=!!Object.getOwnPropertySymbols&&!o((function(){var t=Symbol();return!String(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&r&&r<41}))},8694:function(t,e,n){var r=n(9859),o=n(6733),i=n(8511),s=r.WeakMap;t.exports=o(s)&&/native code/.test(i(s))},6485:function(t,e,n){"use strict";var r=n(7111),o=function(t){var e,n;this.promise=new t((function(t,r){if(void 0!==e||void 0!==n)throw TypeError("Bad Promise constructor");e=t,n=r})),this.resolve=r(e),this.reject=r(n)};t.exports.f=function(t){return new o(t)}},2391:function(t,e,n){var r,o=n(1176),i=n(219),s=n(3837),a=n(5977),c=n(3777),l=n(2635),u=n(4399),h=u("IE_PROTO"),f=function(){},d=function(t){return"