From 61e1f95a4c08e2e936ff4f5d90aa0c203648370d Mon Sep 17 00:00:00 2001 From: Santhosh Thottingal Date: Sun, 12 Jan 2014 18:31:02 +0530 Subject: [PATCH] Wait till rendering thread completion before applying webfonts So that the fontfamily values are always 'seen' by the webfonts jquery plugin. Missing this was causing incorrect behavior -overriding the fontfamiliy from css- in random cases. The stylesheet ext.uls.webfonts.css define font family values for interlanguge links and autonym class. This patch make sure that that css values are read by jquery.webfonts while deciding which font to apply. Autonym font is supposed to be used for them. If jquery.webfonts does not read that these elements has a font family defined in css as "'Autonym', sans-serif", it will attempt to apply fonts as per user preference or default fonts based on lang attribute. That will cause applying bigger fonts. jquery.webfonts does not apply any fonts, if an element has explicit font family value defined by inline css or by external style sheets. Bug: 59958 Change-Id: I2da436caa618bc2318e20e3c0492a6bf1c03e162 --- resources/js/ext.uls.webfonts.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/resources/js/ext.uls.webfonts.js b/resources/js/ext.uls.webfonts.js index 03e1c32a..f315c173 100644 --- a/resources/js/ext.uls.webfonts.js +++ b/resources/js/ext.uls.webfonts.js @@ -84,14 +84,21 @@ return excludes; }() ) } ); - $( 'body' ).webfonts(); - // Load the css required for Autonym font. Note that this wont download the font. - // Browsers are smart enough to delay it till some element with this font-family - // become visible. For eg: 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 css is ready so that automatically - // the font get applied to such future elements. - $( 'body' ).data( 'webfonts' ).load( 'Autonym' ); + + // Execute after task queue is processed so that the rendering is complete. + // This is important because webfonts behavior depends on the font-family + // 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 ); }; $( document ).ready( function () {