From 0f8512a627c38f6bfc728dfec144c433da4198a0 Mon Sep 17 00:00:00 2001 From: "Amir E. Aharoni" Date: Tue, 30 Oct 2012 07:05:49 +0200 Subject: [PATCH] (bug 39560) Bring fix from upstream Change-Id: I22bb979475511ec6354ff61411248e134c4a14a8 --- lib/jquery.webfonts.js | 43 ++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/lib/jquery.webfonts.js b/lib/jquery.webfonts.js index d3607288..053cd697 100644 --- a/lib/jquery.webfonts.js +++ b/lib/jquery.webfonts.js @@ -82,8 +82,10 @@ * @param fontFamily String: font family name */ apply: function( fontFamily, $element ) { - $element = $element || this.$element; var fontStack = this.options.fontStack.slice( 0 ); + + $element = $element || this.$element; + // Loading an empty string is pointless. // Putting an empty string into a font-family list doesn't work with // jQuery.css(). @@ -91,9 +93,16 @@ this.load( fontFamily ); fontStack.unshift( fontFamily ); } - $element.css( 'font-family', fontStack.join() ); - $element.find( 'textarea, input' ).not( this.options.exclude ).css( 'font-family', - fontStack.join() ); + + // Set the font of this element if it's not excluded + if ( !$element.is( this.options.exclude ) ) { + $element.css( 'font-family', fontStack.join() ); + } + + // Set the font of this element's children if they are not excluded + $element.find( 'textarea, input' ) + .not( this.options.exclude ) + .css( 'font-family', fontStack.join() ); }, /** @@ -121,27 +130,33 @@ * different language than element */ parse: function() { - var that = this; - that.$element.find( '*[lang], [style], [class]' ).each( function( i, element ) { - var fontFamilyStyle, fontFamily, $element = $( element ); + var webfonts = this; + + webfonts.$element.find( '*[lang], [style], [class]' ).each( function( i, element ) { + var fontFamilyStyle, fontFamily, + $element = $( element ); fontFamilyStyle = $element.css( 'fontFamily' ); + if ( fontFamilyStyle ) { fontFamily = fontFamilyStyle.split( ',' )[0]; + // Remove the ' and " characters if any. fontFamily = $.trim( fontFamily.replace( /["']/g, '' ) ); - if ( that.load( fontFamily ) ) { - // Font family overrides lang attribute - // But was it the fontfamily allocated for the current + + if ( webfonts.load( fontFamily ) ) { + // Font family overrides the lang attribute, + // but was it the fontfamily allocated for the current // language? - if ( fontFamily === that.getFont( element.lang ) ) { + if ( fontFamily === webfonts.getFont( element.lang ) ) { return true; } } } - if ( element.lang && element.lang !== that.$element.attr( 'lang' ) ) { - fontFamily = that.getFont( element.lang ); - that.apply( fontFamily, $( element ) ); + + if ( element.lang && element.lang !== webfonts.$element.attr( 'lang' ) ) { + fontFamily = webfonts.getFont( element.lang ); + webfonts.apply( fontFamily, $( element ) ); } } ); },