* I18n interface for wysiwyg input fields.
*
* @author Alexander Ebert
- * @copyright 2001-2019 WoltLab GmbH
+ * @copyright 2001-2019 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @module WoltLabSuite/Core/Language/Text
*/
-define(['Core', './Input'], function (Core, LanguageInput) {
+define(["require", "exports", "tslib", "./Input"], function (require, exports, tslib_1, LanguageInput) {
"use strict";
+ Object.defineProperty(exports, "__esModule", { value: true });
+ exports.init = void 0;
+ LanguageInput = tslib_1.__importStar(LanguageInput);
/**
- * @exports WoltLabSuite/Core/Language/Text
+ * Refreshes the editor content on language switch.
*/
- return {
- /**
- * Initializes an WYSIWYG input field.
- *
- * @param {string} elementId input element id
- * @param {Object} values preset values per language id
- * @param {Object} availableLanguages language names per language id
- * @param {boolean} forceSelection require i18n input
- */
- init: function (elementId, values, availableLanguages, forceSelection) {
- var element = elById(elementId);
- if (!element || element.nodeName !== 'TEXTAREA' || !element.classList.contains('wysiwygTextarea')) {
- throw new Error("Expected <textarea class=\"wysiwygTextarea\" /> for id '" + elementId + "'.");
- }
- LanguageInput.init(elementId, values, availableLanguages, forceSelection);
- //noinspection JSUnresolvedFunction
- LanguageInput.registerCallback(elementId, 'select', this._callbackSelect.bind(this));
- //noinspection JSUnresolvedFunction
- LanguageInput.registerCallback(elementId, 'submit', this._callbackSubmit.bind(this));
- },
- /**
- * Refreshes the editor content on language switch.
- *
- * @param {Element} element input element
- * @protected
- */
- _callbackSelect: function (element) {
- if (window.jQuery !== undefined) {
- window.jQuery(element).redactor('code.set', element.value);
- }
- },
- /**
- * Refreshes the input element value on submit.
- *
- * @param {Element} element input element
- * @protected
- */
- _callbackSubmit: function (element) {
- if (window.jQuery !== undefined) {
- element.value = window.jQuery(element).redactor('code.get');
- }
+ function callbackSelect(element) {
+ if (window.jQuery !== undefined) {
+ window.jQuery(element).redactor("code.set", element.value);
}
- };
+ }
+ /**
+ * Refreshes the input element value on submit.
+ */
+ function callbackSubmit(element) {
+ if (window.jQuery !== undefined) {
+ element.value = window.jQuery(element).redactor("code.get");
+ }
+ }
+ /**
+ * Initializes an WYSIWYG input field.
+ */
+ function init(elementId, values, availableLanguages, forceSelection) {
+ const element = document.getElementById(elementId);
+ if (!element || element.nodeName !== "TEXTAREA" || !element.classList.contains("wysiwygTextarea")) {
+ throw new Error(`Expected <textarea class="wysiwygTextarea" /> for id '${elementId}'.`);
+ }
+ LanguageInput.init(elementId, values, availableLanguages, forceSelection);
+ LanguageInput.registerCallback(elementId, "select", callbackSelect);
+ LanguageInput.registerCallback(elementId, "submit", callbackSubmit);
+ }
+ exports.init = init;
});
type LanguageId = number;
-interface I18nValues {
+export interface I18nValues {
// languageID => value
[key: string]: string;
}
-interface Languages {
+export interface Languages {
// languageID => languageName
[key: string]: string;
}
type Values = Map<LanguageId, string>;
-type InputOrTextarea = HTMLInputElement | HTMLTextAreaElement;
+export type InputOrTextarea = HTMLInputElement | HTMLTextAreaElement;
type CallbackEvent = "select" | "submit";
type Callback = (element: InputOrTextarea) => void;
+++ /dev/null
-/**
- * I18n interface for wysiwyg input fields.
- *
- * @author Alexander Ebert
- * @copyright 2001-2019 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @module WoltLabSuite/Core/Language/Text
- */
-define(['Core', './Input'], function (Core, LanguageInput) {
- "use strict";
-
- /**
- * @exports WoltLabSuite/Core/Language/Text
- */
- return {
- /**
- * Initializes an WYSIWYG input field.
- *
- * @param {string} elementId input element id
- * @param {Object} values preset values per language id
- * @param {Object} availableLanguages language names per language id
- * @param {boolean} forceSelection require i18n input
- */
- init: function(elementId, values, availableLanguages, forceSelection) {
- var element = elById(elementId);
- if (!element || element.nodeName !== 'TEXTAREA' || !element.classList.contains('wysiwygTextarea')) {
- throw new Error("Expected <textarea class=\"wysiwygTextarea\" /> for id '" + elementId + "'.");
- }
-
- LanguageInput.init(elementId, values, availableLanguages, forceSelection);
-
- //noinspection JSUnresolvedFunction
- LanguageInput.registerCallback(elementId, 'select', this._callbackSelect.bind(this));
- //noinspection JSUnresolvedFunction
- LanguageInput.registerCallback(elementId, 'submit', this._callbackSubmit.bind(this));
- },
-
- /**
- * Refreshes the editor content on language switch.
- *
- * @param {Element} element input element
- * @protected
- */
- _callbackSelect: function (element) {
- if (window.jQuery !== undefined) {
- window.jQuery(element).redactor('code.set', element.value);
- }
- },
-
- /**
- * Refreshes the input element value on submit.
- *
- * @param {Element} element input element
- * @protected
- */
- _callbackSubmit: function (element) {
- if (window.jQuery !== undefined) {
- element.value = window.jQuery(element).redactor('code.get');
- }
- }
- }
-});
--- /dev/null
+/**
+ * I18n interface for wysiwyg input fields.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2019 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module WoltLabSuite/Core/Language/Text
+ */
+
+import { I18nValues, InputOrTextarea, Languages } from "./Input";
+import * as LanguageInput from "./Input";
+
+/**
+ * Refreshes the editor content on language switch.
+ */
+function callbackSelect(element: InputOrTextarea): void {
+ if (window.jQuery !== undefined) {
+ window.jQuery(element).redactor("code.set", element.value);
+ }
+}
+
+/**
+ * Refreshes the input element value on submit.
+ */
+function callbackSubmit(element: InputOrTextarea): void {
+ if (window.jQuery !== undefined) {
+ element.value = window.jQuery(element).redactor("code.get") as string;
+ }
+}
+
+/**
+ * Initializes an WYSIWYG input field.
+ */
+export function init(
+ elementId: string,
+ values: I18nValues,
+ availableLanguages: Languages,
+ forceSelection: boolean,
+): void {
+ const element = document.getElementById(elementId);
+ if (!element || element.nodeName !== "TEXTAREA" || !element.classList.contains("wysiwygTextarea")) {
+ throw new Error(`Expected <textarea class="wysiwygTextarea" /> for id '${elementId}'.`);
+ }
+
+ LanguageInput.init(elementId, values, availableLanguages, forceSelection);
+
+ LanguageInput.registerCallback(elementId, "select", callbackSelect);
+ LanguageInput.registerCallback(elementId, "submit", callbackSubmit);
+}