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

For example,

<?php
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: drupal_add_js() defer and async options break when aggregation is enabled (Replace with universal attributes array)

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

Comments

StatusFileSize
new1.89 KB

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

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.

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.

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.

StatusFileSize
new1.91 KB

Rerolled patch with a code fix.

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.