Santhosh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/288920

Change subject: Stop tofu detection and usage of autonym font
......................................................................

Stop tofu detection and usage of autonym font

Change-Id: I2fe200fb6598d744472206b6a89f02cb3d37b394
TODO: To be tested well.
---
M extension.json
M resources/js/ext.uls.webfonts.js
2 files changed, 3 insertions(+), 104 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UniversalLanguageSelector 
refs/changes/20/288920/1

diff --git a/extension.json b/extension.json
index 1939628..2171e5e 100644
--- a/extension.json
+++ b/extension.json
@@ -259,7 +259,6 @@
                "ext.uls.webfonts.fonts": {
                        "dependencies": [
                                "jquery.webfonts",
-                               "jquery.uls.data",
                                "ext.uls.webfonts.repository"
                        ],
                        "localBasePath": "resources",
diff --git a/resources/js/ext.uls.webfonts.js b/resources/js/ext.uls.webfonts.js
index 3ecfeb3..d72ade3 100644
--- a/resources/js/ext.uls.webfonts.js
+++ b/resources/js/ext.uls.webfonts.js
@@ -20,11 +20,7 @@
 ( function ( $, mw ) {
        'use strict';
 
-       var ulsPreferences,
-               // Text to prepend the sample text. 0D00 is an unassigned 
unicode point.
-               tofuSalt = '\u0D00',
-               // cache languages with tofu.
-               tofuLanguages = {};
+       var ulsPreferences;
 
        mw.webfonts = mw.webfonts || {};
        ulsPreferences = mw.uls.preferences();
@@ -67,62 +63,6 @@
                }
        };
 
-       /**
-        * Detect tofu
-        *
-        * Create a temporary span in the page with fontsize 72px and 
font-family
-        * sans-serif for each letter of the text.
-        * For each of these spans, calculate the width and height. If they are 
same
-        * for all spans, we can understand that each of the letter is rendered 
using
-        * same glyph - it must be a tofu.
-        *
-        * @param {string} text
-        * @return {boolean}
-        */
-       function detectTofu( text ) {
-               var index,
-                       $fixture,
-                       width = {},
-                       height = {},
-                       length = Math.min( 4, text.length ),
-                       detected = false;
-
-               if ( $.client.test( {
-                               msie: false
-                       } ) ) {
-                       // IE shows a different tofu for unassigned code points!
-                       text = tofuSalt + text;
-               }
-               $fixture = $( '<span>' )
-                       .css( {
-                               fontSize: '72px',
-                               fontFamily: 'sans-serif'
-                       } )
-                       .appendTo( 'body' );
-
-               for ( index = 0; index < length; index++ ) {
-                       $fixture.text( text[ index ] );
-                       width[ index ] = $fixture.width() || width[ index - 1 ];
-                       height[ index ] = $fixture.height();
-
-                       if ( index > 0 &&
-                               ( width[ index ] !== width[ index - 1 ] ||
-                                       height[ index ] !== height[ index - 1 ] 
)
-                       ) {
-                               detected = false;
-                               break;
-                       }
-               }
-
-               $fixture.remove();
-
-               if ( index === length ) {
-                       detected = true;
-               }
-
-               return detected;
-       }
-
        mw.webfonts.setup = function () {
                // Initialize webfonts
                var mediawikiFontRepository = $.webfonts.repository;
@@ -139,48 +79,16 @@
                         *
                         * @param {Object} repository
                         * @param {string} language
-                        * @param {Array} classes
                         */
-                       fontSelector: function ( repository, language, classes 
) {
-                               var font, autonym, defaultFont;
+                       fontSelector: function ( repository, language ) {
+                               var font;
 
                                if ( !language ) {
                                        return null;
                                }
 
-                               defaultFont = repository.defaultFont( language 
);
-
-                               if ( classes && $.inArray( 'autonym', classes ) 
>= 0 ) {
-                                       autonym = true;
-                               }
-
                                // If the user has a font preference, apply it 
always.
                                font = mw.webfonts.preferences.getFont( 
language );
-                               if ( !font || autonym ) {
-                                       // Is there any default font for this 
language?
-                                       if ( ( !defaultFont || defaultFont === 
'system' ) && !autonym ) {
-                                               return font;
-                                       }
-
-                                       // There is a default font for this 
language,
-                                       // but check whether the user sees tofu 
for it.
-                                       if ( tofuLanguages[ language ] === 
undefined ) {
-                                               tofuLanguages[ language ] = 
detectTofu( $.uls.data.getAutonym( language ) );
-
-                                               // Log the tofu detection only 
once per page per language
-                                               if ( tofuLanguages[ language ] 
) {
-                                                       mw.log( 'tofu detected 
for ' + language );
-                                                       mw.hook( 
'mw.uls.webfonts.tofudetected' ).fire( language );
-                                               }
-                                       }
-
-                                       if ( tofuLanguages[ language ] ) {
-                                               font = autonym ? 'Autonym' : 
defaultFont;
-                                       } else {
-                                               // No tofu and no font 
preference. Use system font.
-                                               font = 'system';
-                                       }
-                               }
 
                                if ( font === 'system' ) {
                                        // Avoid setting 'system' as a font in 
css
@@ -212,14 +120,6 @@
                // property values set by stylesheets.
                setTimeout( function () {
                        $( 'body' ).webfonts();
-
-                       // Load the CSS required for the Autonym font. Note 
that this won't download the font.
-                       // Browsers are smart enough to delay it till some 
element with this font-family
-                       // becomes visible. For example: If there is a popup 
div with an element with class
-                       // 'autonym', without explicitly calling .webfonts() on 
it, Autonym font will not
-                       // be applied in general. But we ensure that the CSS is 
ready so that the font
-                       // will be applied automatically to such future 
elements.
-                       $( 'body' ).data( 'webfonts' ).load( 'Autonym' );
                }, 0 );
        };
 

-- 
To view, visit https://gerrit.wikimedia.org/r/288920
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2fe200fb6598d744472206b6a89f02cb3d37b394
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UniversalLanguageSelector
Gerrit-Branch: master
Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to