Latest usable jquery for Plone 4.3: 1.11.3?

When Plone 4 shipped, jquery 1.7 was included by default and this is still the case for the core distribution. Efforte by @thet and others 1-2 years ago made Plone compatible with jQuery 1.9 and when we did upgrades/new themes the recent years as an integrator we pinned jquery at least to 1.9 to benefit from jquery bugfixes.

From a frontend developer I recently talked to I understood that the jquery 1.X series updates after 1.9 were indeed bugfixes and no incompatibilities/problems should arise. For others who follow the same practice: last week I found out jquery 1.11.3 is the last version you can safely update to. (and avoid 1.10.1, tinymce's plonebrowser will not work with that one)

In jquery 1.12.x a function .buildFragment has been made private and the overlayhelpers.js (.prepOverlay() in plone.app.jquerytools that's shipping with Plone 4 depends on that function.

https://blog.jquery.com/2016/01/08/jquery-2-2-and-1-12-released/

The motivation for privatising the function in the jquery 1.X branch is a bit odd where it is argued 'now is the time to do it for jquery 3.X and it wasn't part of the public api". So why break compatibility with for 1.X users, but well...

I tried to look up if other projects that depend on jquery have had the same problem and possible solutions, found one (https://github.com/canjs/canjs/issues/2176) but I'm a (beginning) jquery user, no clue about the internals and the changeset there didn't help me.

So for now, if you prefer a recent jquery in your Plone 4 projects, stick with 1.11.3 if you or your addons need .prepOverlay. And if you're a jquery wizard.... :wink:

1 Like

For reference: I was able to implement a minimal version of $.buildFragment which works for the case where it is called in overlayhelper.js. So, if you put the following code in a JS file you'll be able to use at least jQuery 1.12.4 (the latest from the 1.12.x series now).

Here's the code:

$.buildFragment = function ( elems, context, scripts, selection, ignored ) {
  if ((!scripts.push) || selection || ignored) {
    throw "Essa função foi implementada apenas para uso do arquivo overlayhelpers.js, ver documentação."
  }

  // elems é uma lista de strings HTML. Faz parsing de cada uma delas e extrai as tags script como
  // nós do DOM, adicionando-os ao array strings.
  $.each(elems, function() {
    var parsed = $.parseHTML(elems[0], document, true);

    var $root = $('<div/>');

    $.each(parsed, function() {
      $root.append($(this));
    });

    $root.find('script').each(function() {
      scripts.push(this);
    })
  });
};
3 Likes

Does this issue affect only Plone 4.x? I tried modals (e.g. in Dexterity Types control panel) in Plone 5 with jQuery 1.12.4 and it works without the custom $.buildFragment

The 'default' core modals in Plone 5 are done using mockup's pat-modal (http://plone.github.io/mockup/dev/#pattern/modal) and not with jquery. So the missing .buildFragment in the last jquery 1.x versions will probably not impact thos Plone 5 modals .

1 Like

Thanks, @fredvd! I still see two occurrences of prepOverlay in Plone 5 but couldn't find them in the browser to manually test:

UPDATE: Looking at commit history, those seem to be leftovers from the jQuery Tools to pat-modal migration (currently protected with if clauses so code works for Plone 4 and 5) so we're safe skipping the $.buildFragment jQuery patch on Plone 5.

Plone Foundation Code of Conduct