The module uses $.triggerHandler() to execute any event handlers which are bound to 'dart_tag_render'. This was implemented in #1135168: Allow modules to modify the final rendered ad tag using js

If a module wants to alter the final rendered tag in JS then it has to implement string replacement. As I understand due to the nature of this function jQuery does not allow multiple implementations, because alterations can mostly be string manipulations only.

Instead of returning the jQuery object (to allow chaining), .triggerHandler() returns whatever value was returned by the last handler it caused to be executed. If no handlers are triggered, it returns undefined

e.g. If another module implements this then only the last module's implementation would take precedence, rendering all previous module implementations useless.

One solution would be to implement or adapt a proper 'hook' implementation where the modified string is passed to each event listener making sure that no alterations are lost.
Any suggestions?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

melon’s picture

Status: Active » Needs review
FileSize
2.13 KB

If a new .triggerHandler() is implemented on the tag object before the ad string is constructed then all modules implementing an event listener would be able to modify the tag since objects are passed by reference in javascript and there is no need to return a value.

This patch introduces a new 'hook' called dart_tag_process and it works if there are more than one modules are implementing it. Example implementation would be:

  $(document).bind('dart_tag_process', function(event, tag){
    // modify tag however you see fit and then return it.
    // example of adding a new key|val pair:

    tag.key_vals['myNewKey'] = [{val: 'myNewValue', eval: false}];;
  });

I kept the old dart_tag_render trigger intact for backwards compatibility but anyone currently implementing it should be advised not to. Please let me know of your thoughts on this.

bleen’s picture

Status: Needs review » Fixed

This has been committed, THANKS!!

Status: Fixed » Closed (fixed)

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