Skip to content

Instantly share code, notes, and snippets.

@pamelafox
Created August 14, 2011 00:41
Show Gist options
  • Save pamelafox/1144441 to your computer and use it in GitHub Desktop.
Save pamelafox/1144441 to your computer and use it in GitHub Desktop.
Loading fonts CSS
var fontNum = 0;
var maxCharacters = 1730;
var cssBaseUrl = 'http://fonts.googleapis.com/css?family=';
function addCss() {
var cssUrl = cssBaseUrl;
while ((cssUrl.length + allFontNames[fontNum].length) < maxCharacters && (fontNum < (allFontNames.length-1))) {
// dont load khmer, no point
if (fonts[allFontNames[fontNum]].subsets[0] != 'khmer') {
cssUrl += escape(allFontNames[fontNum]) + '|';
}
fontNum++;
}
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = cssUrl;
document.getElementsByTagName('head')[0].appendChild(link);
}
while (fontNum < (allFontNames.length-1)) {
addCss();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment