2 * I18n interface for wysiwyg input fields.
4 * @author Alexander Ebert
5 * @copyright 2001-2018 WoltLab GmbH
6 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
7 * @module WoltLabSuite/Core/Language/Text
9 define(['Core', './Input'], function (Core
, LanguageInput
) {
13 * @exports WoltLabSuite/Core/Language/Text
17 * Initializes an WYSIWYG input field.
19 * @param {string} elementId input element id
20 * @param {Object} values preset values per language id
21 * @param {Object} availableLanguages language names per language id
22 * @param {boolean} forceSelection require i18n input
24 init: function(elementId
, values
, availableLanguages
, forceSelection
) {
25 var element
= elById(elementId
);
26 if (!element
|| element
.nodeName
!== 'TEXTAREA' || !element
.classList
.contains('wysiwygTextarea')) {
27 throw new Error("Expected <textarea class=\"wysiwygTextarea\" /> for id '" + elementId
+ "'.");
30 LanguageInput
.init(elementId
, values
, availableLanguages
, forceSelection
);
32 //noinspection JSUnresolvedFunction
33 LanguageInput
.registerCallback(elementId
, 'select', this._callbackSelect
.bind(this));
34 //noinspection JSUnresolvedFunction
35 LanguageInput
.registerCallback(elementId
, 'submit', this._callbackSubmit
.bind(this));
39 * Refreshes the editor content on language switch.
41 * @param {Element} element input element
44 _callbackSelect: function (element
) {
45 if (window
.jQuery
!== undefined) {
46 window
.jQuery(element
).redactor('code.set', element
.value
);
51 * Refreshes the input element value on submit.
53 * @param {Element} element input element
56 _callbackSubmit: function (element
) {
57 if (window
.jQuery
!== undefined) {
58 element
.value
= window
.jQuery(element
).redactor('code.get');