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