@fancyapps/ui
Version:
Robust JavaScript UI Component Library
1 lines • 1.72 kB
JavaScript
!/*! License details at fancyapps.com/license */function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).window=e.window||{})}(this,function(e){"use strict";let t=function(e){var t=new DOMParser().parseFromString(e,"text/html").body;if(t.childElementCount>1){for(var n=document.createElement("div");t.firstChild;)n.appendChild(t.firstChild);return n}let o=t.firstChild;if(o&&!(o instanceof HTMLElement)){var n=document.createElement("div");return n.appendChild(o),n}return o},n={dotTpl:'<button class="f-carousel__dot" data-carousel-go-to="%i" aria-label="{{GOTO}}"></button>',maxCount:1/0,minCount:2};e.Dots=()=>{let e,o;function i(t){let o=e?.getOptions().Dots;return("object"==typeof o&&null!==o&&o.constructor===Object&&"[object Object]"===Object.prototype.toString.call(o)?{...n,...o}:n)[t]}function r(){o&&(o.replaceChildren(),o.style.display="none"),e?.getContainer()?.classList.remove("has-dots")}function l(){e&&e.getPages().length!==(o?o.childElementCount:-1)&&(r(),function(){if(!e||!1===e.getOptions().Dots)return;let n=e.getPages().length,r=e.getContainer();if(!(n<i("minCount")||n>i("maxCount"))&&r){o||(o=e.getContainer()?.querySelector(".f-carousel__dots")||void 0),o||((o=document.createElement("div")).classList.add("f-carousel__dots"),e.getViewport()?.insertAdjacentElement("afterend",o));for(let r=0;r<n;r++){let n=i("dotTpl")||"%d",l=t(e.localize(n,[["%d",r+1]]).replace(/\%i/g,r+""));l&&o.appendChild(l)}o.style.display="",r.classList.add("has-dots")}}())}return{init:function(t){(e=t).on("refresh",l)},destroy:function(){r(),e?.off("refresh",l),e=void 0}}}});