diff --git a/Resources/Public/JavaScript/toolbar/opendocs-menu.js b/Resources/Public/JavaScript/toolbar/opendocs-menu.js index 7b99b1d..06d112c 100644 --- a/Resources/Public/JavaScript/toolbar/opendocs-menu.js +++ b/Resources/Public/JavaScript/toolbar/opendocs-menu.js @@ -10,4 +10,4 @@ * * The TYPO3 project - inspiring people to share! */ -import $ from"jquery";import AjaxRequest from"@typo3/core/ajax/ajax-request.js";import Icons from"@typo3/backend/icons.js";import Viewport from"@typo3/backend/viewport.js";import{ModuleStateStorage}from"@typo3/backend/storage/module-state-storage.js";var Selectors;!function(e){e.containerSelector="#typo3-cms-opendocs-backend-toolbaritems-opendocstoolbaritem",e.closeSelector=".t3js-topbar-opendocs-close",e.menuContainerSelector=".dropdown-menu",e.toolbarIconSelector=".toolbar-item-icon .t3js-icon",e.openDocumentsItemsSelector=".t3js-topbar-opendocs-item",e.counterSelector="#tx-opendocs-counter",e.entrySelector=".t3js-open-doc"}(Selectors||(Selectors={}));class OpendocsMenu{constructor(){this.hashDataAttributeName="opendocsidentifier",this.toggleMenu=()=>{$(".scaffold").removeClass("scaffold-toolbar-expanded"),$(Selectors.containerSelector).toggleClass("open")},document.addEventListener("typo3:opendocs:updateRequested",e=>this.updateMenu()),Viewport.Topbar.Toolbar.registerEvent(()=>{this.initializeEvents(),this.updateMenu()})}static updateNumberOfDocs(){const e=$(Selectors.containerSelector).find(Selectors.openDocumentsItemsSelector).length;$(Selectors.counterSelector).text(e).toggle(e>0)}updateMenu(){let e=$(Selectors.toolbarIconSelector,Selectors.containerSelector),t=e.clone();Icons.getIcon("spinner-circle-light",Icons.sizes.small).then(t=>{e.replaceWith(t)}),new AjaxRequest(TYPO3.settings.ajaxUrls.opendocs_menu).get().then(async e=>{$(Selectors.containerSelector).find(Selectors.menuContainerSelector).html(await e.resolve()),OpendocsMenu.updateNumberOfDocs()}).finally(()=>{$(Selectors.toolbarIconSelector,Selectors.containerSelector).replaceWith(t)})}initializeEvents(){$(Selectors.containerSelector).on("click",Selectors.closeSelector,e=>{e.preventDefault();const t=$(e.currentTarget).data(this.hashDataAttributeName);this.closeDocument(t)}).on("click",Selectors.entrySelector,e=>{e.preventDefault();const t=$(e.currentTarget);this.toggleMenu(),ModuleStateStorage.updateWithCurrentMount("web",t.data("pid"),!0);document.querySelector("typo3-backend-module-router").setAttribute("endpoint",t.attr("href"))})}closeDocument(e){const t={};e&&(t.md5sum=e),new AjaxRequest(TYPO3.settings.ajaxUrls.opendocs_closedoc).post(t).then(async e=>{$(Selectors.menuContainerSelector,Selectors.containerSelector).html(await e.resolve()),OpendocsMenu.updateNumberOfDocs(),$(Selectors.containerSelector).toggleClass("open")})}}let opendocsMenuObject;opendocsMenuObject=new OpendocsMenu,"undefined"!=typeof TYPO3&&(TYPO3.OpendocsMenu=opendocsMenuObject);export default opendocsMenuObject; \ No newline at end of file +import $ from"jquery";import AjaxRequest from"@typo3/core/ajax/ajax-request.js";import Icons from"@typo3/backend/icons.js";import Viewport from"@typo3/backend/viewport.js";import{ModuleStateStorage}from"@typo3/backend/storage/module-state-storage.js";var Selectors;!function(e){e.containerSelector="#typo3-cms-opendocs-backend-toolbaritems-opendocstoolbaritem",e.closeSelector=".t3js-topbar-opendocs-close",e.menuContainerSelector=".dropdown-menu",e.toolbarIconSelector=".toolbar-item-icon .t3js-icon",e.openDocumentsItemsSelector=".t3js-topbar-opendocs-item",e.counterSelector="#tx-opendocs-counter",e.entrySelector=".t3js-open-doc"}(Selectors||(Selectors={}));class OpendocsMenu{constructor(){this.hashDataAttributeName="opendocsidentifier",this.toggleMenu=()=>{$(".scaffold").removeClass("scaffold-toolbar-expanded"),$(Selectors.containerSelector).toggleClass("open")},document.addEventListener("typo3:opendocs:updateRequested",(e=>this.updateMenu())),Viewport.Topbar.Toolbar.registerEvent((()=>{this.initializeEvents(),this.updateMenu()}))}static updateNumberOfDocs(){const e=$(Selectors.containerSelector).find(Selectors.openDocumentsItemsSelector).length;$(Selectors.counterSelector).text(e).toggle(e>0)}updateMenu(){let e=$(Selectors.toolbarIconSelector,Selectors.containerSelector),t=e.clone();Icons.getIcon("spinner-circle-light",Icons.sizes.small).then((t=>{e.replaceWith(t)})),new AjaxRequest(TYPO3.settings.ajaxUrls.opendocs_menu).get().then((async e=>{$(Selectors.containerSelector).find(Selectors.menuContainerSelector).html(await e.resolve()),OpendocsMenu.updateNumberOfDocs()})).finally((()=>{$(Selectors.toolbarIconSelector,Selectors.containerSelector).replaceWith(t)}))}initializeEvents(){$(Selectors.containerSelector).on("click",Selectors.closeSelector,(e=>{e.preventDefault();const t=$(e.currentTarget).data(this.hashDataAttributeName);this.closeDocument(t)})).on("click",Selectors.entrySelector,(e=>{e.preventDefault();const t=$(e.currentTarget);this.toggleMenu(),ModuleStateStorage.updateWithCurrentMount("web",t.data("pid"),!0);document.querySelector("typo3-backend-module-router").setAttribute("endpoint",t.attr("href"))}))}closeDocument(e){const t={};e&&(t.md5sum=e),new AjaxRequest(TYPO3.settings.ajaxUrls.opendocs_closedoc).post(t).then((async e=>{$(Selectors.menuContainerSelector,Selectors.containerSelector).html(await e.resolve()),OpendocsMenu.updateNumberOfDocs(),$(Selectors.containerSelector).toggleClass("open")}))}}let opendocsMenuObject;opendocsMenuObject=new OpendocsMenu,"undefined"!=typeof TYPO3&&(TYPO3.OpendocsMenu=opendocsMenuObject);export default opendocsMenuObject; \ No newline at end of file