From 581079a20c111adcd55bbc5890e0c49b0e88742e Mon Sep 17 00:00:00 2001 From: Ben Thomson Date: Fri, 16 Sep 2022 09:37:35 +0800 Subject: [PATCH] Add ability to define local config overrides in DataConfig This will enable the ability to override data attribute config values on the JavaScript side. This can be useful for per-instance overrides derived from other frontend code, and saves developers having to override data attributes using JavaScript. --- modules/system/assets/js/build/manifest.js | 2 +- modules/system/assets/js/build/system.js | 2 +- .../js/snowboard/build/snowboard.base.debug.js | 2 +- .../assets/js/snowboard/build/snowboard.base.js | 2 +- .../js/snowboard/build/snowboard.data-attr.js | 2 +- .../assets/js/snowboard/build/snowboard.extras.js | 2 +- .../assets/js/snowboard/build/snowboard.request.js | 2 +- .../assets/js/snowboard/build/snowboard.vendor.js | 2 +- .../system/assets/js/snowboard/extras/DataConfig.js | 13 ++++++++++++- 9 files changed, 20 insertions(+), 9 deletions(-) diff --git a/modules/system/assets/js/build/manifest.js b/modules/system/assets/js/build/manifest.js index 15c3878c3..6bb0026d2 100644 --- a/modules/system/assets/js/build/manifest.js +++ b/modules/system/assets/js/build/manifest.js @@ -1 +1 @@ -!function(){"use strict";var n,r={},t={};function e(n){var o=t[n];if(void 0!==o)return o.exports;var u=t[n]={exports:{}};return r[n](u,u.exports,e),u.exports}e.m=r,n=[],e.O=function(r,t,o,u){if(!t){var i=1/0;for(a=0;a=u)&&Object.keys(e.O).every((function(n){return e.O[n](t[c])}))?t.splice(c--,1):(f=!1,u0&&n[a-1][2]>u;a--)n[a]=n[a-1];n[a]=[t,o,u]},e.n=function(n){var r=n&&n.__esModule?function(){return n.default}:function(){return n};return e.d(r,{a:r}),r},e.d=function(n,r){for(var t in r)e.o(r,t)&&!e.o(n,t)&&Object.defineProperty(n,t,{enumerable:!0,get:r[t]})},e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(n){if("object"==typeof window)return window}}(),e.o=function(n,r){return Object.prototype.hasOwnProperty.call(n,r)},function(){var n={911:0};e.O.j=function(r){return 0===n[r]};var r=function(r,t){var o,u,i=t[0],f=t[1],c=t[2],s=0;if(i.some((function(r){return 0!==n[r]}))){for(o in f)e.o(f,o)&&(e.m[o]=f[o]);if(c)var a=c(e)}for(r&&r(t);s=i)&&Object.keys(t.O).every((function(r){return t.O[r](e[c])}))?e.splice(c--,1):(f=!1,i0&&r[a-1][2]>i;a--)r[a]=r[a-1];r[a]=[e,o,i]},t.d=function(r,n){for(var e in n)t.o(n,e)&&!t.o(r,e)&&Object.defineProperty(r,e,{enumerable:!0,get:n[e]})},t.o=function(r,n){return Object.prototype.hasOwnProperty.call(r,n)},function(){var r={911:0};t.O.j=function(n){return 0===r[n]};var n=function(n,e){var o,i,u=e[0],f=e[1],c=e[2],s=0;if(u.some((function(n){return 0!==r[n]}))){for(o in f)t.o(f,o)&&(t.m[o]=f[o]);if(c)var a=c(t)}for(n&&n(e);s{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(s(s({},e),{},{X_WINTER_SUCCESS:406!==n.status,X_WINTER_RESPONSE_CODE:n.status}))}),(t=>{e(this.renderError(`Unable to parse JSON response: ${t}`))})):n.text().then((e=>{t(e)}),(t=>{e(this.renderError(`Unable to process response: ${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: ${t}`))})):n.text().then((t=>{e(this.renderError(t))}),(t=>{e(this.renderError(`Unable to process response: ${t}`))}))}),(t=>{e(this.renderError(`Unable to retrieve a response from the server: ${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 s=this.options.update&&this.options.update[e]?this.options.update[e]:e,i="replace";"@"===s.substr(0,1)?(i="append",s=s.substr(1)):"^"===s.substr(0,1)?(i="prepend",s=s.substr(1)):"#"!==s.substr(0,1)&&"."!==s.substr(0,1)&&(i="noop");const o=document.querySelectorAll(s);o.length>0&&o.forEach((t=>{switch(i){case"append":t.innerHTML+=r;break;case"prepend":t.innerHTML=r+t.innerHTML;break;case"noop":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||!1!==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||!1!==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)}this.destruct()}get form(){return this.options.form?"string"==typeof this.options.form?document.querySelector(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,s){const i=new Error(t);return i.exception=e||null,i.file=n||null,i.line=r||null,i.trace=s||[],i}}Snowboard.addPlugin("request",o)},8809:function(t,e,n){"use strict";n.d(e,{Z:function(){return r}});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="${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: "${t}"`))})),document.body.append(r)}))}loadStyle(t){return new Promise(((e,n)=>{if(document.querySelector(`link[rel="stylesheet"][href="${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: "${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: "${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(9529);class r extends Snowboard.PluginBase{construct(t,e){if(t instanceof Snowboard.PluginBase==!1)throw new Error("You must provide a Snowboard plugin to enable data configuration");if(e instanceof HTMLElement==!1)throw new Error("Data configuration can only be extracted from HTML elements");this.instance=t,this.element=e,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{construct(t,e,n){if(this.message=t,this.type=e||"default",this.duration=Number(n||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"]}destruct(){null!==this.timer&&window.clearTimeout(this.timer),this.flashTimer&&this.flashTimer.remove(),this.flash&&(this.flash.remove(),this.flash=null,this.flashTimer=null),super.destruct()}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.destruct()}))}clear(){document.querySelectorAll("body > div.flash-message").forEach((t=>t.remove()))}startTimer(){0!==this.duration&&(this.timerTrans=this.snowboard.transition(this.flashTimer,"timeout",null,`${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}});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.then((()=>{this.hide()})).catch((()=>{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}});class r extends Snowboard.PluginBase{construct(t,e,n,r,s){if(t instanceof HTMLElement==!1)throw new Error("A HTMLElement must be provided for transitioning");if(this.element=t,"string"!=typeof e)throw new Error("Transition name must be specified as a string");if(this.transition=e,n&&"function"!=typeof n)throw new Error("Callback must be a valid function");this.callback=n,this.duration=r?this.parseDuration(r):null,this.trailTo=!0===s,this.doTransition()}eventClasses(){for(var t=arguments.length,e=new Array(t),n=0;n{const[n,r]=t;-1!==e.indexOf(n)&&s.push(r)})),s}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.destruct())}))}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.destruct()}cancel(){this.element.removeEventListener("transitionend",(()=>this.onTransitionEnd),{once:!0}),this.resetClasses(),null!==this.duration&&(this.element.style.transitionDuration=null),this.destruct()}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]);return"sec"===("s"===e[3]?"sec":"msec")?1e3*n+"ms":`${Math.floor(n)}ms`}}},1662:function(t,e){"use strict";e.Z={get(t,e,n){if("string"==typeof e){const n=e.toLowerCase();if(t.hasPlugin(n))return function(){return Reflect.get(t,"plugins")[n].getInstance(...arguments)}}return Reflect.get(t,e,n)},has(t,e){if("string"==typeof e){const n=e.toLowerCase();if(t.hasPlugin(n))return!0}return Reflect.has(t,e)}}},5878:function(t,e,n){"use strict";n.d(e,{Z:function(){return g}});n(9529);class r{constructor(t){this.snowboard=t}construct(){}dependencies(){return[]}listens(){return{}}destruct(){this.detach(),delete this.snowboard}destructor(){this.destruct()}}class s extends r{}var i={get(t,e,n){if("string"==typeof e){const n=e.toLowerCase();if(["attachAbstracts","loadUtilities","initialise","initialiseSingletons"].includes(e))throw new Error(`You cannot use the "${e}" Snowboard method within a plugin.`);if(t.hasPlugin(n))return function(){return Reflect.get(t,"plugins")[n].getInstance(...arguments)}}return Reflect.get(t,e,n)},has(t,e){if("string"==typeof e){const n=e.toLowerCase();if(["attachAbstracts","loadUtilities","initialise","initialiseSingletons"].includes(e))return!1;if(t.hasPlugin(n))return!0}return Reflect.has(t,e)}};class o{constructor(t,e,n){this.name=t,this.snowboard=new Proxy(e,i),this.instance=n,Object.freeze(this.instance),this.instances=[],this.singleton={initialised:!1},Object.seal(this.singleton),this.mocks={},this.originalFunctions={},Object.freeze(o.prototype),Object.freeze(this)}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 "${this.name}" plugin requires the following plugins: ${t.join(", ")}`)}if(this.isSingleton())return 0===this.instances.length&&this.initialiseSingleton(...n),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),s=0;s0&&(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),s=0;sthis.instances.splice(this.instances.indexOf(s),1),s.construct(...n),this.instances.push(s),s}getInstances(){return this.isFunction()?[]:this.instances}isFunction(){return"function"==typeof this.instance&&this.instance.prototype instanceof r==!1}isSingleton(){return this.instance.prototype instanceof s==!0}isInitialised(){return!this.isSingleton()||this.singleton.initialised}initialiseSingleton(){if(!this.isSingleton())return;for(var t=arguments.length,e=new Array(t),n=0;nthis.instances.splice(this.instances.indexOf(r),1),r.construct(...e),this.instances.push(r),this.singleton.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 "${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),s=0;s{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=a.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=a.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})),a.Z.set(t,r,c(c({},this.getDefaults()),n))}remove(t,e){a.Z.remove(t,c(c({},this.getDefaults()),e))}}class d extends s{construct(){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,s=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 ${n}`)}if("{"===t[e]||"["===t[e]){const r=[t[e]];n=t[e];for(let s=e+1;s=0?e-5:0,50)}`)}parseKey(t,e,n){let r="";for(let s=e;s="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 s{construct(){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.readiness.dom=!0}))}initialiseSingletons(){Object.values(this.plugins).forEach((t=>{t.isSingleton()&&t.dependenciesFulfilled()&&t.initialiseSingleton()}))}addPlugin(t,e){const n=t.toLowerCase();if(this.hasPlugin(n))throw new Error(`A plugin called "${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[n])throw new Error("The given name is already in use for a property or method of the Snowboard class.");this.plugins[n]=new o(n,this,e),this.debug(`Plugin "${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.readiness.dom){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.destruct()})),delete this.plugins[e],delete this[e],delete this[t],this.debug(`Plugin "${t}" removed`)):this.debug(`Plugin "${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){const e=t.toLowerCase();if(!this.hasPlugin(e))throw new Error(`No plugin called "${e}" has been registered.`);return this.plugins[e]}listensToEvent(t){const e=[];return Object.entries(this.plugins).forEach((n=>{const[r,s]=n;if(s.isFunction())return;if(!s.dependenciesFulfilled())return;if(!s.hasMethod("listens"))return;"string"==typeof s.callMethod("listens")[t]&&e.push(r)})),e}ready(t){this.readiness.dom&&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 s=r.callMethod("listens")[t];r.getInstances().forEach((r=>{if(!i){if(!r[s])throw new Error(`Missing "${s}" method in "${e}" plugin`);try{!1===r[s](...n)&&(i=!0,this.debug(`Global event "${t}" cancelled by "${e}" plugin`))}catch(n){this.error(`Error thrown in "${t}" event by "${e}" plugin.`,n)}}}))})),!i&&this.listeners[t]&&this.listeners[t].length>0&&(this.debug(`Found ${this.listeners[t].length} ad-hoc listener(s) for global event "${t}"`),this.listeners[t].forEach((e=>{if(!i)try{!1===e(...n)&&(i=!0,this.debug(`Global event "${t} cancelled by an ad-hoc listener.`))}catch(e){this.error(`Error thrown in "${t}" event by an ad-hoc listener.`,e)}}))),!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 s=r.callMethod("listens")[t];r.getInstances().forEach((r=>{if(!r[s])throw new Error(`Missing "${s}" method in "${e}" plugin`);try{const t=r[s](...n);if(t instanceof Promise==!1)return;i.push(t)}catch(n){this.error(`Error thrown in "${t}" promise event by "${e}" plugin.`,n)}}))})),this.listeners[t]&&this.listeners[t].length>0&&(this.debug(`Found ${this.listeners[t].length} ad-hoc listener(s) for global promise event "${t}"`),this.listeners[t].forEach((e=>{try{const t=e(...n);if(t instanceof Promise==!1)return;i.push(t)}catch(e){this.error(`Error thrown in "${t}" promise event by an ad-hoc listener.`,e)}}))),0===i.length?Promise.resolve():Promise.all(i)}logMessage(t,e,n){console.groupCollapsed("%c[Snowboard]",`color: ${t}; font-weight: ${e?"bold":"normal"};`,n);for(var r=arguments.length,s=new Array(r>3?r-3:0),i=3;i{t+=1,console.log(`%c${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()}log(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r1?e-1:0),r=1;r1?e-1:0),r=1;r{t.addPlugin("assetLoader",l.Z),t.addPlugin("dataConfig",c.Z),t.addPlugin("extrasStyles",a.Z),t.addPlugin("transition",s.Z),t.addPlugin("flash",r.Z),t.addPlugin("attachLoading",i.Z),t.addPlugin("stripeLoader",o.Z)})(window.Snowboard)},2165:function(t,e,n){"use strict";var r=n(5878),s=n(1662);(t=>{const e=new Proxy(new r.Z(!0,!0),s.Z);t.snowboard=e,t.Snowboard=e,t.SnowBoard=e})(window)},7111:function(t,e,n){var r=n(6733),s=n(9821),i=TypeError;t.exports=function(t){if(r(t))return t;throw i(s(t)+" is not a function")}},9736:function(t,e,n){var r=n(95),s=n(2391),i=n(1787).f,o=r("unscopables"),a=Array.prototype;null==a[o]&&i(a,o,{configurable:!0,value:s(null)}),t.exports=function(t){a[o][t]=!0}},1176:function(t,e,n){var r=n(5052),s=String,i=TypeError;t.exports=function(t){if(r(t))return t;throw i(s(t)+" is not an object")}},9540:function(t,e,n){var r=n(905),s=n(3231),i=n(9646),o=function(t){return function(e,n,o){var a,l=r(e),c=i(l),h=s(o,c);if(t&&n!=n){for(;c>h;)if((a=l[h++])!=a)return!0}else for(;c>h;h++)if((t||h in l)&&l[h]===n)return t||h||0;return!t&&-1}};t.exports={includes:o(!0),indexOf:o(!1)}},7079:function(t,e,n){var r=n(5968),s=r({}.toString),i=r("".slice);t.exports=function(t){return i(s(t),8,-1)}},7081:function(t,e,n){var r=n(8270),s=n(4826),i=n(7933),o=n(1787);t.exports=function(t,e,n){for(var a=s(e),l=o.f,c=i.f,h=0;h0&&r[0]<4?1:+(r[0]+r[1])),!s&&o&&(!(r=o.match(/Edge\/(\d+)/))||r[1]>=74)&&(r=o.match(/Chrome\/(\d+)/))&&(s=+r[1]),t.exports=s},3837:function(t){t.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]},3103:function(t,e,n){var r=n(9859),s=n(7933).f,i=n(5762),o=n(4768),a=n(8400),l=n(7081),c=n(6541);t.exports=function(t,e){var n,h,u,d,f,p=t.target,g=t.global,b=t.stat;if(n=g?r:b?r[p]||a(p,{}):(r[p]||{}).prototype)for(h in e){if(d=e[h],u=t.dontCallGetSet?(f=s(n,h))&&f.value:n[h],!c(g?h:p+(b?".":"#")+h,t.forced)&&void 0!==u){if(typeof d==typeof u)continue;l(d,u)}(t.sham||u&&u.sham)&&i(d,"sham",!0),o(n,h,d,t)}}},4229:function(t){t.exports=function(t){try{return!!t()}catch(t){return!0}}},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),s=Function.prototype.call;t.exports=r?s.bind(s):function(){return s.apply(s,arguments)}},1805:function(t,e,n){var r=n(7400),s=n(8270),i=Function.prototype,o=r&&Object.getOwnPropertyDescriptor,a=s(i,"name"),l=a&&"something"===function(){}.name,c=a&&(!r||r&&o(i,"name").configurable);t.exports={EXISTS:a,PROPER:l,CONFIGURABLE:c}},5968:function(t,e,n){var r=n(7188),s=Function.prototype,i=s.bind,o=s.call,a=r&&i.bind(o,o);t.exports=r?function(t){return t&&a(t)}:function(t){return t&&function(){return o.apply(t,arguments)}}},1333:function(t,e,n){var r=n(9859),s=n(6733),i=function(t){return s(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),s=n(9650);t.exports=function(t,e){var n=t[e];return s(n)?void 0:r(n)}},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),s=n(2991),i=r({}.hasOwnProperty);t.exports=Object.hasOwn||function(t,e){return i(s(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),s=n(4229),i=n(2635);t.exports=!r&&!s((function(){return 7!=Object.defineProperty(i("div"),"a",{get:function(){return 7}}).a}))},9337:function(t,e,n){var r=n(5968),s=n(4229),i=n(7079),o=Object,a=r("".split);t.exports=s((function(){return!o("z").propertyIsEnumerable(0)}))?function(t){return"String"==i(t)?a(t,""):o(t)}:o},8511:function(t,e,n){var r=n(5968),s=n(6733),i=n(5353),o=r(Function.toString);s(i.inspectSource)||(i.inspectSource=function(t){return o(t)}),t.exports=i.inspectSource},6407:function(t,e,n){var r,s,i,o=n(1180),a=n(9859),l=n(5968),c=n(5052),h=n(5762),u=n(8270),d=n(5353),f=n(4399),p=n(5977),g="Object already initialized",b=a.TypeError,m=a.WeakMap;if(o||d.state){var w=d.state||(d.state=new m),v=l(w.get),y=l(w.has),E=l(w.set);r=function(t,e){if(y(w,t))throw b(g);return e.facade=t,E(w,t,e),e},s=function(t){return v(w,t)||{}},i=function(t){return y(w,t)}}else{var S=f("state");p[S]=!0,r=function(t,e){if(u(t,S))throw b(g);return e.facade=t,h(t,S,e),e},s=function(t){return u(t,S)?t[S]:{}},i=function(t){return u(t,S)}}t.exports={set:r,get:s,has:i,enforce:function(t){return i(t)?s(t):r(t,{})},getterFor:function(t){return function(e){var n;if(!c(e)||(n=s(e)).type!==t)throw b("Incompatible receiver, "+t+" required");return n}}}},6733:function(t){t.exports=function(t){return"function"==typeof t}},6541:function(t,e,n){var r=n(4229),s=n(6733),i=/#|\.prototype\./,o=function(t,e){var n=l[a(t)];return n==h||n!=c&&(s(e)?r(e):!!e)},a=o.normalize=function(t){return String(t).replace(i,".").toLowerCase()},l=o.data={},c=o.NATIVE="N",h=o.POLYFILL="P";t.exports=o},9650:function(t){t.exports=function(t){return null==t}},5052:function(t,e,n){var r=n(6733),s="object"==typeof document&&document.all,i=void 0===s&&void 0!==s;t.exports=i?function(t){return"object"==typeof t?null!==t:r(t)||t===s}:function(t){return"object"==typeof t?null!==t:r(t)}},4231:function(t){t.exports=!1},9395:function(t,e,n){var r=n(1333),s=n(6733),i=n(1321),o=n(6969),a=Object;t.exports=o?function(t){return"symbol"==typeof t}:function(t){var e=r("Symbol");return s(e)&&i(e.prototype,a(t))}},9646:function(t,e,n){var r=n(4237);t.exports=function(t){return r(t.length)}},6039:function(t,e,n){var r=n(4229),s=n(6733),i=n(8270),o=n(7400),a=n(1805).CONFIGURABLE,l=n(8511),c=n(6407),h=c.enforce,u=c.get,d=Object.defineProperty,f=o&&!r((function(){return 8!==d((function(){}),"length",{value:8}).length})),p=String(String).split("String"),g=t.exports=function(t,e,n){"Symbol("===String(e).slice(0,7)&&(e="["+String(e).replace(/^Symbol\(([^)]*)\)/,"$1")+"]"),n&&n.getter&&(e="get "+e),n&&n.setter&&(e="set "+e),(!i(t,"name")||a&&t.name!==e)&&(o?d(t,"name",{value:e,configurable:!0}):t.name=e),f&&n&&i(n,"arity")&&t.length!==n.arity&&d(t,"length",{value:n.arity});try{n&&i(n,"constructor")&&n.constructor?o&&d(t,"prototype",{writable:!1}):t.prototype&&(t.prototype=void 0)}catch(t){}var r=h(t);return i(r,"source")||(r.source=p.join("string"==typeof e?e:"")),t};Function.prototype.toString=g((function(){return s(this)&&u(this).source||l(this)}),"toString")},917:function(t){var e=Math.ceil,n=Math.floor;t.exports=Math.trunc||function(t){var r=+t;return(r>0?n:e)(r)}},2391:function(t,e,n){var r,s=n(1176),i=n(219),o=n(3837),a=n(5977),l=n(3777),c=n(2635),h=n(4399),u=h("IE_PROTO"),d=function(){},f=function(t){return"