]> BookStack Code Mirror - bookstack/blob - resources/js/wysiwyg/scrolling.js
Covered app icon setting with testing
[bookstack] / resources / js / wysiwyg / scrolling.js
1 /**
2  * Scroll to a section dictated by the current URL query string, if present.
3  * Used when directly editing a specific section of the page.
4  * @param {Editor} editor
5  */
6 export function scrollToQueryString(editor) {
7     const queryParams = (new URL(window.location)).searchParams;
8     const scrollId = queryParams.get('content-id');
9     if (scrollId) {
10         scrollToText(editor, scrollId);
11     }
12 }
13
14 /**
15  * @param {Editor} editor
16  * @param {String} scrollId
17  */
18 function scrollToText(editor, scrollId) {
19     const element = editor.dom.get(encodeURIComponent(scrollId).replace(/!/g, '%21'));
20     if (!element) {
21         return;
22     }
23
24     // scroll the element into the view and put the cursor at the end.
25     element.scrollIntoView();
26     editor.selection.select(element, true);
27     editor.selection.collapse(false);
28     editor.focus();
29 }