UNPKG

@fancyapps/ui

Version:

Robust JavaScript UI Component Library

2 lines 2.1 kB
/*! License details at fancyapps.com/license */ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.window=e.window||{}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let t=(e,t=``)=>{e&&e.classList&&t.split(` `).forEach(t=>{t&&e.classList.add(t)})},n=e=>typeof e==`object`&&!!e&&e.constructor===Object&&Object.prototype.toString.call(e)===`[object Object]`,r=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 r=t.firstChild;if(r&&!(r instanceof HTMLElement)){var n=document.createElement(`div`);return n.appendChild(r),n}return r},i=(e,t=``,n)=>{e&&e.classList&&t.split(` `).forEach(t=>{t&&e.classList.toggle(t,n||!1)})},a={prevTpl:`<svg width="24" height="24" viewBox="0 0 24 24" tabindex="-1"><path d="M15 3l-9 9 9 9"></path></svg>`,nextTpl:`<svg width="24" height="24" viewBox="0 0 24 24" tabindex="-1"><path d="M9 3l9 9-9 9"></path></svg>`};e.Arrows=()=>{let e;function o(){let t=e?.getOptions().Arrows;return n(t)?{...a,...t}:a}let s,c;function l(){if(!e)return;let t=e.getViewport();t&&(s||(s=u(`prev`),s&&t.insertAdjacentElement(`beforebegin`,s)),c||(c=u(`next`),c&&t.insertAdjacentElement(`afterend`,c)),i(e.getContainer(),`has-arrows`,!0))}function u(n){let i=o(),a=`<button data-carousel-go-${n} tabindex="0" class="f-button is-arrow is-${n}" title="{{${n.toUpperCase()}}}">`+i[`${n}Tpl`]+`</button>`,s=r(e.localize(a))||void 0;return s&&t(s,i[`${n}Class`]),s}function d(){s?.remove(),s=void 0,c?.remove(),c=void 0,e?.getContainer()?.classList.remove(`has-arrows`)}function f(){e&&(s?.toggleAttribute(`aria-disabled`,!e.canGoPrev()),c?.toggleAttribute(`aria-disabled`,!e.canGoNext()))}function p(){e&&e.getOptions().Arrows!==!1&&e.getPages().length>1?(l(),f()):d()}return{init:function(t){e=t.on([`change`,`refresh`],p)},destroy:function(){d(),e?.off([`change`,`refresh`],p),e=void 0}}}});