]> BookStack Code Mirror - bookstack/blobdiff - resources/js/components/editor-toolbox.js
Comments: Split tests, added extra archive/reference tests
[bookstack] / resources / js / components / editor-toolbox.js
index a581ae7b4609727200ad3251b6f0e5e59dd1213e..95339328542a6a9946ee226ad49c42f608811c92 100644 (file)
@@ -1,4 +1,4 @@
-import {Component} from "./component";
+import {Component} from './component';
 
 export class EditorToolbox extends Component {
 
@@ -8,6 +8,11 @@ export class EditorToolbox extends Component {
         this.buttons = this.$manyRefs.tabButton;
         this.contentElements = this.$manyRefs.tabContent;
         this.toggleButton = this.$refs.toggle;
+        this.editorWrapEl = this.container.closest('.page-editor');
+
+        // State
+        this.open = false;
+        this.tab = '';
 
         this.setupListeners();
 
@@ -30,16 +35,18 @@ export class EditorToolbox extends Component {
 
     toggle() {
         this.container.classList.toggle('open');
-        const expanded = this.container.classList.contains('open') ? 'true' : 'false';
-        this.toggleButton.setAttribute('aria-expanded', expanded);
+        const isOpen = this.container.classList.contains('open');
+        this.toggleButton.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
+        this.editorWrapEl.classList.toggle('toolbox-open', isOpen);
+        this.open = isOpen;
+        this.emitState();
     }
 
     setActiveTab(tabName, openToolbox = false) {
-
         // Set button visibility
         for (const button of this.buttons) {
             button.classList.remove('active');
-            const bName =  button.dataset.tab;
+            const bName = button.dataset.tab;
             if (bName === tabName) button.classList.add('active');
         }
 
@@ -53,6 +60,13 @@ export class EditorToolbox extends Component {
         if (openToolbox && !this.container.classList.contains('open')) {
             this.toggle();
         }
+
+        this.tab = tabName;
+        this.emitState();
+    }
+
+    emitState() {
+        this.$emit('change', {tab: this.tab, open: this.open});
     }
 
-}
\ No newline at end of file
+}