From 61fc2de43b1c261d1ea39c7e38a80bb0c82dd9a0 Mon Sep 17 00:00:00 2001 From: Aevann Date: Sun, 29 Oct 2023 17:06:50 +0300 Subject: [PATCH] dont focus if i dont pick anything (and trigger the mobile keyboard unnecessarily) --- files/assets/js/core.js | 6 ++++++ files/assets/js/emoji_modal/emoji_modal.js | 11 ++++++++--- files/assets/js/gif_modal.js | 14 ++++---------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/files/assets/js/core.js b/files/assets/js/core.js index 39f763a30e..fbbf44e471 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 cb965a23d3..d32f990144 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 47e487d03c..6475b48de3 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}); } }