@fancyapps/ui
Version:
Robust JavaScript UI Component Library
1 lines • 2.45 kB
JavaScript
!/*! License details at fancyapps.com/license */function(e,t){"object"==typeof exports&&"u">typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="u">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=(e,t="")=>{e&&e.classList&&t.split(" ").forEach(t=>{t&&e.classList.add(t)})},o=(e,t="")=>{e&&e.classList&&t.split(" ").forEach(t=>{t&&e.classList.remove(t)})},i={dotTpl:'<button class="f-carousel__dot" data-carousel-go-to="%i" aria-label="{{GOTO}}"></button>',dynamicFrom:11,dynamicPadd:4,maxCount:1/0,minCount:2},l="f-carousel__dots",r="has-dots";e.Dots=()=>{let e,a,s=!1,d=4,c=0,f=4;function u(t){let n=e?.getOptions().Dots;return("object"==typeof n&&null!==n&&n.constructor===Object&&"[object Object]"===Object.prototype.toString.call(n)?{...i,...n}:i)[t]}function p(){if(!e)return;d=u("dynamicPadd"),c=0,f=d;let o=e.getContainer(),i=e.getPages().length;if(!1===e.getOptions().Dots||!o||i<u("minCount")||i>u("maxCount"))return void h();a||(a=e.getContainer()?.querySelector("."+l)||void 0),a||(n(a=document.createElement("div"),l),e.getViewport()?.insertAdjacentElement("afterend",a));let p=s,m=u("dynamicFrom");p!==(s=!!m&&!!(i>=m)&&!!(i>=d+4))&&h(),function(){if(!e||!a)return;let n=e.getPages().length;if(n!==a.childElementCount){let o=[];for(let i=0;i<n;i++){let n=u("dotTpl")||"%d",l=t(e.localize(n,[["%d",i+1]]).replace(/\%i/g,i+""));l&&o.push(l)}a.replaceChildren(...o)}}(),g(),a.classList.toggle("is-dynamic",s),a.style.display="",n(o,r)}function m(){g()}function g(){if(!e||!a||!s)return;let t=e.getPageIndex(),i=e.getPages().length;t<c&&(f=(c=t)+d)>i&&(f=i),t>f&&(c=(f=t)-d)<0&&(c=0);let l=e=>e===t?"active":e>=c&&e<=f?"padd":e===c-1||e===f+1?"small":e===c-2||e===f+2?"micro":"hidden";for(let e of[...a.childNodes]){let t=parseInt(e.dataset.carouselGoTo||"0",10);o(e,"active padd small micro hidden"),n(e,l(t))}}function h(){a&&(a.replaceChildren(),a.style.display="none"),o(e?.getContainer(),r)}return{init:function(t){(e=t).on("refresh",p),e.on("change",m)},destroy:function(){h(),e?.off("refresh",p),e?.off("change",m),e=void 0}}}});