@salla.sa/twilight-components
Version:
Salla Web Component
5 lines • 3.23 kB
JavaScript
/*!
* Crafted with ❤ by Salla
*/
System.register(["./p-f422bbf9.system.js","./p-8f7b9e36.system.js"],(function(t){"use strict";var e,n,i,s;return{setters:[function(t){e=t.r;n=t.h;i=t.g},function(t){s=t.a}],execute:function(){var r=":host{display:block}";var a=t("salla_advertisement",function(){function t(t){var n=this;e(this,t);var i;this.position=undefined;this.advertisements=undefined;this.advertIcon=undefined;this.currentSlug=salla.config.get("page.slug");salla.onReady((function(){n.currentSlug=salla.config.get("page.slug")}));this.advSlot=((i=this.host.querySelector('[slot="adv"]'))===null||i===void 0?void 0:i.innerHTML)||'<div class="s-advertisement-content"><h2 class="s-advertisement-content-main">{iconElem}{urlElem}</h2>{closeElem}</div>\n '}t.prototype.isNotVisible=function(t){return!!salla.storage.get("statusAd-".concat(t.id))};t.prototype.setCanDisplayFlag=function(t,e){if(!e){salla.storage.set("statusAd-".concat(t.id),"dismissed");s({targets:this.host,opacity:[1,0],duration:300,height:[this.host.clientHeight,0],easing:"easeInOutQuad"})}};t.prototype.render=function(){var t=this;if(Array.isArray(this.advertisements)&&!this.advertisements.length||!this.advertisements){return}return this.advertisements.map((function(e){return n("div",{class:{"s-hidden":t.isNotVisible(e),"s-advertisement":true},"data-id":e.id,style:{"background-color":e.colors.bg,color:e.colors.text}},n("div",{id:"adv-slot",innerHTML:t.advSlot.replace("{iconElem}",'<i class="s-advertisement-content-icon '.concat(e.icon,'"></i>')).replace("{urlElem}",e.url?'<a href="'.concat(e.url,'" target="').concat(e.target,'">').concat(e.description,"</a>"):e.description).replace("{closeElem}",'<button class="s-advertisement-action" aria-label="close-alert"><i class="sicon-cancel"></i></button>').replace("{icon}",e.icon).replace("{url}",e.url).replace("{target}",e.target).replace("{description}",e.description).replace("{bg_color}",e.colors.bg).replace("{text_color}",e.colors.text)}))}))};t.prototype.componentWillLoad=function(){var t=this;return new Promise((function(t){return salla.onReady(t)})).then((function(){return salla.api.advertisement.fetch(t.currentSlug)})).then((function(t){return Array.isArray(t.data)?t.data.find((function(t){return!salla.storage.get("statusAd-".concat(t.id))})):null})).then((function(e){return t.advertisements=e?[e]:[]}))};t.prototype.componentDidRender=function(){var t=this;var e;if(Array.isArray(this.advertisements)&&!this.advertisements.length||!this.advertisements){return}setTimeout((function(){var e=t.host.querySelector(".s-advertisement-action");if(e){e.addEventListener("click",(function(){return t.setCanDisplayFlag(t.advertisements[0],false)}))}}));this.host.querySelectorAll("#adv-slot").forEach((function(t){return t===null||t===void 0?void 0:t.replaceWith(t===null||t===void 0?void 0:t.firstChild)}));(e=this.host.querySelector('[slot="adv"]'))===null||e===void 0?void 0:e.remove();s({targets:this.host,opacity:[0,1],duration:300,height:[0,this.host.clientHeight],easing:"easeInOutQuad"})};Object.defineProperty(t.prototype,"host",{get:function(){return i(this)},enumerable:false,configurable:true});return t}());a.style=r}}}));
//# sourceMappingURL=p-2e845bd2.system.entry.js.map