UNPKG

@fancyapps/ui

Version:

Robust JavaScript UI Component Library

1 lines 1.9 kB
!/*! 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=null;function i(){let t=e?.getOptions().Dots;return"object"==typeof t&&null!==t&&t.constructor===Object&&"[object Object]"===Object.prototype.toString.call(t)?{...n,...t}:n}function l(){o?.parentElement?.removeChild(o),o=null,e?.getContainer()?.classList.remove("has-dots")}function r(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 s(){r(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=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",r=t(e.localize(n,[["%d",l+1]]).replace(/\%i/g,l+""));r&&o.appendChild(r)}r(e.getPageIndex()),l.classList.add("has-dots")}}())}return{init:function(t){(e=t).on("refresh",a),e.on("change",s)},destroy:function(){l(),e?.off("refresh",a),e?.off("change",s),e=void 0}}}});