Skip to content

Instantly share code, notes, and snippets.

@Undistraction
Created December 10, 2014 21:09
Show Gist options
  • Save Undistraction/8ecfa4975c2c1fbea12c to your computer and use it in GitHub Desktop.
Save Undistraction/8ecfa4975c2c1fbea12c to your computer and use it in GitHub Desktop.
<script type="text/javascript">
// This is a hack to rewrite font-names so that different weights / styles of the same face have
// the same font-name.
(function () {
'use strict';
var faceFrom = 'Maison Neue Medium';
var faceTo = 'Maison Neue';
var hasRewrittenRules = false;
/**
* Fontdeck returns different font-family for each font variation.
* We will rewrite inline <style> it creates to have one font-family.
*/
function rewriteFontFaceRules() {
if (hasRewrittenRules) {
return;
}
var key;
var stylesheet;
var index;
var rule;
var fontFamily;
for (key in document.styleSheets) {
stylesheet = document.styleSheets[key];
if (!stylesheet.ownerNode || stylesheet.ownerNode.tagName !== 'STYLE') {
continue;
}
for (index in stylesheet.rules) {
rule = stylesheet.rules[index];
if (!(rule instanceof window.CSSFontFaceRule)) {
continue;
}
fontFamily = rule.style.fontFamily;
if (fontFamily && fontFamily.indexOf(faceFrom) > -1) {
rule.style.fontFamily = faceTo;
hasRewrittenRules = true;
}
}
}
}
window.WebFontConfig = {
fontdeck: { id: '49493' },
fontactive: rewriteFontFaceRules,
active: rewriteFontFaceRules
};
var wf = document.createElement('script');
wf.src = ('https:' === document.location.protocol ? 'https' : 'http') +
'://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
wf.type = 'text/javascript';
wf.async = 'true';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(wf, s);
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment