Problem: drupal_add_js() should allow the specification of custom attributes.

For example,

drupal_add_js($theme_path . '/path/to/require.js', array(
      'type' => 'file',
      'scope' => 'footer',
      'weight' => 5,
      'attributes' => array(
        'data-main' => $theme_path . '/path/to/main.js',

should produce:
<script data-main="/path/to/main.js" src="/path/to/require.js"></script>

Solution: Patch core with D8 backport of drupal_add_js(). See #1664602: Allow an attributes array to be passed in to drupal_add_js() for setting attributes such as "async" and "defer"

Problem: Aurora hijacks drupal_get_js(), but does not respect custom attributes.

#5 custom_attributes-1910040-5.patch1.91 KBjmoughon
#1 custom_attributes-1910040-2.patch1.89 KBAnonymous (not verified)
Members fund testing for the Drupal project. Drupal Association Learn more


Anonymous’s picture

Here is a patch that implements the necessary changes to aurora_get_js_old().

Snugug’s picture

Status: Active » Postponed (maintainer needs more info)

I'm not sure I understand exactly what you're asking. If you are using the "move js to footer" option in Aurora (and therefore aurora_get_js_old()), the code is identical to drupal_get_js, if not you're using Core's drupal_get_js. Currently, drupal_get_js does not respect attributes, so aurora_get_js_old() behaves correctly. If, on the other hand, you'd like us to add this functionality, it won't go into aurora_get_js_old but rather aurora_get_js as that's where our experimental JS handling goes as that patch hasn't been officially backported yet.

If you'd like this in aurora_get_js_old and in Core's drupal_get_js, I'd highly encourage you to review the patch and get it committed into Core, then we'll backport it into our implementation. If, however, you'd like to use this inside Aurora right now, before it's gotten officially backported, please reroll this patch against aurora_get_js and be aware that you'll need to turn on the experimental JS handling option in order to use this.

Anonymous’s picture

I ran into the issue, because I need that patch to core, but it didn't behave as expected because Aurora implements the original unpatched version. So, I just ported the patch over so that I can pull it into my make file.

Anonymous’s picture

Category: bug » feature

I'm changing this to a feature request. Because, as you point out, this is not technically a bug :-) Just something I needed.

jmoughon’s picture

Rerolled patch with a code fix.

iamcarrico’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

Until that piece is actually implemented into core---- we shouldn't add it here too. Once this patch is implemented into core, then we can go ahead and implement it here.

Closing until that is resolved.