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