[ticket/13713] Move function to get textarea element to core.js

PHPBB3-13713
This commit is contained in:
Marc Alexander 2021-05-20 20:38:13 +02:00
parent 1b5c521d8f
commit a0d9c7fe85
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
3 changed files with 29 additions and 25 deletions

View file

@ -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,

View file

@ -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;

View file

@ -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;