Update version from upstream
* Adds exclude option Change-Id: Iaa220abf0bc11c26b13a481e1fbf3b307a0e9d0b
This commit is contained in:
@@ -78,23 +78,27 @@
|
||||
|
||||
/**
|
||||
* Apply a font for the element.
|
||||
*
|
||||
* @param fontFamily String: font family name
|
||||
*/
|
||||
apply: function( fontFamily, $element ) {
|
||||
$element = $element || this.$element;
|
||||
var fontStack = this.options.fontStack.slice( 0 );
|
||||
// Loading an empty string is pointless.
|
||||
// Putting an empty string into a font-family list doesn't work with jQuery.css().
|
||||
// Putting an empty string into a font-family list doesn't work with
|
||||
// jQuery.css().
|
||||
if ( fontFamily ) {
|
||||
this.load( fontFamily );
|
||||
fontStack.unshift( fontFamily );
|
||||
}
|
||||
$element.css( 'font-family', fontStack.join() );
|
||||
$element.find('textarea, input').css('font-family', fontStack.join());
|
||||
$element.find( 'textarea, input' ).not( this.options.exclude ).css( 'font-family',
|
||||
fontStack.join() );
|
||||
},
|
||||
|
||||
/**
|
||||
* Load a given fontFamily if not loaded already
|
||||
*
|
||||
* @param fontFamily String font family name
|
||||
*/
|
||||
load: function( fontFamily ) {
|
||||
@@ -113,14 +117,14 @@
|
||||
},
|
||||
|
||||
/**
|
||||
* Parse the element for custom font-family styles and
|
||||
* for nodes with different language than element
|
||||
* Parse the element for custom font-family styles and for nodes with
|
||||
* different language than element
|
||||
*/
|
||||
parse: function() {
|
||||
var that = this;
|
||||
that.$element.find('*[lang], [style], [class]').each(function(i, element) {
|
||||
var fontFamilyStyle, fontFamily,
|
||||
$element = $(element);
|
||||
that.$element.find( '*[lang], [style], [class]' ).not( that.options.exclude ).each(
|
||||
function( i, element ) {
|
||||
var fontFamilyStyle, fontFamily, $element = $( element );
|
||||
|
||||
fontFamilyStyle = $element.css( 'fontFamily' );
|
||||
if ( fontFamilyStyle ) {
|
||||
@@ -129,7 +133,8 @@
|
||||
fontFamily = $.trim( fontFamily.replace( /["']/g, '' ) );
|
||||
if ( that.load( fontFamily ) ) {
|
||||
// Font family overrides lang attribute
|
||||
// But was it the fontfamily allocated for the current language?
|
||||
// But was it the fontfamily allocated for the current
|
||||
// language?
|
||||
if ( fontFamily === that.getFont( element.lang ) ) {
|
||||
return true;
|
||||
}
|
||||
@@ -144,13 +149,13 @@
|
||||
|
||||
/**
|
||||
* List all fonts for the given language
|
||||
* @param language mixed: [optional] language code. If undefined all fonts will
|
||||
* be listed
|
||||
*
|
||||
* @param language mixed: [optional] language code. If undefined all
|
||||
* fonts will be listed
|
||||
* @return Array font names array
|
||||
*/
|
||||
list: function( language ) {
|
||||
var fontName = null,
|
||||
fontNames = [];
|
||||
var fontName = null, fontNames = [];
|
||||
|
||||
if ( language ) {
|
||||
fontNames = this.repository.languages[language];
|
||||
@@ -166,11 +171,11 @@
|
||||
|
||||
/**
|
||||
* List all languages supported by the repository
|
||||
*
|
||||
* @return Array language codes
|
||||
*/
|
||||
languages: function() {
|
||||
var language = null,
|
||||
languages = [];
|
||||
var language = null, languages = [];
|
||||
for (language in this.repository.languages) {
|
||||
if ( this.repository.languages.hasOwnProperty( language ) ) {
|
||||
languages.push( language );
|
||||
@@ -181,6 +186,7 @@
|
||||
|
||||
/**
|
||||
* Set the font repository
|
||||
*
|
||||
* @param {Object} repository The font repository.
|
||||
*/
|
||||
setRepository: function( repository ) {
|
||||
@@ -202,10 +208,12 @@
|
||||
},
|
||||
|
||||
/**
|
||||
* 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, inject it to the head
|
||||
* of the body so that it gets loaded.
|
||||
*
|
||||
* @param fontFamily The font-family name
|
||||
* @param variant The font variant, eg: bold, italic etc. Default is normal.
|
||||
* @param variant The font variant, eg: bold, italic etc. Default is
|
||||
* normal.
|
||||
*/
|
||||
getCSS: function( fontFamily, variant ) {
|
||||
var fontconfig, base, version, versionSuffix, styleString, userAgent, fontStyle, fontFormats;
|
||||
@@ -241,13 +249,16 @@
|
||||
styleString += "local('" + fontFamily + "'),";
|
||||
}
|
||||
if ( fontconfig.woff ) {
|
||||
fontFormats.push("\t\turl('" + base + fontconfig.woff + versionSuffix + "') format('woff')");
|
||||
fontFormats.push( "\t\turl('" + base + fontconfig.woff + versionSuffix
|
||||
+ "') format('woff')" );
|
||||
}
|
||||
if ( fontconfig.svg ) {
|
||||
fontFormats.push("\t\turl('" + base + fontconfig.svg + versionSuffix + "#" + fontFamily + "') format('svg')");
|
||||
fontFormats.push( "\t\turl('" + base + fontconfig.svg + versionSuffix + "#"
|
||||
+ fontFamily + "') format('svg')" );
|
||||
}
|
||||
if ( fontconfig.ttf ) {
|
||||
fontFormats.push("\t\turl('" + base + fontconfig.ttf + versionSuffix + "') format('truetype')");
|
||||
fontFormats.push( "\t\turl('" + base + fontconfig.ttf + versionSuffix
|
||||
+ "') format('truetype')" );
|
||||
}
|
||||
styleString += fontFormats.join() + ";\n";
|
||||
if ( fontconfig.fontweight ) {
|
||||
@@ -276,7 +287,8 @@
|
||||
|
||||
$.fn.webfonts.defaults = {
|
||||
repository: WebFonts.repository, // Default font repository
|
||||
fontStack : ['Helvetica', 'Arial', 'sans-serif'] // Default font fall back series
|
||||
fontStack: [ 'Helvetica', 'Arial', 'sans-serif' ], // Default font fallback
|
||||
exclude: '' // jQuery selectors to exclude
|
||||
};
|
||||
|
||||
$.fn.webfonts.Constructor = WebFonts;
|
||||
|
||||
Reference in New Issue
Block a user