When jQuery is loaded async, if all elements in a page are cached, it is possible that when jQuery is executed, the domready event has already fired, and Drupal.behaviors won't be executed.

We need mechanism to detect it and run Drupal.behaviors in that case. This bug exists only in D6 version, because it is fixed in jQuery 1.4+ which is used in D7.

Comments

jcisio’s picture

Priority: Normal » Critical
jcisio’s picture

This is discussed at https://github.com/getify/LABjs/issues/16 and it affects both 6.x and 7.x branch. The fix could be quite easy: the jquery_update way! This module replaces drupal.js with its own version. I'll roll a patch in the next few days when I have time.

jcisio’s picture

If anyone wants to test first:
- In this module change $LAB.executeQueue(); to

$LAB.queue(function() {
  $(document).trigger("scripts-ready");
}).executeQueue();

- Then change your misc/drupal.js. In D7, replace this block (I removed comments)

$(function () {
  if (jQuery.support.positionFixed === undefined) {
    var el = $('<div style="position:fixed; top:10px" />').appendTo(document.body);
    jQuery.support.positionFixed = el[0].offsetTop === 10;
    el.remove();
  }
});
$(function () {
  Drupal.attachBehaviors(document, Drupal.settings);
});

with

$(document).bind("scripts-ready", function(){
  if (jQuery.support.positionFixed === undefined) {
    var el = $('<div style="position:fixed; top:10px" />').appendTo(document.body);
    jQuery.support.positionFixed = el[0].offsetTop === 10;
    el.remove();
  }
  Drupal.attachBehaviors(document, Drupal.settings);
});

This is untested, however.

bryancasler’s picture

can't test tonight, will possibly give it a shot tomorrow evening

bryancasler’s picture

I could only find one instance of $LAB.executeQueue(); it was on line 88 of labjs.module 'data' => LABJS_EXCLUDE . "\n\$LAB.executeQueue();",.

After replacing that and updating drupal.js I went ahead and enabled LABjs. I received the following error.

After enabling I got "Parse error: syntax error, unexpected '(', expecting T_VARIABLE or '$' in C:\xampp\htdocs\drupal\sites\all\modules\labjs\labjs.module on line 88"

**I'm on D7**

jcisio’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Active » Needs review

We'll fix it in D7 first. I've committed a patch that does exactly what I said in #3. A small problem with overlay: when I click to a link, the hash change, new page is loaded by Ajax, but just right after that, the URL changes. This problem does not always happen, and I haven't found the cause.

jcisio’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Needs review » Patch (to be ported)

#6 is separated into a new issue: #1050866: Intermittent problem with overlay.module. I consider it is fixed in 7.x. The rest is backporting to 6.x.

dgastudio’s picture

subscribe

matthewdolman’s picture

Version: 6.x-1.x-dev » 7.x-1.0

I just installed the latest release and I get object not defined errors which leads me to believe that the $document(ready) is not firing in the included scripts.

Is this the same issue as mentioned here?

jcisio’s picture

Version: 7.x-1.0 » 6.x-1.x-dev

No, it is not the same thing. Please open new issue, with as much detail as possible.

mikeytown2’s picture

using advagg we can replace misc/drupal.js with a patched version of that file. I already do this when using jsmin+ as it blows up on the misc/jquery.form.js file.
http://drupalcode.org/project/advagg.git/blob/refs/heads/6.x-1.x:/advagg...

jcisio’s picture

Yes, user with addavg enabled can profit pre alter to change drupal.js. Even without advagg, I think I can borrow from jquery_update.module to replace this file.

mikeytown2’s picture

jcisio
Mind posting a modified drupal.js here and I'll fix this issue for users of advagg?

jcisio’s picture

This a a diff for D7 drupal.js in #6. I haven't work in D6, but it should be the same.

--- ../d7/misc/drupal.js	2011-01-22 19:07:08.000000000 +0700
+++ ../d7/sites/all/modules/contrib/labjs/drupal.modified.js	2011-01-23 04:31:48.000000000 +0700
@@ -1,4 +1,4 @@
-// $Id: drupal.js,v 1.72 2011/01/01 04:11:39 webchick Exp $
+// $Id: drupal.modified.js,v 1.1 2011/01/22 21:31:48 jcisio Exp $
 
 var Drupal = Drupal || { 'settings': {}, 'behaviors': {}, 'locale': {} };
 
@@ -350,7 +350,7 @@ document.cookie = 'has_js=1; path=/';
 /**
  * Additions to jQuery.support.
  */
-$(function () {
+$(document).bind('scripts-ready', function(){
   /**
    * Boolean indicating whether or not position:fixed is supported.
    */
@@ -359,10 +359,8 @@ $(function () {
     jQuery.support.positionFixed = el[0].offsetTop === 10;
     el.remove();
   }
-});
 
-//Attach all behaviors.
-$(function () {
+  //Attach all behaviors.
   Drupal.attachBehaviors(document, Drupal.settings);
 });

You'll need to fire the scripts-ready event, too. It needs a patch for labjs.module. I'm really busy now, but I'll commit that code.

jcisio’s picture

Status: Patch (to be ported) » Fixed

Ok, finally get it done. It's be more reasonable to fix LABjs issue in LABjs module ;)

mikeytown2’s picture

Sadly that last commit just broke advagg's integration with LABjs. JS file replacement has to happen though advagg's hooks because it does not use core's aggregation. If I write a patch for this module would you accept it?

jcisio’s picture

Sure.

In this special case I think you'll patch LABjs so that if advagg is enabled, LABjs won't replace drupal.js, is it what you plan to do? Then in AdvAgg, use the drupal.modified.js instead ;)

mikeytown2’s picture

StatusFileSize
new3.45 KB

Looks like my editor took care of some white space issues for you as well.

mikeytown2’s picture

Status: Fixed » Needs review
mikeytown2’s picture

StatusFileSize
new4.35 KB

still learning git. Here's a patch on top of that one... well its all in one file. Forgot to rename the hook so its labjs

jcisio’s picture

Status: Needs review » Fixed

I'm learning Git, too. Thanks for the patch. Reviewed, tested and committed. I'll let you close #1082612: LABjs compatibility .

Status: Fixed » Closed (fixed)

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

socialnicheguru’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Closed (fixed) » Active

This is still an issue in D7 views 3 with labjs. I am using the dev version from 1-27-2012

jcisio’s picture

SocialNicheGuru, how to reproduce it? I tested with Views 3.1 with a few actions and I didn't have any problem.

iaugur’s picture

I get it with Views 7.x-3.3 - The collapsible groups fields don't work (in the popup for Display Suite settings). See #1237648: Accordion effects of the Overlay doesn't work in the views. for similar issue
It can be overcome with excluding the admin pages in Labjs configuration.

adamgerthel’s picture

I (think) I am having the same problem.

After activating Lab JS (tried latest release and latest dev), all javascript except $(document).ready stuff stops working. It doesn't seem to load at all. Firebug isn't showing any errors.

skein’s picture

Views Slideshow breaks for me if I enable LabJs. The view loads but no transition effects.

memoday’s picture

Issue summary: View changes

I am having the same issue here after 3-4 years from this post. Disabling labjs solved the issue. I don't even use advagg module. What is the real problem here and how should it be fixed?