Update jquery.webfonts from upstream
Upstream: https://github.com/wikimedia/jquery.webfonts/ Changes: * Respect explicit font styles of child elements when switching languages * Fix duplicate font-weight property Change-Id: Ic45357b2613e6f33c392f9a78cc389f31c99e036
This commit is contained in:
committed by
Siebrand
parent
afc5774ee2
commit
7867b41ca4
@@ -61,8 +61,10 @@
|
|||||||
* @return {String} Font family name
|
* @return {String} Font family name
|
||||||
*/
|
*/
|
||||||
getFont: function( language ) {
|
getFont: function( language ) {
|
||||||
|
language = ( language || this.language ).toLowerCase();
|
||||||
|
|
||||||
if ( this.options.fontSelector ) {
|
if ( this.options.fontSelector ) {
|
||||||
return this.options.fontSelector( this.repository, language || this.language );
|
return this.options.fontSelector( this.repository, language );
|
||||||
} else {
|
} else {
|
||||||
return this.repository.defaultFont( language );
|
return this.repository.defaultFont( language );
|
||||||
}
|
}
|
||||||
@@ -211,7 +213,15 @@
|
|||||||
|
|
||||||
// Load and apply fonts for other language tagged elements (batched)
|
// Load and apply fonts for other language tagged elements (batched)
|
||||||
if ( element.lang && element.lang !== webfonts.language ) {
|
if ( element.lang && element.lang !== webfonts.language ) {
|
||||||
|
// language differs. We may want to apply a different font.
|
||||||
|
if ( webfonts.hasExplicitFontStyle ( $element ) ) {
|
||||||
|
// respect the explicit font family style. Do not override.
|
||||||
|
// This style may be from css, inheritance, or even from
|
||||||
|
// browser settings.
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
fontFamily = webfonts.getFont( element.lang );
|
fontFamily = webfonts.getFont( element.lang );
|
||||||
|
}
|
||||||
|
|
||||||
if ( !fontFamily ) {
|
if ( !fontFamily ) {
|
||||||
// No font preference for the language.
|
// No font preference for the language.
|
||||||
@@ -246,6 +256,24 @@
|
|||||||
} );
|
} );
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find out whether an element has explicit non generic font family style
|
||||||
|
* For the practical purpose we check whether font is same as top element
|
||||||
|
* or having any of generic font family
|
||||||
|
* http://www.w3.org/TR/CSS2/fonts.html#generic-font-families
|
||||||
|
* @param {jQuery} $element
|
||||||
|
* @return {boolean}
|
||||||
|
*/
|
||||||
|
hasExplicitFontStyle: function ( $element ) {
|
||||||
|
var elementFontFamily = $element.css( 'fontFamily' );
|
||||||
|
|
||||||
|
// whether the font is inherited from top element to which plugin applied
|
||||||
|
return this.$element.css( 'fontFamily' ) !== elementFontFamily
|
||||||
|
// whether the element has generic font family
|
||||||
|
&& ( $.inArray( elementFontFamily,
|
||||||
|
['monospace', 'serif', 'cursive','fantasy', 'sans-serif'] ) < 0 );
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List all fonts for the given language
|
* List all fonts for the given language
|
||||||
*
|
*
|
||||||
@@ -375,10 +403,6 @@
|
|||||||
fontFaceRule += '\tfont-weight:' + fontconfig.fontweight + ';';
|
fontFaceRule += '\tfont-weight:' + fontconfig.fontweight + ';';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( fontconfig.fontweight !== undefined ) {
|
|
||||||
fontFaceRule += '\tfont-weight:' + fontconfig.fontweight + ';';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( fontconfig.fontstyle !== undefined ) {
|
if ( fontconfig.fontstyle !== undefined ) {
|
||||||
fontFaceRule += '\tfont-style:' + fontconfig.fontstyle + ';';
|
fontFaceRule += '\tfont-style:' + fontconfig.fontstyle + ';';
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user