UNPKG

@fancyapps/ui

Version:

Robust JavaScript UI Component Library

3 lines (2 loc) • 1.36 kB
/*! License details at fancyapps.com/license */ import{isPlainObject as t}from"../utils/isPlainObject.js";const n={btnTpl:'<button data-expand-action="toggle" class="f-button" title="{{TOGGLE_EXPAND}}"><svg><g><path d="M14.5 9.5 21 3m0 0h-6m6 0v6M3 21l6.5-6.5M3 21v-6m0 6h6"/></g><g><path d="m14 10 7-7m-7 7h6m-6 0V4M3 21l7-7m0 0v6m0-6H4"/></g></svg></button>'},e="in-expanded-mode",o="with-expanded-carousel",i=()=>{let i;function s(e){const o=i?.getOptions().Expand;let s=(t(o)?{...n,...o}:n)[e];return s&&"function"==typeof s&&i?s(i):s}function c(){i?.getPlugins().Toolbar?.add("expand",{tpl:s("btnTpl")})}function d(t,n){const e=n.target;e&&!n.defaultPrevented&&"toggle"===e.dataset.expandAction&&a()}function l(t){if("Escape"===t.key&&!t.defaultPrevented){const t=s("el")||i?.getContainer();t?.classList.contains(e)&&a()}}function a(){const t=s("el")||i?.getContainer();t&&(t.classList.toggle(e),t.classList.contains(e)?(document.documentElement.classList.add(o),document.addEventListener("keydown",l,!0)):(document.documentElement.classList.remove(o),document.removeEventListener("keydown",l,!0)))}return{init:function(t){i=t,i.on("initPlugins",c),i.on("click",d)},destroy:function(){i?.off("initPlugins",c),i?.off("click",d),i=void 0,document.documentElement.classList.remove(o),document.removeEventListener("keydown",l,!0)},toggle:a}};export{i as Expand};