]> BookStack Code Mirror - bookstack/commitdiff
Updated page navigation click to show content tab on mobile
authorDan Brown <redacted>
Sat, 25 May 2019 14:37:49 +0000 (15:37 +0100)
committerDan Brown <redacted>
Sat, 25 May 2019 14:37:49 +0000 (15:37 +0100)
Fixes #1454

resources/assets/js/components/page-display.js
resources/assets/js/components/tri-layout.js

index e87966d7dbbcfc7b83b8fc7b596f36e034bbafd2..513a07b8df924e8203099fa06792577ca48e3b10 100644 (file)
@@ -20,6 +20,7 @@ class PageDisplay {
 
         // Sidebar page nav click event
         $('.sidebar-page-nav').on('click', 'a', event => {
+            window.components['tri-layout'][0].showContent();
             this.goToText(event.target.getAttribute('href').substr(1));
         });
     }
index 0ae7df976b37e3ad97835a3da3f61e1a20659bd0..5cd49b74fa67ddcc3f0928919e88cc18f7599040 100644 (file)
@@ -66,28 +66,44 @@ class TriLayout {
      */
     mobileTabClick(event) {
         const tab = event.target.getAttribute('tri-layout-mobile-tab');
+        this.showTab(tab);
+    }
+
+    /**
+     * Show the content tab.
+     * Used by the page-display component.
+     */
+    showContent() {
+        this.showTab('content');
+    }
+
+    /**
+     * Show the given tab
+     * @param tabName
+     */
+    showTab(tabName) {
         this.scrollCache[this.lastTabShown] = document.documentElement.scrollTop;
 
         // Set tab status
-        const activeTabs = document.querySelectorAll('.tri-layout-mobile-tab.active');
-        for (let tab of activeTabs) {
-            tab.classList.remove('active');
+        const tabs = document.querySelectorAll('.tri-layout-mobile-tab');
+        for (let tab of tabs) {
+            const isActive = (tab.getAttribute('tri-layout-mobile-tab') === tabName);
+            tab.classList.toggle('active', isActive);
         }
-        event.target.classList.add('active');
 
         // Toggle section
-        const showInfo = (tab === 'info');
+        const showInfo = (tabName === 'info');
         this.elem.classList.toggle('show-info', showInfo);
 
         // Set the scroll position from cache
         const pageHeader = document.querySelector('header');
         const defaultScrollTop = pageHeader.getBoundingClientRect().bottom;
-        document.documentElement.scrollTop = this.scrollCache[tab] || defaultScrollTop;
+        document.documentElement.scrollTop = this.scrollCache[tabName] || defaultScrollTop;
         setTimeout(() => {
-            document.documentElement.scrollTop = this.scrollCache[tab] || defaultScrollTop;
+            document.documentElement.scrollTop = this.scrollCache[tabName] || defaultScrollTop;
         }, 50);
 
-        this.lastTabShown = tab;
+        this.lastTabShown = tabName;
     }
 
 }