@fancyapps/ui
Version:
Robust JavaScript UI Component Library
1 lines • 2.99 kB
JavaScript
!/*! 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={autoStart:!0,pauseOnHover:!0,showProgressbar:!0,timeout:2e3};e.Autoplay=()=>{let e,o,i=!1,a=!1,s=!1,r=null;function l(o){let i=e?.getOptions().Autoplay,a=(t(i)?{...n,...i}:n)[o];return a&&"function"==typeof a&&e?a(e):a}function u(){for(let t of e?.getPage()?.slides||[])if(0===t.state)return!0;return!1}function f(){clearTimeout(o),o=void 0}function g(){!(o||s||u())&&e?.isSettled()&&(function(){if(!e||(p(),!l("showProgressbar")))return;let t=l("progressbarParentEl");if(!t&&e.getPlugins().Toolbar?.isEnabled()&&(t=e.getContainer()),!t&&e.getPlugins().Toolbar?.isEnabled()!==!0){let n=e.getPages()[0]?.slides||[],o=e.getPage()?.slides||[];1===n.length&&1===o.length&&(t=o[0].el)}if(t||(t=e.getViewport()),!t)return;(r=document.createElement("div")).classList.add("f-progressbar"),t.prepend(r);let n=l("timeout")||1e3;r.style.animationDuration=`${n}ms`}(),o=setTimeout(()=>{if(e&&i&&!a){if(!e.isInfinite()&&e.getPageIndex()===e.getPages().length-1)return void e.goTo(0);e.next()}},l("timeout")))}function c(){if(!e||e.getPages().length<2||!1===e.getOptions().Autoplay||i)return;i=!0,e.emit("autoplay:start",l("timeout")),e.getContainer()?.classList.add("has-autoplay"),e.getTween()?.on("start",P);let t=e?.getContainer();t&&l("pauseOnHover")&&matchMedia("(hover: hover)").matches&&(t.addEventListener("mouseenter",w,!1),t.addEventListener("mouseleave",x,!1)),e.on("change",v),e.on("settle",b),e.on("contentReady",y),e.on("panzoom:animationStart",d),e.isSettled()&&g()}function d(){if(f(),p(),i&&e){e.emit("autoplay:end"),e.getContainer()?.classList.remove("has-autoplay"),e.getTween()?.off("start",P);let t=e?.getContainer();t&&(t.removeEventListener("mouseenter",w,!1),t.removeEventListener("mouseleave",x,!1))}e&&(e.off("change",v),e.off("settle",b),e.off("contentReady",y),e.off("panzoom:animationStart",d)),i=!1,a=!1}function p(){r&&(r.remove(),r=null)}function m(){e&&e.getPages().length>1&&l("autoStart")&&c()}function y(t){e&&e.getPageIndex(t.index)===e.getPageIndex()&&(!i||s||u()||g())}function h(e,t){let n=t.target;n&&!t.defaultPrevented&&"toggle"===n.dataset.autoplayAction&&E.toggle()}function v(){e&&(e?.isInfinite()||e.getPageIndex()!==e.getPages().length-1)?(p(),f()):d()}function b(){!i||s||a||g()}function P(){f(),p()}function w(){s=!0,i&&(p(),f())}function x(){s=!1,i&&!a&&e?.isSettled()&&g()}let E={init:function(t){(e=t).on("ready",m),e.on("click",h)},destroy:function(){d(),e?.off("ready",m),e?.off("click",h),e=void 0},isEnabled:()=>i,pause:function(){a=!0,f()},resume:function(){a=!1,i&&!s&&g()},start(){c()},stop(){d()},toggle(){i?d():c()}};return E}});