Simplify tofu detection cache

Change-Id: If68fce9c0bd281019de6e2992c856bdbe843aec8
This commit is contained in:
Amir E. Aharoni
2014-03-17 12:53:29 +02:00
committed by Santhosh Thottingal
parent b1e2812fd6
commit 0c8984e2f5

View File

@@ -142,7 +142,7 @@
* @param {array} classes * @param {array} classes
*/ */
fontSelector: function ( repository, language, classes ) { fontSelector: function ( repository, language, classes ) {
var font, tofu, autonym, defaultFont; var font, autonym, defaultFont;
if ( !language ) { if ( !language ) {
return null; return null;
@@ -164,19 +164,17 @@
// There is a default font for this language, // There is a default font for this language,
// but check whether the user sees tofu for it. // but check whether the user sees tofu for it.
tofu = tofuLanguages[language] || if ( tofuLanguages[language] === undefined ) {
detectTofu( $.uls.data.getAutonym( language ) ); tofuLanguages[language] = detectTofu( $.uls.data.getAutonym( language ) );
if ( tofu ) {
// Log the tofu detection only once per page per language // Log the tofu detection only once per page per language
if ( !tofuLanguages[language] ) { if ( tofuLanguages[language] ) {
mw.log( 'tofu detected for ' + language ); mw.log( 'tofu detected for ' + language );
mw.hook( 'mw.uls.webfonts.tofudetected' ).fire( language ); mw.hook( 'mw.uls.webfonts.tofudetected' ).fire( language );
// Cache the languages with tofu
tofuLanguages[language] = true;
} }
}
if ( tofuLanguages[language] ) {
font = autonym ? 'Autonym' : defaultFont; font = autonym ? 'Autonym' : defaultFont;
} else { } else {
// No tofu and no font preference. Use system font. // No tofu and no font preference. Use system font.