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