Nevermind we don't need the button as a source of the events anyway

Closes #134
This commit is contained in:
Eragon 2024-03-09 13:52:24 +01:00
parent 5283d45c36
commit 1fa5dd8085
Signed by: Eragon
GPG Key ID: 087126EBFC725006
1 changed files with 12 additions and 20 deletions

View File

@ -2,33 +2,25 @@
/* Locate the editor associated to an edition event.
event: Global event emitted by one of the editor buttons
Returns [the div.editor, the button, the textarea] */
Returns [the div.editor, the textarea] */
function editor_event_source(event)
{
let button = undefined;
let editor = undefined;
/* Grab the button and the parent editor block. The onclick event itself
/* Grab the the parent editor block. The onclick event itself
usually reports the SVG in the button as the source */
let node = event.currentTarget || event.srcElement;
let node = event.current || event.srcElement;
while (node != document.body) {
if (node.tagName == "BUTTON" && !button) {
button = node;
}
if (node.classList.contains("editor") && !editor) {
editor = node;
// Hack to use keybinds
if (!button) {
button = node.firstElementChild.firstElementChild
}
break;
}
node = node.parentNode;
}
if (!button || !editor) return;
if (!editor) return;
const ta = editor.querySelector(".editor textarea");
return [editor, button, ta];
return [editor, ta];
}
/* Replace the range [start:end) with the new contents, and returns the new
@ -46,7 +38,7 @@ function editor_replace_range(textarea, start, end, contents)
after token is the same as before if not specified */
function editor_insert_around(event, before="", after=null)
{
const [editor, button, ta] = editor_event_source(event);
const [editor, ta] = editor_event_source(event);
ta.focus();
let indexStart = ta.selectionStart;
let indexEnd = ta.selectionEnd;
@ -74,7 +66,7 @@ function editor_insert_around(event, before="", after=null)
generic function. */
function editor_act_on_lines(event, fn)
{
const [editor, button, ta] = editor_event_source(event);
const [editor, ta] = editor_event_source(event);
ta.focus();
let indexStart = ta.selectionStart;
let indexEnd = ta.selectionEnd;
@ -109,7 +101,7 @@ function editor_clear_modals(event, close = true)
{
// Stop the propagation of the event
event.stopPropagation()
const [editor, button, ta] = editor_event_source(event);
const [editor, ta] = editor_event_source(event);
// Reset all modal inputs
editor.getElementsByClassName('media-alt-input')[0].value = '';
@ -144,13 +136,13 @@ function editor_inline(event, type, enable_preview = true)
}
if (enable_preview) {
const [editor, button, ta] = editor_event_source(event);
const [editor, ta] = editor_event_source(event);
preview(editor);
}
}
function editor_display_link_modal(event) {
const [editor, button, ta] = editor_event_source(event);
const [editor, ta] = editor_event_source(event);
let indexStart = ta.selectionStart;
let indexEnd = ta.selectionEnd;
let selection = ta.value.substring(indexStart, indexEnd);
@ -169,7 +161,7 @@ function editor_display_link_modal(event) {
function editor_insert_link(event, link_id, text_id, media = false)
{
const [editor, button, ta] = editor_event_source(event);
const [editor, ta] = editor_event_source(event);
ta.focus();
let indexStart = ta.selectionStart;
let indexEnd = ta.selectionEnd;
@ -295,7 +287,7 @@ const DISABLE_PREVIEW_ICON = '<svg xmlns="http://www.w3.org/2000/svg" width="16"
const ENABLE_PREVIEW_ICON = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-eye" viewBox="0 0 16 16"><path d="M16 8s-3-5.5-8-5.5S0 8 0 8s3 5.5 8 5.5S16 8 16 8zM1.173 8a13.133 13.133 0 0 1 1.66-2.043C4.12 4.668 5.88 3.5 8 3.5c2.12 0 3.879 1.168 5.168 2.457A13.133 13.133 0 0 1 14.828 8c-.058.087-.122.183-.195.288-.335.48-.83 1.12-1.465 1.755C11.879 11.332 10.119 12.5 8 12.5c-2.12 0-3.879-1.168-5.168-2.457A13.134 13.134 0 0 1 1.172 8z"/><path d="M8 5.5a2.5 2.5 0 1 0 0 5 2.5 2.5 0 0 0 0-5zM4.5 8a3.5 3.5 0 1 1 7 0 3.5 3.5 0 0 1-7 0z"/></svg>';
function toggle_auto_preview() {
const [editor, button, ta] = editor_event_source(event);
const [editor, ta] = editor_event_source(event);
let auto_preview;
if (document.cookie.split(";").some((item) => item.trim().startsWith("auto-preview="))) {