From a0d9c7fe85ae30d26323babae270b38b0af68631 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 20 May 2021 20:38:13 +0200 Subject: [PATCH] [ticket/13713] Move function to get textarea element to core.js PHPBB3-13713 --- phpBB/assets/javascript/core.js | 25 +++++++++++++++++++++++++ phpBB/assets/javascript/editor.js | 26 ++------------------------ phpBB/assets/javascript/mentions.js | 3 ++- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index 3c0bcf2243..d301cc8da8 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -1745,6 +1745,31 @@ phpbb.lazyLoadAvatars = function loadAvatars() { }); }; +/** + * Get editor text area element + * + * @param {string} formName Name of form + * @param {string} textareaName Textarea name + * + * @return {HTMLElement|null} Text area element or null if textarea couldn't be found + */ +phpbb.getEditorTextArea = function(formName, textareaName) { + let doc; + + // find textarea, make sure browser supports necessary functions + if (document.forms[formName]) { + doc = document; + } else { + doc = opener.document; + } + + if (!doc.forms[formName]) { + return; + } + + return doc.forms[formName].elements[textareaName]; +} + phpbb.recaptcha = { button: null, ready: false, diff --git a/phpBB/assets/javascript/editor.js b/phpBB/assets/javascript/editor.js index d1734564b5..3b86ca380d 100644 --- a/phpBB/assets/javascript/editor.js +++ b/phpBB/assets/javascript/editor.js @@ -384,33 +384,11 @@ function getCaretPosition(txtarea) { return caretPos; } -/** - * Get editor text area element - * - * @return {HTMLElement|null} Text area element or null if textarea couldn't be found - */ -function getEditorTextArea() { - let doc; - - // find textarea, make sure browser supports necessary functions - if (document.forms[form_name]) { - doc = document; - } else { - doc = opener.document; - } - - if (!doc.forms[form_name]) { - return; - } - - return doc.forms[form_name].elements[text_name]; -} - (function($) { 'use strict'; - $(document).ready(function() { - const textarea = getEditorTextArea(); + $(document).ready(() => { + const textarea = phpbb.getEditorTextArea(form_name, text_name); if (typeof textarea === 'undefined') { return; diff --git a/phpBB/assets/javascript/mentions.js b/phpBB/assets/javascript/mentions.js index 578c9795d3..0288ffd3d1 100644 --- a/phpBB/assets/javascript/mentions.js +++ b/phpBB/assets/javascript/mentions.js @@ -311,7 +311,8 @@ phpbb.mentions = new Mentions(); $(document).ready(() => { - const textarea = getEditorTextArea(); + /* global form_name, text_name */ + const textarea = phpbb.getEditorTextArea(form_name, text_name); if (typeof textarea === 'undefined') { return;