Hello!
I want to load a lot of external fonts from the Google Font Api. To increase performance, I want to load them "on the fly", when a specific font is selected from the dropdown menu. When the ckeditor loads the 1st time, I want to parse the content from the body and look for all used unknown font-family - put it in an array and load the fonts form the google api.
Can you please tell me, at which point do I have to launch the function, when the ckeditor loads the 1.st time and which point, when the user selected a new font from the drop-down menu?
I use the compressed ckeditor.js because I get an error, that the variable plugins is null when I use the ckeditor_source.js.
if someone needs the parser ... I'am not a js pro but it's a start
var used_fonts = []; var font_pool = ['Fontdiner+Swanky','Cherry+Cream+Soda','Slackey','Sunshiney','Luckiest','Walter+Turncoat','Calligraffitti','Schoolbell','Coming+Soon','Permanent+Marker','Crushed','Homemade+Apple','Rock+Salt','Syncopate','Crafty+Girls','Chewy','Irish+Growler','Bentham','Merriweather','Kranky','UnifrakturMaguntia','Orbitron','Lekton','Corben','Unkempt','Buda','Cabin','Gruppo','Tinos','Lato','Allerta+Stencil','Cousine','Coda','Arimo','Just+Another+Hand','Kenia','Allerta','PT+Sans','UnifrakturCook','Raleway','Arvo','Vibur','Anonymous+Pro','Puritan','Josefin+Sans','Lobster','Covered+By+Your+Grace','Neuton','Cuprum','Philosopher','Copse','Crimson+Text','Molengo','Old+Standard+TT','Nobile','Reenie+Beanie','Cantarell','Droid+Sans+Mono','Droid+Sans','Vollkorn','Cardo','IM+Fell','Inconsolata','Ubuntu','Yanone+Kaffeesatz','Droid+Serif','Mountains+of+Christmas','Tangerine','Just+Me+Again+Down+Here','Josefin+Slab','OFL+Sorts+Mill+Goudy+TT','Geo','Sniglet','Neucha','Kristi']; $("*").each(function(){ var string = $(this).css("font-family").replace(/'/g,""); string = string.replace(/sans/,""); string = string.replace(/serif/,""); string = string.replace(/,/g,""); string = string.replace(/"/g,""); string = string.replace(/ /g,"+"); if($.inArray(string,font_pool) != "-1" && $.inArray(string,used_fonts) == "-1"){ used_fonts.push(string); //alert(string); } }); WebFontConfig = { google: { families: used_fonts } }; (function() { 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); })();
Re: CKE and Google Fonts Api
you need to add :
- the google font name to 'font_names' config var
the google css to 'contentCss' config var
Sample ? To add the google webfont "Lobster", call ckeditor with something like :
Re: CKE and Google Fonts Api
Hello,
I did this part of script to use all google webfonts (I got the list in the Font previewer tool, in the select input).
Just enter the fonts you want in the array myFonts and it will be automatically loaded. Many font will make the ckeditor font selector menu heavy to load.
Here's the js :
Re: CKE and Google Fonts Api
Ze Big Duck
You can do what you are doing there programmatically, without having to create a great big array. And at the same time pick up on the latest set of Google webfonts. First you need to get a webfonts key from Google, then simply this:
Re: Re: CKE and Google Fonts Api
Thanks for the code, much appreciate it. Can you please explain which code goes where in what file. This would greatly help starters/non-programmer.
Regards,
Praney
Can we improve the
Can we improve the performance here. i have around 400 web fonts and concat all the css into contents.css take a bit long. how i can improve it?
can i add based on what font user select and dynamically i will add the css into the head ?
Hello, i do the following:
Hello, i do the following:
CKEditor INLINE fix
Hi,
add the google fonts stylesheet to your document header.
Performance Issue when user a lot of fonts
Hi,
I use this code and its work percectly but I have a problem with the performance.
I already change the code to make only one request to google for getting the CSS but when I click on the Font Select Box
to open the font list the browser is making a lot of request to google for getting the fonts that need to be display and this is
taking a lot of time (its downloading 6.2MB because I am using around 60 font).
I googling and find the next plugin for Bootstrap and as you can see they do it using a background image with all the fonts.
http://bootstrapformhelpers.com/googlefont/#.Um_TCXAwojY
I like to do the same for the CKEditor but I do not know how to edit and change the font combobox to work like this.
Can anyone have a solution to my case?
Keep it simple
Simply add this at the top of the ckeditor stylesheet, contents.css that is.