mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-28 17:02:04 +03:00
Modularised our tinymce config and plugins
- Split everything into specific plugin/concern files to make things more managable. Means original component file is now simple and much of the core config is focused in one place.
This commit is contained in:
44
resources/js/wysiwyg/scrolling.js
Normal file
44
resources/js/wysiwyg/scrolling.js
Normal file
@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Scroll to a section dictated by the current URL query string, if present.
|
||||
* Used when directly editing a specific section of the page.
|
||||
* @param {Editor} editor
|
||||
*/
|
||||
export function scrollToQueryString(editor) {
|
||||
const queryParams = (new URL(window.location)).searchParams;
|
||||
const scrollId = queryParams.get('content-id');
|
||||
if (scrollId) {
|
||||
scrollToText(editor, scrollId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Override for touch events to allow scrolling on mobile devices.
|
||||
* TODO - Check if still needed or if needs editing.
|
||||
* @param {Editor} editor
|
||||
*/
|
||||
export function fixScrollForMobile(editor) {
|
||||
const container = editor.getContainer();
|
||||
const toolbarButtons = container.querySelectorAll('.mce-btn');
|
||||
for (let button of toolbarButtons) {
|
||||
button.addEventListener('touchstart', event => {
|
||||
event.stopPropagation();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Editor} editor
|
||||
* @param {String} scrollId
|
||||
*/
|
||||
function scrollToText(editor, scrollId) {
|
||||
const element = editor.dom.get(encodeURIComponent(scrollId).replace(/!/g, '%21'));
|
||||
if (!element) {
|
||||
return;
|
||||
}
|
||||
|
||||
// scroll the element into the view and put the cursor at the end.
|
||||
element.scrollIntoView();
|
||||
editor.selection.select(element, true);
|
||||
editor.selection.collapse(false);
|
||||
editor.focus();
|
||||
}
|
Reference in New Issue
Block a user