Imagine I want to hook some js code to a specific event from the webfont loader like the 'active' event seen at https://developers.google.com/webfonts/docs/webfont_loader#Events

Is this currently possible using this module?

Comments

btmash’s picture

@anthonyR, it isn't possible with this module at the moment...I'm trying to think of a way that is easy for a person to integrate the additional behaviors. The easiest solution (for me) would basically be run drupal_alter() on the array before sending it off to get turned into a js setting. Then you have a hook you can work with in a module you may have. Would that work? Or would you prefer some other method of adding specific js code you have? You could quite possibly override the core js object I provide to webfont loader as well in your js file with something like:

Drupal.settings.google_webfont_loader_api_setting.active = function() {
  // Some of my codes
}

within your jquery sandwich (so long as the weight of your code is lower than the weight of the webfont loader - I'm going to see if I can alter the weight so it comes further down so it is easier to add in your js if necessary).

btmash’s picture

Sorry, this was a post in the wrong issue...

anthonyR’s picture

Status: Active » Fixed

Hey @btmash,
after fiddling around with the weights and trying out some stuff I now have a working solution.
It's possible to just add this in your normal script (in your theme f.e.), which will come after the script provided by the module.
This way it gets added to the existing google_webfont_loader_api_setting object in Drupal.settings, but the code will get executed on the event of the webfont loader, because this stuff lives in the Drupal behaviors i guess.
Pretty easy solution after all : )

(function ($) {
  $(document).ready(function(){
    // theme js lives here

    Drupal.settings.google_webfont_loader_api_setting.active = function() {
      // do stuff on this event fire
    };

  });
})(jQuery);

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.