From: Alexander Ebert Date: Tue, 13 Mar 2012 19:55:40 +0000 (+0100) Subject: i18n input properly detects if i18n is used or not X-Git-Tag: 2.0.0_Beta_1~1236 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=3804718124aecad33d94b81a6345502dcd122fa8;p=GitHub%2FWoltLab%2FWCF.git i18n input properly detects if i18n is used or not Fixes #516 --- diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 23c2a09773..924205e7b2 100644 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -1737,6 +1737,12 @@ WCF.MultipleLanguageInput.prototype = { * @var jQuery */ _element: null, + + /** + * true, if data was entered after initialization + * @var boolean + */ + _insertedDataAfterInit: false, /** * enables multiple language ability @@ -1792,6 +1798,7 @@ WCF.MultipleLanguageInput.prototype = { // build selection handler var $enableOnInit = ($.getLength(this._values) > 0) ? true : false; + this._insertedDataAfterInit = $enableOnInit; this._prepareElement($enableOnInit); // listen for submit event @@ -1860,6 +1867,7 @@ WCF.MultipleLanguageInput.prototype = { } this._isEnabled = true; + this._insertedDataAfterInit = false; } // toggle list @@ -1903,6 +1911,13 @@ WCF.MultipleLanguageInput.prototype = { * Closes the language selection. */ _closeSelection: function() { + if (!this._insertedDataAfterInit) { + // prevent loop of death + this._insertedDataAfterInit = true; + + this._disable(); + } + if (this._list !== null) { this._list.removeClass('open'); } @@ -1915,12 +1930,13 @@ WCF.MultipleLanguageInput.prototype = { */ _changeLanguage: function(event) { var $button = $(event.target); - + this._insertedDataAfterInit = true; + // save current value if (this._didInit) { this._values[this._languageID] = this._element.val(); } - + // set new language this._languageID = $button.data('languageID'); if (this._values[this._languageID]) { @@ -1929,14 +1945,14 @@ WCF.MultipleLanguageInput.prototype = { else { this._element.val(''); } - + // update marking this._list.children('li').removeClass('active'); $button.addClass('active'); - + // update label this._list.prev('.wcf-dropdownCaption').children('span').text(this._availableLanguages[this._languageID]); - + // close selection and set focus on input element this._closeSelection(); this._element.focus();