Simplify the cancel logic for input and display settings

Change-Id: I2afe78edad31b00a35d0589384e4091b61091275
This commit is contained in:
Nikerabbit
2013-08-29 10:35:02 +00:00
committed by Niklas Laxström
parent f14161a0cd
commit ef826e0e75
3 changed files with 14 additions and 45 deletions

View File

@@ -113,9 +113,11 @@
this.$parent.$settingsPanel.empty();
this.$webfonts = $( 'body' ).data( 'webfonts' );
this.$parent.$settingsPanel.append( this.$template );
this.disableApplyButton();
this.prepareLanguages();
this.prepareUIFonts();
this.prepareContentFonts();
$.i18n().locale = this.uiLanguage;
this.i18n();
this.$webfonts.refresh();
this.listen();
@@ -620,48 +622,20 @@
* Cancel the changes done by user for display settings
*/
cancel: function () {
var displaySettings = this,
origUILanguage = this.getUILanguage();
if ( !displaySettings.dirty ) {
// Nothing changed
if ( !this.dirty ) {
return;
}
// Reload preferences
mw.webfonts.preferences = $.extend( true, {}, displaySettings.savedRegistry );
if ( displaySettings.$webfonts ) {
displaySettings.$webfonts.refresh();
}
mw.webfonts.preferences = $.extend( true, {}, this.savedRegistry );
if ( $.i18n().locale !== origUILanguage ) {
// restore UI localization for display settings panel
$.i18n().locale = origUILanguage;
this.i18n();
// Restore fonts
if ( this.$webfonts ) {
this.$webfonts.refresh();
}
// Clear the dirty bit
displaySettings.dirty = false;
displaySettings.disableApplyButton();
// Restore content and UI language
displaySettings.uiLanguage = displaySettings.getUILanguage();
displaySettings.contentLanguage = displaySettings.getContentLanguage();
// Restore the font dropdowns
displaySettings.prepareUIFonts();
displaySettings.prepareContentFonts();
// Restore the visual state of selected language button
displaySettings.$template.find( 'div.uls-ui-languages button.button' ).each( function () {
var $button = $( this );
if ( $button.attr( 'lang' ) === displaySettings.uiLanguage ) {
$button.addClass( 'down' );
} else {
$button.removeClass( 'down' );
}
} );
this.uiLanguage = this.getUILanguage();
this.contentLanguage = this.getContentLanguage();
}
};