]> BookStack Code Mirror - bookstack/blobdiff - resources/assets/js/components/page-display.js
Typo fix
[bookstack] / resources / assets / js / components / page-display.js
index a3879d0061533f0cb31ed2a8cc9e459222942d16..2be1c1c48b8cc93f5ac147b64023cf910eabc3fa 100644 (file)
@@ -1,6 +1,7 @@
 import Clipboard from "clipboard/dist/clipboard.min";
 import Code from "../services/code";
 import * as DOM from "../services/dom";
+import {scrollAndHighlightElement} from "../services/util";
 
 class PageDisplay {
 
@@ -20,10 +21,15 @@ class PageDisplay {
 
         // Sidebar page nav click event
         const sidebarPageNav = document.querySelector('.sidebar-page-nav');
-        DOM.onChildEvent(sidebarPageNav, 'a', 'click', (event, child) => {
-            window.components['tri-layout'][0].showContent();
-            this.goToText(child.getAttribute('href').substr(1));
-        });
+        if (sidebarPageNav) {
+            DOM.onChildEvent(sidebarPageNav, 'a', 'click', (event, child) => {
+                event.preventDefault();
+                window.components['tri-layout'][0].showContent();
+                const contentId = child.getAttribute('href').substr(1);
+                this.goToText(contentId);
+                window.history.pushState(null, null, '#' + contentId);
+            });
+        }
     }
 
     goToText(text) {
@@ -35,11 +41,11 @@ class PageDisplay {
         });
 
         if (idElem !== null) {
-            window.scrollAndHighlight(idElem);
+            scrollAndHighlightElement(idElem);
         } else {
             const textElem = DOM.findText('.page-content > div > *', text);
             if (textElem) {
-                window.scrollAndHighlight(textElem);
+                scrollAndHighlightElement(textElem);
             }
         }
     }