This issue means to provide steps and tasks needed to push the jQuery module forward.

CommentFileSizeAuthor
#7 jquery.patch10.28 KBrobloach
#7 jquery.make_.txt672 bytesrobloach

Comments

robloach’s picture

We should have all versions of the jQuery module across all versions of Drupal (5, 6 and 7) accomplish the same thing. Replace the installed version of jQuery (and jQuery UI) with whatever version of jQuery that the Libraries API finds.

Since hook_library is pretty much what the jQ module was in Drupal 5/6, we should consider backporting it. jQP goes one step further and provides a user interface around it. Not sure we really need a user interface for the jQuery module though.

sun’s picture

TBH, I wouldn't want to waste time on D6 and below. Those old "scenarios" either work or they don't. It's rather unlikely that users will switch from jquery_update or any other, as people usually use their API functions in custom code and themes. I'd say we rather have to deal with new users/installs, and people upgrading from earlier Drupal versions once D7 is out (who will have to redo their sites anyway).

Already mentioned over in #719896: Add a hook_libraries_info(): After hook_libraries_info() landed, one of the next steps for Libraries API is to expose a "widget" for integrating modules, which probably counts as UI. Aside from that, Libraries API should also provide helper functions for dealing with hook_requirements() and related scenarios, i.e. enforce properly supported libraries (versions) at Drupal installation time, module installation time, and informal status reporting at runtime.

Additionally, we discussed in IRC that Libraries API needs to be able to expose (or even override?) installed libraries to hook_library(). That's another follow-up issue to tackle, once hook_libraries_info() lands (and which doesn't exist yet).

klonos’s picture

I agree on the 5.x as an 'old scenario', but for 6.x you'll need to rethink IMHO: http://drupal.org/node/763378

6.x: ~275.000 sites using it
7.x: only ~1.000 - ~1.250 sites using it

I like the new features coming with D7 too, but the upgrade_status module report still shows only 4 of my modules ready (actually in D7 core), ~40 of them do not even have a 7.x dev version yet.

As for the people that'll switch to D7 from D6... I wouldn't count on large crowds rushing to do so. How about a plan to go for the D7 version and then backport it to D6? I think it sounds reasonable + you'll get more beta testers in the 6.x version.

As I said... MHO.

robloach’s picture

I'm on board with klonos in getting everything working very nicely in Drupal 7, and then backporting. We should make sure the Drupal 7 version is solid and does what it says it does very nicely, and then consider backporting it to the jQuery module for 6.x.

In Drupal 7, I see the Libraries API and jQuery module doing a couple of things:

  1. #719896: Add a hook_libraries_info()... We have to think about this one, since hook_library is pretty much just a bunch of meta-data already, essentially the same idea as hook_libraries_info(). Could we instead use hook_library() and just build off of it instead of implementing yet another hook?
  2. Implement hook_library_alter() to swap out Drupal core's jQuery and jQuery UI versions
  3. Note that because of this, you could essentially install any version of jQuery you wanted. We must somehow allow modules to tell which version of jQuery is being used, so the developer can take that into consideration. In #685060: Get ready for 1.4, I exposed a hook_jquery_update_requirements($version), but I'm not sure this is the right solution for Drupal 7. Thoughts?
sun’s picture

Excellent considerations, Rob!

1) A first patch for #719896: Add a hook_libraries_info() has been committed already; but tstoeckler is working on a follow-up. I don't feel very comfortable with the idea of re-using hook_library(), primarily, because that would bind and limit us to the structure and format of the core hook. Also, the surrounding API functionality in core does not support all features and possible libraries that Libraries API does, so users may mistakenly expect that they could load a library through the usual API in Drupal core.

2) yup. :) Technically, 1) is more or less ready. If work was started on this, we'd get important implementation feedback for Libraries API.

3) That's an interesting point. Although the API also supports to register and auto-load version- or variant-specific integration files per module, it doesn't provide a one-shot function returning the installed version of a library yet.

klonos’s picture

Now that we have issue summaries, how about updating this one's?

robloach’s picture

Status: Active » Needs review
StatusFileSize
new672 bytes
new10.28 KB
robloach’s picture

Status: Needs review » Needs work

Still needs work though, since it should also replace jQuery UI.

sun’s picture

Yay, thanks!

+++ b/jquery.module
@@ -5,49 +5,51 @@
     $name = 'jquery';
     $library = libraries_detect($name);
-
     if ($library['installed']) {
...
+    $library = libraries_detect('jquery_ui');

Missing 'installed' check/condition for jquery_ui.

+++ b/jquery.module
@@ -5,49 +5,51 @@
+      $libraries['jquery']['version'] = $library['version'];

The version is only replaced for jquery, but not for jQuery UI components.

+++ b/jquery.module
@@ -5,49 +5,51 @@
-          // @todo Integration files for later versions also need to be assigned
-          //   here, since libraries_load() is not going to be invoked.

@@ -57,81 +59,90 @@ function jquery_library_alter(&$libraries, $module) {
-      // @todo Special handling for the purpose of replacing core libraries; in
-      //   hook_library_alter(), we need to figure out, what core files need to
-      //   be replaced, and, which files not contained in core (but contained in
-      //   a later version) need to be added to the library files. Ugh.

Some of the todos are not resolved yet and should be retained.

+++ b/jquery.module
@@ -5,49 +5,51 @@
+    $components = array('ui', 'ui.accordion', 'ui.autocomplete', 'ui.button',
+      'ui.datepicker', 'ui.dialog', 'ui.draggable', 'ui.droppable', 'ui.mouse',
...
+      'effects.transfer');

Minor: Let's write each component on a separate line, please.

+++ b/jquery.module
@@ -5,49 +5,51 @@
+    foreach ($components as $component) {
+      // Replace all the JavaScript and CSS for the associated libraries.
+      foreach (array('js', 'css') as $asset) {
+        if (isset($libraries[$component]['files'][$asset])) {
+          // Reference each file relative from the library's path.
+          foreach ($libraries[$component]['files'][$asset] as $file => $options) {
+            $libraries[$component]['files'][$asset][$file]['data'] = $library['library path'] . '/' . $options['data'];
+          }
+          $libraries[$component][$asset] = array_intersect_assoc($library['files'][$asset], $libraries[$component][$asset]);
         }
       }
     }

This loop looks extremely complex and confusing, since $libraries refers to the hook_library() libraries, and $library refers to the Libraries API library. I wonder whether we can do anything about that to make it more readable. Potentially using clearer variable names leveraging references.

+++ b/jquery.module
@@ -57,81 +59,90 @@ function jquery_library_alter(&$libraries, $module) {
   $libraries['jquery'] = array(
...
+      'directory_name' => 'jquery',

Why isn't the default directory_name the name (key) of the library?

+++ b/jquery.module
@@ -57,81 +59,90 @@ function jquery_library_alter(&$libraries, $module) {
+      'url' => 'http://code.jquery.com/jquery-1.7.1.min.js',

We need to ask the jQuery team whether they can provide a jquery-latest-stable*.js symlink/download URL.

+++ b/jquery.module
@@ -57,81 +59,90 @@ function jquery_library_alter(&$libraries, $module) {
-      // 1.4.3+: jQuery JavaScript Library v1.4.3
...
+      // ! jQuery v1.7.1 jquery.com | jquery.org/license */

It is highly recommended to keep the info about old version strings, regardless of whether they may be outdated. (all of this may be backported to D6 at some point)

The recommended syntax for these comments is like the old (here removed) line:

// [version(s)]: [example-string]