Skip to content

Instantly share code, notes, and snippets.

@xavierartot
Created March 5, 2014 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xavierartot/9370715 to your computer and use it in GitHub Desktop.
Save xavierartot/9370715 to your computer and use it in GitHub Desktop.
charging Google font
// charging google font
1
2 $.get("https://www.googleapis.com/webfonts/v1/webfonts?key=AIzaSyChZeTZ-DzMW-45IUBXUSuBha9MWEiXXtI", {},
3 function (data) {
4 // charge toutes les polices dans le select
5 $.each(data.items, function (index, value) {
6 $('#fonts-l').append($("<option class='google'></option>").attr("value", value.family).text(value.family));
7 });
8
9 // au chargement de la page on affiche la police enregistrer
10 var t = $.trim( $('.hide-fonts').text() );
11 $("#fonts-l ").val(t).attr('selected', 'selected');
12
13 if($("#fonts-l").find('option:selected').hasClass('google') ){
14 $('body')
15 .append("<link rel='stylesheet' href='http://fonts.googleapis.com/css?family=" + t.replace(/\s+/g," ") +"' type='text/css' media='all' />");
16 $('#primary-navigation a').css({'font-family':'"'+t+'"'});
17 }
18 });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment