/* * This file is part of the TYPO3 CMS project. * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 * of the License, or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. * * The TYPO3 project - inspiring people to share! */ import c from"@typo3/backend/info-window.js";import p from"@typo3/core/event/regular-event.js";import o from"@typo3/backend/window-manager.js";import d from"@typo3/backend/module-menu.js";import u from"@typo3/core/document-service.js";import l from"@typo3/backend/utility.js";class i{constructor(){this.delegates={},this.createDelegates(),u.ready().then(()=>this.registerEvents())}static resolveArguments(e){if(e.dataset.dispatchArgs){const t=e.dataset.dispatchArgs.replace(/"/g,'"'),a=JSON.parse(t);return a instanceof Array?l.trimItems(a):null}else if(e.dataset.dispatchArgsList){const t=e.dataset.dispatchArgsList.split(",");return l.trimItems(t)}return null}createDelegates(){this.delegates={"TYPO3.InfoWindow.showItem":c.showItem.bind(null),"TYPO3.WindowManager.localOpen":o.localOpen.bind(o),"TYPO3.ModuleMenu.showModule":d.App.showModule.bind(d.App)}}registerEvents(){new p("click",this.handleClickEvent.bind(this)).delegateTo(document,"[data-dispatch-action]")}handleClickEvent(e,t){e.preventDefault(),this.delegateTo(e,t)}delegateTo(e,t){if(t.hasAttribute("data-dispatch-disabled"))return;const r=t.dataset.dispatchAction;let s=i.resolveArguments(t);s instanceof Array&&(s=s.map(n=>{switch(n){case"{$target}":return t;case"{$event}":return e;default:return n}})),this.delegates[r]&&this.delegates[r].apply(null,s||[])}}var h=new i;export{h as default};