@fancyapps/ui
Version:
Robust JavaScript UI Component Library
1 lines • 2 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 l(){o&&(o.replaceChildren(),o.style.display="none"),e?.getContainer()?.classList.remove("has-dots")}function s(e=-1){o?.querySelectorAll("[data-carousel-go-to]").forEach(t=>{parseInt(t.dataset?.carouselGoTo||"-1",10)===e?t.classList.add("is-selected"):t.classList.remove("is-selected")})}function r(){s(e?.getPageIndex())}function a(){e&&e.getPages().length!==(o?o.childElementCount:-1)&&(l(),function(){if(!e||!1===e.getOptions().Dots)return;let n=e.getPages().length,l=e.getContainer();if(!(n<i("minCount")||n>i("maxCount"))&&l){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 l=0;l<n;l++){let n=i("dotTpl")||"%d",s=t(e.localize(n,[["%d",l+1]]).replace(/\%i/g,l+""));s&&o.appendChild(s)}s(e.getPageIndex()),o.style.display="",l.classList.add("has-dots")}}())}return{init:function(t){(e=t).on("refresh",a),e.on("change",r)},destroy:function(){l(),e?.off("refresh",a),e?.off("change",r),e=void 0}}}});