Last active
April 7, 2017 20:27
-
-
Save examinedliving/211445334708d7e632dc to your computer and use it in GitHub Desktop.
Creates a font string from desired google fonts based upon arguments as font names.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * loadFonts | |
| * Does the legwork to generate fontStrings to be used in two other functions | |
| * @arguments String {comes from useFonts or getFonts} | |
| * @returns array | |
| */ | |
| function loadFonts(fonts){ | |
| var fontStrings=fonts.map(function(font){ | |
| font=(font[0].toUpperCase() + font.substr(1)).replace(/\s/g,'+'); | |
| return font; | |
| }); | |
| return fontStrings; | |
| } | |
| /** | |
| * useFonts | |
| * loads fonts and appends stylesheet to head | |
| * @arguments String or Array font-names variable number | |
| */ | |
| function useFonts(){ | |
| var fonts=Array.prototype.slice.call(arguments); | |
| var fontString=''; | |
| loadFonts(fonts).forEach(function(font){ | |
| fontString+=font+'|'; | |
| }); | |
| $('head').append('<link href="http://fonts.googleapis.com/css?family=' + fontString + '" rel="stylesheet" type="text/css">'); | |
| } | |
| /** | |
| * getFonts(fonts) | |
| * | |
| * loads fonts and return link | |
| * @arguments String or array font-names variable number | |
| */ | |
| function getFonts(){ | |
| var fonts=Array.prototype.slice.call(arguments); | |
| var fontString=''; | |
| loadFonts(fonts).forEach(function(font){ | |
| fontString+=font+'|'; | |
| }); | |
| return '<link href="http://fonts.googleapis.com/css?family=' + fontString + '" rel="stylesheet" type="text/css">'; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment