After #1524944: Allow different version for administrative pages:

* Set jquery 1.8 for front end pages.
* Set jquery 1.7 for back end pages.
* Go to a node with a media field
* Add a file to the media field
* Save
* Edit the node
* Click on Remove next to the media field

Te site does nothing but it should show a popup. The problem seems to be that in this point (and some other places too) it's trying to load jquery 1.8:

GET ...jquery/1.8/jquery.min.js?v=1.8.2&_=1364428694695    200 OK   jquery...v=1.7.1 (line 4)
GET ...ox/jquery.colorbox-min.js?mkc9hs&_=1364428694905   200 OK   jquery...v=1.7.1 (line 4)
GET ...b/colorbox/js/colorbox.js?mkc9hs&_=1364428694987    200 OK   jquery...v=1.7.1 (line 4)
GET ...colorbox_default_style.js?mkc9hs&_=1364428695069    200 OK   jquery...v=1.7.1 (line 4)
TypeError: $(...).filter(...).once(...).colorbox is not a function
[Break On This Error] 	
.colorbox(settings.colorbox);
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lucascaro’s picture

Title: Setting different versions for frontend and admin leads to errors. » Loads the frontend version on ajax calls on backend pages

Debugging this I realized that when doing an ajax call from the backend, jquery_update has no way to know and attempts to load the frontend version of jquery, causing an error and breaking ajax calls.

current_paths for ajax calls might not be marked as admin paths, but they need to use the same jquery version as the original page.

  if (!empty($admin_version) && path_is_admin(current_path())) {
    if (version_compare($version, $admin_version, '!=')) {
      $version = $admin_version;
    }
  }
lucascaro’s picture

lucascaro’s picture

Status: Active » Needs review

I've found an error on jquery_update.module:207

 if (!empty($_POST['ajax_page_state']['jquery_version'])) {
    $ajax_version = $_POST['ajax_page_state']['jquery_version'];
    if (in_array($valid_version, array('1.5', '1.6', '1.7'))) {
      $version = $ajax_version;
    }
  }

The if clause is using a undefined variable, it should be using $ajax_version instead.

I also had to add the following script to make it work (inspired on http://drupal.org/node/1957782):

(function (D) {
  var beforeSerialize = D.ajax.prototype.beforeSerialize;
  D.ajax.prototype.beforeSerialize = function (element, options) {
    beforeSerialize.call(this, element, options);
    options.data['ajax_page_state[jquery_version]'] = D.settings.ajaxPageState.jquery_version;
  }
})(Drupal);

With these two changes it's working on my end. Ill post a patch ASAP.

lucascaro’s picture

Here's the patch:

Punk_UnDeaD’s picture

don't use drupal_add_js
it fix for drupal.ajax library, not an independent file
use something like


$javascript['drupal.ajax']['js'][] = array(
    'data' => array('ajaxPageState' => array('jquery_version' => $version)),
    'type' => 'setting'
  );
  $javascript['drupal.ajax']['js'][$path . '/jquery_update.js'] = $javascript['drupal.ajax']['js']['misc/ajax.js'];

lucascaro’s picture

re-roll with the change from #5

ericduran’s picture

Hmm, The beforeSerialize shouldn't be require. That is why I added the POST check.

How is the Ajax request being made? If the ajax request is properly being done using Drupal Ajax system the post value should be there.

I'm going to need to test this before this patch can be added.

Punk_UnDeaD’s picture

not all data collect to send
only ajax_html_ids, ajax_page_state[theme], ajax_page_state[theme_token], ajax_page_state[css] and ajax_page_state[js]

see Drupal.ajax.prototype.beforeSerialize

ericduran’s picture

@Punk_UnDeaD Ahh, It's because I only tested with ajax forms which does return the entire Drupal.settings.

Reviewing the patch now.

Thanks.

ericduran’s picture

+++ b/jquery_update.moduleundefined
@@ -92,6 +92,8 @@ function jquery_update_library_alter(&$javascript, $module) {
+  $javascript['drupal.ajax']['js'][$path . '/js/jquery_update.js'] = $javascript['drupal.ajax']['js']['misc/ajax.js'];

We should actually change the weight to go right after the ajax script.

Lets not leave the weight the same to make it clear that we want that specific order.

The rest looks good.

Thanks all.

ericduran’s picture

Status: Needs review » Fixed

I made some changes. I made sure our ajax fix is only on the drupal ajax js and made sure it's always after it.

This is now fixed.

Thanks.

--
http://drupalcode.org/project/jquery_update.git/commit/7b66e73

Status: Fixed » Closed (fixed)

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