@fancyapps/ui
Version:
Robust JavaScript UI Component Library
1 lines • 2 kB
JavaScript
!/*! License details at fancyapps.com/license */function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).window=t.window||{})}(this,function(t){"use strict";let e=function(t){var e=new DOMParser().parseFromString(t,"text/html").body;if(e.childElementCount>1){for(var n=document.createElement("div");e.firstChild;)n.appendChild(e.firstChild);return n}let i=e.firstChild;if(i&&!(i instanceof HTMLElement)){var n=document.createElement("div");return n.appendChild(i),n}return i},n='<svg width="24" height="24" viewBox="0 0 24 24" tabindex="-1">',i="</svg>",o={prevTpl:n+'<path d="M15 3l-9 9 9 9"></path>'+i,nextTpl:n+'<path d="M9 3l9 9-9 9"></path>'+i};t.Arrows=()=>{let t,n,i;function r(){let e=t?.getOptions().Arrows;return"object"==typeof e&&null!==e&&e.constructor===Object&&"[object Object]"===Object.prototype.toString.call(e)?{...o,...e}:o}function s(n){if(!t)return;let i=`<button data-carousel-go-${n} tabindex="0" class="f-button is-arrow is-${n}" title="{{${n.toUpperCase()}}}">`+r()[`${n}Tpl`]+"</button",o=e(t.localize(i))||void 0;return o&&((t,e="")=>{t&&t.classList&&e.split(" ").forEach(e=>{e&&t.classList.add(e)})})(o,r()[`${n}Class`]),o}function a(){n?.remove(),n=void 0,i?.remove(),i=void 0,t?.getContainer()?.classList.remove("has-arrows")}function l(){t&&!1!==t.getOptions().Arrows&&t.getPages().length>1?(!function(){if(!t)return;let e=t.getViewport();e&&(!n&&(n=s("prev"))&&e.insertAdjacentElement("beforebegin",n),!i&&(i=s("next"))&&e.insertAdjacentElement("afterend",i),((t,e="",n)=>{t&&t.classList&&e.split(" ").forEach(e=>{e&&t.classList.toggle(e,n||!1)})})(t.getContainer(),"has-arrows",!!(n||i)))}(),t&&(n?.toggleAttribute("aria-disabled",!t.canGoPrev()),i?.toggleAttribute("aria-disabled",!t.canGoNext()))):a()}return{init:function(e){t=e.on(["change","refresh"],l)},destroy:function(){a(),t?.off(["change","refresh"],l),t=void 0}}}});