' ).text(
$.i18n( 'ext-uls-webfonts-select-for', $.uls.data.getAutonym( language ) ) ) );
// Possible messages:
// ext-uls-webfonts-select-for-ui-info
// ext-uls-webfonts-select-for-content-info
$fontLabel.append( $( '' ).text(
$.i18n( 'ext-uls-webfonts-select-for-' + target + '-info' ) ) );
},
/**
* Prepare the font selector for UI language.
*/
prepareUIFonts: function () {
if ( this.uiLanguage === this.contentLanguage ) {
this.$template.find( 'div.uls-ui-fonts' ).hide();
return;
}
this.prepareFontSelector( 'ui' );
},
/**
* Prepare the font selector for UI language.
*/
prepareContentFonts: function () {
this.prepareFontSelector( 'content' );
},
/**
* Enable the apply button.
* Useful in many places when something changes.
*/
enableApplyButton: function () {
this.$template.find( '#uls-displaysettings-apply' ).removeAttr( 'disabled' );
},
/**
* Register general event listeners
*/
listen: function () {
var that = this,
$contentFontSelector, $uiFontSelector,
oldFont;
$contentFontSelector = this.$template
.find( '#content-font-selector' );
$uiFontSelector = this.$template
.find( '#ui-font-selector' );
oldFont = $uiFontSelector.find( 'option:selected' ).val();
// TODO all these repeated selectors can be placed in object constructor.
this.$template.find( '#uls-displaysettings-apply' ).on( 'click', function () {
that.apply();
} );
this.$template.find( 'button.uls-settings-close' ).on( 'click', function () {
mw.webfonts.preferences.setFont( that.contentLanguage, oldFont );
that.$webfonts.refresh();
that.close();
} );
this.$template.find( '#webfonts-enable-checkbox' ).on( 'click', function () {
that.enableApplyButton();
if ( this.checked ) {
mw.webfonts.preferences.enable();
$contentFontSelector.prop( 'disabled', false );
$uiFontSelector.prop( 'disabled', false );
that.$webfonts.apply( $uiFontSelector.find( 'option:selected' ) );
} else {
mw.webfonts.preferences.disable();
$contentFontSelector.prop( 'disabled', true );
$uiFontSelector.prop( 'disabled', true );
that.$webfonts.reset();
}
} );
$uiFontSelector.on( 'change', function () {
that.enableApplyButton();
var font = $( this ).find( 'option:selected' ).val();
mw.webfonts.preferences.setFont( that.uiLanguage, font );
that.$webfonts.refresh();
} );
$contentFontSelector.on( 'change', function () {
that.enableApplyButton();
var font = $( this ).find( 'option:selected' ).val();
mw.webfonts.preferences.setFont( that.contentLanguage, font );
that.$webfonts.refresh();
} );
},
/**
* Hide this window.
* Used while navigating to language selector and need coming back
*/
hide: function () {
this.$parent.hide();
},
/**
* Close the language settings window.
* Depending on the context, actions vary.
*/
close: function () {
this.$parent.close();
},
/**
* Callback for save preferences
*/
onSave: function ( success ) {
if ( success ) {
// Live font update
this.$webfonts.refresh();
this.$parent.hide();
// we delay change UI language to here, because it causes a page refresh
if ( this.uiLanguage !== this.getUILanguage() ) {
mw.uls.changeLanguage( this.uiLanguage );
}
} else {
// FIXME failure. what to do?!
}
},
/**
* Handle the apply button press
*/
apply: function () {
var that = this;
// Save the preferences
mw.webfonts.preferences.save( function ( result ) {
// closure for not losing the scope
that.onSave( result );
} );
}
};
// Register this module to language settings modules
$.fn.languagesettings.modules = $.extend( $.fn.languagesettings.modules, {
display: DisplaySettings
} );
})( jQuery, mediaWiki );