]> BookStack Code Mirror - hacks/commitdiff
refactor(mermaid-viewer): Use bind to pass direction to handleZoomClick
authorAlexander Wilms <redacted>
Thu, 26 Jun 2025 22:18:15 +0000 (00:18 +0200)
committerAlexander Wilms <redacted>
Thu, 26 Jun 2025 22:18:15 +0000 (00:18 +0200)
content/mermaid-viewer/head.html

index 26bee0bdb4945aa5e14b7bc74fc121c88c4d6da3..fe9d0cd897b682f594840b15d9dc08f765132fc0 100644 (file)
             this.boundMouseUpHandler = this.handleMouseUp.bind(this);
             this.boundToggleInteraction = this.toggleInteraction.bind(this);
             this.boundCopyCode = this.copyCode.bind(this);
-            this.boundZoomIn = () => {
-                const { clientX, clientY } = this._getViewportCenterClientCoords();
-                this.zoom(1, clientX, clientY);
-            };
-            this.boundZoomOut = () => {
-                const { clientX, clientY } = this._getViewportCenterClientCoords();
-                this.zoom(-1, clientX, clientY);
-            };
+            this.boundZoomIn = this.handleZoomClick.bind(this, 1);
+            this.boundZoomOut = this.handleZoomClick.bind(this, -1);
             this.boundResetZoom = this.resetZoom.bind(this);
             this.boundHandleWheel = this.handleWheel.bind(this);
             this.boundHandleMouseDown = this.handleMouseDown.bind(this);
             this.content.style.transform = `translate(${this.translateX}px, ${this.translateY}px) scale(${this.scale})`;
         }
 
+        handleZoomClick(direction) {
+            const { clientX, clientY } = this._getViewportCenterClientCoords();
+            this.zoom(direction, clientX, clientY);
+        }
+
         handleWheel(e) {
             if (!this.interactionEnabled) return;
             // Prevent default browser scroll/zoom behavior when wheeling over the diagram