Santhosh has uploaded a new change for review.

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


Change subject: Update jquery.webfonts from upstream
......................................................................

Update jquery.webfonts from upstream

Upstream: https://github.com/wikimedia/jquery.webfonts
Changes:
* Fixes Bug 53203
* More documentation and code cleanup

Bug: 53203
Change-Id: Ieb48ba532cc1d9880d2fde1b185af7cbed1a3eff
---
M lib/jquery.webfonts.js
1 file changed, 31 insertions(+), 23 deletions(-)


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

diff --git a/lib/jquery.webfonts.js b/lib/jquery.webfonts.js
index 36fa391..72b41b6 100644
--- a/lib/jquery.webfonts.js
+++ b/lib/jquery.webfonts.js
@@ -55,6 +55,11 @@
        WebFonts.prototype = {
                constructor: WebFonts,
 
+               /**
+                * Get the default font family for given language.
+                * @param {String} language Language code.
+                * @return {String} Font family name
+                */
                getFont: function( language ) {
                        if ( this.options.fontSelector ) {
                                return this.options.fontSelector( 
this.repository, language || this.language );
@@ -74,16 +79,19 @@
                        this.parse();
                },
 
+               /**
+                * TODO: document
+                */
                refresh: function() {
                        this.reset();
                        this.init();
                },
 
                /**
-                * Apply a font for the element.
+                * Apply a font for given elements.
                 *
-                * @param fontFamily String: font family name
-                * @param $element
+                * @param {String} fontFamily Font family name
+                * @param {jQuery} $element One or more jQuery elements
                 */
                apply: function( fontFamily, $element ) {
                        var fontStack = this.options.fontStack.slice( 0 );
@@ -142,6 +150,8 @@
                                }
                        }
 
+                       // In case the list contained only fonts that are 
already loaded
+                       // or non-existing fonts.
                        if ( fontFaceRule !== '' ) {
                                injectCSS( fontFaceRule );
                        }
@@ -177,8 +187,12 @@
                                var fontFamilyStyle, fontFamily,
                                        $element = $( element );
 
+                               // Note: it depends on the browser whether this 
returns font names
+                               // which don't exist. In Chrome it does, while 
in Opera it doesn't.
                                fontFamilyStyle = $element.css( 'fontFamily' );
 
+                               // Note: It is unclear whether this can ever be 
falsy. Maybe also
+                               // browser specific.
                                if ( fontFamilyStyle ) {
                                        fontFamily = fontFamilyStyle.split( ',' 
)[0];
 
@@ -186,10 +200,10 @@
                                        fontFamily = $.trim( 
fontFamily.replace( /["']/g, '' ) );
 
                                        append( fontQueue, fontFamily );
-                               // Load and apply fonts for other language 
tagged elements (batched)
                                }
 
-                               if ( element.lang && element.lang !== 
webfonts.$element.attr( 'lang' ) ) {
+                               // Load and apply fonts for other language 
tagged elements (batched)
+                               if ( element.lang && element.lang !== 
webfonts.language ) {
                                        fontFamily = webfonts.getFont( 
element.lang );
                                        // We do not have fonts for all 
languages
                                        if ( fontFamily !== null ) {
@@ -210,8 +224,8 @@
                /**
                 * List all fonts for the given language
                 *
-                * @param language mixed: [optional] language code. If 
undefined all fonts will be listed
-                * @return Array font names array
+                * @param {String} [language] Language code. If undefined all 
fonts will be listed.
+                * @return {Array} List of font family names.
                 */
                list: function( language ) {
                        var fontName,
@@ -233,7 +247,7 @@
                /**
                 * List all languages supported by the repository
                 *
-                * @return Array language codes
+                * @return {Array} List of language codes
                 */
                languages: function() {
                        var language,
@@ -272,11 +286,11 @@
                },
 
                /**
-                * Construct the CSS required for the font-family, inject it to 
the head
-                * of the body so that it gets loaded.
+                * Construct the CSS required for the font-family.
                 *
-                * @param fontFamily The font-family name
-                * @param variant The font variant, eg: bold, italic etc. 
Default is normal.
+                * @param {String} fontFamily The font-family name
+                * @param {String} [variant] The font variant, eg: bold, italic 
etc. Default is normal.
+                * @return {String} CSS
                 */
                getCSS: function( fontFamily, variant ) {
                        var webfonts, base, version, versionSuffix,
@@ -317,17 +331,17 @@
 
                        if ( fontconfig.woff ) {
                                fontFormats.push( '\t\turl(\'' + base + 
fontconfig.woff + versionSuffix
-                                               + '\') format(\'woff\')' );
+                                       + '\') format(\'woff\')' );
                        }
 
                        if ( fontconfig.svg ) {
                                fontFormats.push( '\t\turl(\'' + base + 
fontconfig.svg + versionSuffix + '#'
-                                               + fontFamily + '\') 
format(\'svg\')' );
+                                       + fontFamily + '\') format(\'svg\')' );
                        }
 
                        if ( fontconfig.ttf ) {
                                fontFormats.push( '\t\turl(\'' + base + 
fontconfig.ttf + versionSuffix
-                                               + '\') format(\'truetype\')' );
+                                       + '\') format(\'truetype\')' );
                        }
 
                        fontFaceRule += fontFormats.join() + ';\n';
@@ -348,7 +362,7 @@
                                fontFaceRule += '\tfont-style: normal;';
                        }
 
-                       fontFaceRule += '}';
+                       fontFaceRule += '}\n';
 
                        webfonts = this;
                        if ( fontconfig.variants !== undefined ) {
@@ -390,14 +404,10 @@
        /**
         * Create a new style tag and add it to the DOM.
         *
-        * @param css String: CSS text
-        * @return HTMLStyleElement
+        * @param {String} css
         */
        function injectCSS( css ) {
                var s = document.createElement( 'style' );
-
-               s.type = 'text/css';
-               s.rel = 'stylesheet';
 
                // Insert into document before setting cssText
                document.getElementsByTagName( 'head' )[0].appendChild( s );
@@ -409,7 +419,5 @@
                        // Safari sometimes borks on null
                        s.appendChild( document.createTextNode( String( css ) ) 
);
                }
-
-               return s;
        }
 } )( jQuery, window, document );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ieb48ba532cc1d9880d2fde1b185af7cbed1a3eff
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UniversalLanguageSelector
Gerrit-Branch: master
Gerrit-Owner: Santhosh <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to