Download & Extend

Move drupal_add_js $reset parameter as an option for $options['type']

Project:Drupal core
Version:7.x-dev
Component:javascript
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

This patch does what the title says. This allows for the possibility of ultimately allowing the option to override function parameters for #315100: Allow to add JS/CSS libraries (sets of files, settings, and dependent libraries).

That means that to reset js, you'll call drupal_add_js(NULL, 'reset'); rather than drupal_add_js(NULL, NULL, TRUE);

For completeness, we do the same with drupal_add_css. (Hoping we can merge those two functions later for cleaner code.) This patch also takes care of all simpletests for the two. I grepped core for drupal_add_js(NULL, NULL, TRUE); and drupal_add_css(NULL, NULL, TRUE); but found nothing.

There's also the possibility that something like drupal_add_js('myfile.js', 'header', TRUE); is called, which would be bad practice now. I did a quick scan through the API and didn't see anything, so it's probably safe.

AttachmentSizeStatusTest resultOperations
drupal_add_js_reset.patch6.38 KBIdlePassed: 8972 passes, 0 fails, 0 exceptionsView details

Comments

#1

Status:active» needs work

This is wicked awesome cool, but noticed this:

<?php
-function drupal_add_css($path = NULL, $options = NULL, $reset = FALSE) {
-  static
$css = array();
+function
drupal_add_css($path = NULL, $options = NULL) {
+static
$css = array();
?>

Would be good to have the two spaces in there. I'll be able to hit this up sometime in the next 12 hours.

#2

Status:needs work» needs review

thanks for catching that. here's an updated patch.

AttachmentSizeStatusTest resultOperations
drupal_add_js_reset.patch6.36 KBIdlePassed: 8991 passes, 0 fails, 0 exceptionsView details

#3

Status:needs review» reviewed & tested by the community

Yay!

#4

Sorry, thought I should remove the fuzzies. Didn't change anything code-wise.

AttachmentSizeStatusTest resultOperations
345973.patch5.91 KBIdlePassed: 8972 passes, 0 fails, 0 exceptionsView details

#5

Status:reviewed & tested by the community» needs work

Hrm, it seems to me that the documentation for the 'reset' parameter is inaccurate.

+ *   Note that if $options or $options['type'] is 'reset', then $path will be
+ *   ignored.

This doesn't seem to be the case, the processing continues even after the reset. So you could in theory add CSS/JS file at the same time as resetting all the current files. Should we add a "return" immediately following the if (options['reset']) or should we adjust the docs? The $options['reset'] option also needs a much better description, since it doesn't say what it actually does.

#6

Status:needs work» needs review

Note that if type is 'reset', then $data and all other $options will be ignored and the JavaScript added so far will be reset.

AttachmentSizeStatusTest resultOperations
345973.patch5.96 KBIdlePassed: 8994 passes, 0 fails, 0 exceptionsView details

#7

Status:needs review» reviewed & tested by the community

Code looks good. Tests pass. This is a simple change.

#8

Webchick asked for a test.

AttachmentSizeStatusTest resultOperations
345973.patch6.3 KBIdleUnable to apply patch 345973_1.patchView details

#9

Status:reviewed & tested by the community» needs work

Awesome, thanks!!

Committed to HEAD. This needs documentation in the upgrade docs, it looks like.

#10

Yay, thanks a lot, Matt and Aaron. Docs here, if there's anything missing there, please feel free to hack away.

#11

Status:needs work» fixed

Uhh, fixed. Next step is #259368: Allow Inline CSS in drupal_add_css, I believe.....

#12

Status:fixed» closed (fixed)

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

nobody click here