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
6 export function scrollToQueryString(editor) {
7 const queryParams = (new URL(window.location)).searchParams;
8 const scrollId = queryParams.get('content-id');
10 scrollToText(editor, scrollId);
15 * Override for touch events to allow scrolling on mobile devices.
16 * TODO - Check if still needed or if needs editing.
17 * @param {Editor} editor
19 export function fixScrollForMobile(editor) {
20 const container = editor.getContainer();
21 const toolbarButtons = container.querySelectorAll('.mce-btn');
22 for (let button of toolbarButtons) {
23 button.addEventListener('touchstart', event => {
24 event.stopPropagation();
30 * @param {Editor} editor
31 * @param {String} scrollId
33 function scrollToText(editor, scrollId) {
34 const element = editor.dom.get(encodeURIComponent(scrollId).replace(/!/g, '%21'));
39 // scroll the element into the view and put the cursor at the end.
40 element.scrollIntoView();
41 editor.selection.select(element, true);
42 editor.selection.collapse(false);