{if $availableLanguages|count > 1}
<script data-relocate="true">
- require(['Language', 'WoltLabSuite/Core/Language/Input'], function(Language, LanguageInput) {
+ require(['Language', 'WoltLabSuite/Core/Language/Input', 'WoltLabSuite/Core/Language/Text'], function(Language, LanguageInput, LanguageText) {
Language.addObject({
'wcf.global.button.disabledI18n': '{lang}wcf.global.button.disabledI18n{/lang}'
});
var availableLanguages = { {implode from=$availableLanguages key=languageID item=languageName}{@$languageID}: '{$languageName}'{/implode} };
var values = { {implode from=$i18nValues[$elementIdentifier] key=languageID item=value}'{@$languageID}': '{$value}'{/implode} };
- LanguageInput.init('{@$elementIdentifier}', values, availableLanguages, {if $forceSelection}true{else}false{/if});
+ var element = elById('{@$elementIdentifier}');
+ var type = LanguageInput;
+ if (element && element.nodeName === 'TEXTAREA' && element.classList.contains('wysiwygTextarea')) {
+ type = LanguageText;
+ }
+
+ type['init']('{@$elementIdentifier}', values, availableLanguages, {if $forceSelection}true{else}false{/if});
});
</script>
{/if}
{if $availableLanguages|count > 1}
<script data-relocate="true">
- require(['Language', 'WoltLabSuite/Core/Language/Input'], function(Language, LanguageInput) {
+ require(['Language', 'WoltLabSuite/Core/Language/Input', 'WoltLabSuite/Core/Language/Text'], function(Language, LanguageInput, LanguageText) {
Language.addObject({
'wcf.global.button.disabledI18n': '{lang}wcf.global.button.disabledI18n{/lang}'
});
var availableLanguages = { {implode from=$availableLanguages key=languageID item=languageName}{@$languageID}: '{$languageName}'{/implode} };
var values = { {implode from=$i18nValues[$elementIdentifier] key=languageID item=value}'{@$languageID}': '{$value}'{/implode} };
- LanguageInput.init('{@$elementIdentifier}', values, availableLanguages, {if $forceSelection}true{else}false{/if});
+ var element = elById('{@$elementIdentifier}');
+ var type = LanguageInput;
+ if (element && element.nodeName === 'TEXTAREA' && element.classList.contains('wysiwygTextarea')) {
+ type = LanguageText;
+ }
+
+ type['init']('{@$elementIdentifier}', values, availableLanguages, {if $forceSelection}true{else}false{/if});
});
</script>
{/if}
this._initElement(elementId, element, unescapedValues, availableLanguages, forceSelection);
},
+ /**
+ * Registers a callback for an element.
+ *
+ * @param {string} elementId
+ * @param {string} eventName
+ * @param {function} callback
+ */
+ registerCallback: function (elementId, eventName, callback) {
+ if (!_values.has(elementId)) {
+ throw new Error("Unknown element id '" + elementId + "'.");
+ }
+
+ _elements.get(elementId).callbacks.set(eventName, callback);
+ },
+
/**
* Caches common event listener callbacks.
*/
_elements.set(elementId, {
buttonLabel: button.children[0],
+ callbacks: new Dictionary(),
element: element,
languageId: 0,
isEnabled: true,
_select: function(elementId, languageId, isInit) {
var data = _elements.get(elementId);
- var dropdownMenu = UiSimpleDropdown.getDropdownMenu(data.element.parentNode.id);
+ var dropdownMenu = UiSimpleDropdown.getDropdownMenu(data.element.closest('.inputAddon').id);
var item, label = '';
for (var i = 0, length = dropdownMenu.childElementCount; i < length; i++) {
item = dropdownMenu.children[i];
data.element.blur();
data.element.focus();
}
+
+ if (data.callbacks.has('select')) {
+ data.callbacks.get('select')(data.element);
+ }
},
/**
if (data.isEnabled) {
values = _values.get(elementId);
+ if (data.callbacks.has('submit')) {
+ data.callbacks.get('submit')(data.element);
+ }
+
// update with current value
if (data.languageId) {
values.set(data.languageId, data.element.value);
--- /dev/null
+/**
+ * I18n interface for wysiwyg input fields.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2017 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');
+ }
+ }
+ }
+});
> textarea {
flex: 0 0 100%;
}
+
+ > .redactor-box {
+ flex: 0 0 100%;
+ margin-top: 0 !important;
+ }
}
.inputAddon input,