@fancyapps/ui
Version:
Robust JavaScript UI Component Library
3 lines (2 loc) • 1.61 kB
JavaScript
/*! License details at fancyapps.com/license */
import{isPlainObject as t}from"../utils/isPlainObject.js";import{stringToHtml as e}from"../utils/strToHtml.js";const n={dotTpl:'<button class="f-carousel__dot" data-carousel-go-to="%i" aria-label="{{GOTO}}"></button>',maxCount:1/0,minCount:2},o=()=>{let o,l=null;function s(){const e=null==o?void 0:o.getOptions().Dots;return t(e)?Object.assign(Object.assign({},n),e):n}function i(){var t,e;null===(t=null==l?void 0:l.parentElement)||void 0===t||t.removeChild(l),l=null,null===(e=null==o?void 0:o.getContainer())||void 0===e||e.classList.remove("has-dots")}function a(t=-1){null==l||l.querySelectorAll("[data-carousel-go-to]").forEach((e=>{var n;parseInt((null===(n=e.dataset)||void 0===n?void 0:n.carouselGoTo)||"-1",10)===t?e.classList.add("is-selected"):e.classList.remove("is-selected")}))}function r(){a(null==o?void 0:o.getPageIndex())}function u(){o&&o.getPages().length!==(l?l.childElementCount:-1)&&(i(),function(){var t;if(!o)return;if(!1===o.getOptions().Dots)return;const n=o.getPages().length,i=o.getContainer();if(!(n<s().minCount||n>s().maxCount)&&i){l||(l=document.createElement("div"),l.classList.add("f-carousel__dots"),null===(t=o.getViewport())||void 0===t||t.insertAdjacentElement("afterend",l));for(let t=0;t<n;t++){const n=s().dotTpl||"%d",i=e(o.localize(n,[["%d",t+1]]).replace(/\%i/g,t+""));i&&l.appendChild(i)}a(o.getPageIndex()),i.classList.add("has-dots")}}())}return{init:function(t){o=t,o.on("refresh",u),o.on("change",r)},destroy:function(){i(),null==o||o.off("refresh",u),null==o||o.off("change",r),o=void 0}}};export{o as Dots};