Use new jquery.uls and preferences system
Change-Id: I0e626320f494597e9125d394fb9bbbceccfff34c
This commit is contained in:
@@ -59,7 +59,7 @@
|
|||||||
this.contentLanguage = this.getContentLanguage();
|
this.contentLanguage = this.getContentLanguage();
|
||||||
this.$webfonts = null;
|
this.$webfonts = null;
|
||||||
this.$parent = $parent;
|
this.$parent = $parent;
|
||||||
this.webfontPreferences = new $.fn.uls.preferences( 'webfonts' );
|
this.webfontPreferences = mw.uls.preferences( 'webfonts' );
|
||||||
};
|
};
|
||||||
|
|
||||||
DisplaySettings.prototype = {
|
DisplaySettings.prototype = {
|
||||||
@@ -283,10 +283,12 @@
|
|||||||
|
|
||||||
this.$template.find( '#webfonts-enable-checkbox' ).on( 'click', function () {
|
this.$template.find( '#webfonts-enable-checkbox' ).on( 'click', function () {
|
||||||
if ( this.checked ) {
|
if ( this.checked ) {
|
||||||
|
that.webfontPreferences.set( 'webfonts-enabled', true );
|
||||||
$contentFontSelector.prop( "disabled", false );
|
$contentFontSelector.prop( "disabled", false );
|
||||||
$uiFontSelector.prop( "disabled", false );
|
$uiFontSelector.prop( "disabled", false );
|
||||||
that.$webfonts.apply( $uiFontSelector.find( 'option:selected' ) );
|
that.$webfonts.apply( $uiFontSelector.find( 'option:selected' ) );
|
||||||
} else {
|
} else {
|
||||||
|
that.webfontPreferences.set( 'webfonts-enabled', false );
|
||||||
$contentFontSelector.prop( "disabled", true );
|
$contentFontSelector.prop( "disabled", true );
|
||||||
$uiFontSelector.prop( "disabled", true );
|
$uiFontSelector.prop( "disabled", true );
|
||||||
that.$webfonts.reset();
|
that.$webfonts.reset();
|
||||||
@@ -295,22 +297,14 @@
|
|||||||
|
|
||||||
$uiFontSelector.on( "change", function () {
|
$uiFontSelector.on( "change", function () {
|
||||||
var font = $( this ).find( 'option:selected' ).val();
|
var font = $( this ).find( 'option:selected' ).val();
|
||||||
|
that.webfontPreferences.set( that.uiLanguage, font );
|
||||||
if ( that.uiLanguage === that.getUILanguage() ) {
|
that.$webfonts.refresh();
|
||||||
if ( font === 'system' ) {
|
|
||||||
that.$webfonts.reset();
|
|
||||||
} else {
|
|
||||||
that.$webfonts.apply( font );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
$contentFontSelector.on( "change", function () {
|
$contentFontSelector.on( "change", function () {
|
||||||
var font = $( this ).find( 'option:selected' ).val();
|
var font = $( this ).find( 'option:selected' ).val();
|
||||||
if ( font === 'system' ) {
|
that.webfontPreferences.set( that.contentLanguage, font );
|
||||||
that.$webfonts.reset();
|
that.$webfonts.refresh();
|
||||||
} else {
|
|
||||||
that.$webfonts.apply( font );
|
|
||||||
}
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
},
|
},
|
||||||
@@ -332,6 +326,8 @@
|
|||||||
*/
|
*/
|
||||||
onSave: function ( success ) {
|
onSave: function ( success ) {
|
||||||
if ( success ) {
|
if ( success ) {
|
||||||
|
// Live font update
|
||||||
|
this.$webfonts.refresh();
|
||||||
this.$parent.hide();
|
this.$parent.hide();
|
||||||
// we delay change UI language to here, because it causes a page refresh
|
// we delay change UI language to here, because it causes a page refresh
|
||||||
if ( this.uiLanguage !== this.getUILanguage() ) {
|
if ( this.uiLanguage !== this.getUILanguage() ) {
|
||||||
@@ -347,26 +343,8 @@
|
|||||||
*/
|
*/
|
||||||
apply: function () {
|
apply: function () {
|
||||||
var that = this;
|
var that = this;
|
||||||
var uiFont = this.$template.find( "select#ui-font-selector" )
|
|
||||||
.find( 'option:selected' ).val();
|
|
||||||
var contentFont = this.$template.find( "select#content-font-selector" )
|
|
||||||
.find( 'option:selected' ).val();
|
|
||||||
var webfontEnabled = this.$template.find( '#webfonts-enable-checkbox' )
|
|
||||||
.prop( 'checked' ) ? true : false;
|
|
||||||
|
|
||||||
// Live font update if current UI language match with language selection
|
|
||||||
if ( ( this.uiLanguage === this.getUILanguage() ) && webfontEnabled ) {
|
|
||||||
if ( uiFont === 'system' ) {
|
|
||||||
this.$webfonts.reset();
|
|
||||||
} else {
|
|
||||||
this.$webfonts.apply( uiFont );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save the preferences
|
// Save the preferences
|
||||||
this.webfontPreferences.set( this.uiLanguage, uiFont );
|
|
||||||
this.webfontPreferences.set( this.contentLanguage, contentFont );
|
|
||||||
this.webfontPreferences.set( 'webfonts-enabled', webfontEnabled );
|
|
||||||
this.webfontPreferences.save( function ( result ) {
|
this.webfontPreferences.save( function ( result ) {
|
||||||
// closure for not losing the scope
|
// closure for not losing the scope
|
||||||
that.onSave( result );
|
that.onSave( result );
|
||||||
|
|||||||
@@ -21,23 +21,22 @@
|
|||||||
|
|
||||||
$( document ).ready( function() {
|
$( document ).ready( function() {
|
||||||
var mediawikiFontRepository = $.webfonts.repository;
|
var mediawikiFontRepository = $.webfonts.repository;
|
||||||
|
var webfontsPreferences = mw.uls.preferences( 'webfonts' );
|
||||||
mediawikiFontRepository.base = mw.config.get( 'wgExtensionAssetsPath' )
|
mediawikiFontRepository.base = mw.config.get( 'wgExtensionAssetsPath' )
|
||||||
+ '/UniversalLanguageSelector/data/fontrepo/fonts/';
|
+ '/UniversalLanguageSelector/data/fontrepo/fonts/';
|
||||||
|
// Initialize webfonts
|
||||||
$( 'body' ).webfonts( {
|
$( 'body' ).webfonts( {
|
||||||
repository: mediawikiFontRepository
|
repository: mediawikiFontRepository,
|
||||||
|
fontSelector: function ( repository, language ) {
|
||||||
|
var font = webfontsPreferences.get( language );
|
||||||
|
if ( !font ) {
|
||||||
|
font = repository.defaultFont(language);
|
||||||
|
}
|
||||||
|
if ( font === 'system' ) {
|
||||||
|
font = null;
|
||||||
|
}
|
||||||
|
return font;
|
||||||
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
var $webfonts = $( 'body' ).data( 'webfonts' );
|
|
||||||
var webfontPreferences = new $.fn.uls.preferences( 'webfonts' );
|
|
||||||
var rememberedFont = webfontPreferences.get( mw.config.get( 'wgUserLanguage' ) );
|
|
||||||
|
|
||||||
if ( rememberedFont === 'system' ) {
|
|
||||||
$webfonts.reset();
|
|
||||||
} else {
|
|
||||||
// FIXME: jquery.webfonts should have an option to specify default font to use.
|
|
||||||
$webfonts.apply( rememberedFont );
|
|
||||||
}
|
|
||||||
} );
|
} );
|
||||||
} )( jQuery, mediaWiki );
|
} )( jQuery, mediaWiki );
|
||||||
|
|||||||
Reference in New Issue
Block a user