jQuery Update currently operates by removing existing scripts and appending its replacements to the end of the list. This may break other scripts that rely on a properly initialized environment, that is, the load order of scripts. The attached patch solves this problem by properly exchanging scripts without touching the order. As a side effect, the special handling for jquery.js is also removed.

CommentFileSizeAuthor
#1 858578-jquery_update.patch3.67 KBsmk-ka
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

smk-ka’s picture

Status: Active » Needs review
FileSize
3.67 KB
froboy’s picture

Applied this patch and everything seems to work just fine and dandy. Thanks!

mfer’s picture

This looks nice. Let me take a look at it.

sun’s picture

+++ jquery_update.module	19 Jul 2010 17:30:37 -0000
@@ -55,34 +56,34 @@ function jquery_update_theme_registry_al
+    $scripts = drupal_add_js();
...
+    $new_scripts = array();
...
+    // Merge new scripts back into $scripts.
+    $scripts = array_merge($scripts, $new_scripts);

Is there a reason for why we are building a new array and merging that later on into $scripts, instead of directly altering the existing $scripts array entries? If so, we should document that. If not, then directly manipulating the existing $scripts would be more safe.

Powered by Dreditor.

smk-ka’s picture

This is what JU currently does: since $scripts is keyed by file name, it unsets the old key and appends the new one, which changes the order. The new script creates a copy exactly for the reason to retain the order. The only way to manipulate $scripts directly would be using array_splice(). Looking at its syntax makes me believe the result won't be more readable, though.

sun’s picture

Ah, I see it now, sorry - only in D7, drupal_get_js() is using the array values and ignoring the keys entirely.

...which makes this RTBC, although I didn't test myself, but I'm sure you did -- unless mfer still wants to have a look at it, too?

markhalliwell’s picture

Issue summary: View changes
Status: Needs review » Closed (outdated)

Drupal 6 reached EOL (end-of-life) on February 24, 2016.