diff --git a/files/assets/js/core.js b/files/assets/js/core.js index 39f763a30..fbbf44e47 100644 --- a/files/assets/js/core.js +++ b/files/assets/js/core.js @@ -469,6 +469,12 @@ function insertText(input, text) { input.selectionStart = newPos; handle_disabled(input) + + if (typeof checkForRequired === "function") checkForRequired(); + + setTimeout(() => { + input.focus(); + }, 50); } diff --git a/files/assets/js/emoji_modal/emoji_modal.js b/files/assets/js/emoji_modal/emoji_modal.js index cb965a23d..d32f99014 100644 --- a/files/assets/js/emoji_modal/emoji_modal.js +++ b/files/assets/js/emoji_modal/emoji_modal.js @@ -217,6 +217,7 @@ function emojiAddToInput(event) strToInsert = ":" + strToInsert + ":" insertText(emojiInputTargetDOM, strToInsert) + insertedAnEmoji = true // kick-start the preview emojiInputTargetDOM.dispatchEvent(new Event('input')); @@ -230,17 +231,21 @@ function emojiAddToInput(event) } const emojiModal = document.getElementById('emojiModal') +let insertedAnEmoji function openEmojiModal(t, inputTargetIDName) { selecting = false; + insertedAnEmoji = false; if (inputTargetIDName) { emojiInputTargetDOM = document.getElementById(inputTargetIDName); emojiModal.addEventListener('hide.bs.modal', () => { - setTimeout(() => { - emojiInputTargetDOM.focus(); - }, 200); + if (insertedAnEmoji) { + setTimeout(() => { + emojiInputTargetDOM.focus(); + }, 50); + } }, {once : true}); } diff --git a/files/assets/js/gif_modal.js b/files/assets/js/gif_modal.js index 47e487d03..6475b48de 100644 --- a/files/assets/js/gif_modal.js +++ b/files/assets/js/gif_modal.js @@ -7,12 +7,12 @@ let commentFormID; function insertGIF(url) { const commentBox = document.getElementById(commentFormID); const old = commentBox.value; + let text - if (old) commentBox.value = `${old}\n${url}`; - else commentBox.value = url + if (old) text = `${old}\n${url}`; + else text = url - handle_disabled(commentBox) - if (typeof checkForRequired === "function") checkForRequired(); + insertText(commentBox, text) } const gifModal = document.getElementById('gifModal') @@ -118,12 +118,6 @@ async function show_gif_categories(t, form) { bootstrap.Modal.getOrCreateInstance(document.getElementById(t.dataset.previousModal)).show() }, {once : true}); } - - gifModal.addEventListener('hide.bs.modal', () => { - setTimeout(() => { - document.getElementById(commentFormID).focus(); - }, 200); - }, {once : true}); } }