Google's WebFont loader .ready()
Google WebFont config allows you assign a active
function that will be executed when all fonts are loaded. The problem is you can only assign one function. I wrote the ready
method you can add to the WebFontConfig global allows you to add callbacks, without replacing the last one, in the same style as jQuery.
window.WebFontConfig = {
google: { families: ['Oswald:400,300:latin'] },
listeners: [],
active: function() {
this.called_ready = true;
for(var i = 0; i < this.listeners.length; i++) {
this.listeners[i]();
}
},
ready: function(callback) {
if (this.called_ready) {
callback()
} else {
this.listeners.push(callback)
}
}
};
Then on another script:
WebFontConfig.ready(yourCallback);
Written by Marcel Miranda
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Webfonts
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#