UNPKG

@fancyapps/ui

Version:

Robust JavaScript UI Component Library

1 lines 1.91 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=e=>"object"==typeof e&&null!==e&&e.constructor===Object&&"[object Object]"===Object.prototype.toString.call(e),n=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},o={dotTpl:'<button class="f-carousel__dot" data-carousel-go-to="%i" aria-label="{{GOTO}}"></button>',maxCount:1/0,minCount:2};e.Dots=()=>{let e,i=null;function l(){let n=e?.getOptions().Dots;return t(n)?{...o,...n}:o}function r(){i?.parentElement?.removeChild(i),i=null,e?.getContainer()?.classList.remove("has-dots")}function s(e=-1){i?.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 a(){s(e?.getPageIndex())}function d(){e&&e.getPages().length!==(i?i.childElementCount:-1)&&(r(),function(){if(!e||!1===e.getOptions().Dots)return;let t=e.getPages().length,o=e.getContainer();if(!(t<l().minCount)&&!(t>l().maxCount)&&o){i||((i=document.createElement("div")).classList.add("f-carousel__dots"),e.getViewport()?.insertAdjacentElement("afterend",i));for(let o=0;o<t;o++){let t=l().dotTpl||"%d",r=n(e.localize(t,[["%d",o+1]]).replace(/\%i/g,o+""));r&&i.appendChild(r)}s(e.getPageIndex()),o.classList.add("has-dots")}}())}return{init:function(t){(e=t).on("refresh",d),e.on("change",a)},destroy:function(){r(),e?.off("refresh",d),e?.off("change",a),e=void 0}}}});