I get this error on my console.

Uncaught TypeError: undefined is not a function

www.mysite.com/sites/all/modules/comment_goodness/comment_goodness.js?n7uccm:5

in firebug it says $(...).live is not a function

I'm using jQuery_update with jQuery 1.10.

I'm near to my production deadline, should I try the dev release?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

RgnYLDZ’s picture

I found out that .live() method is deprecated in jQuery 1.7.

Changin .live() with .on() in comment_goodness.js solved my problem.

I wrote this in case someone else get this error. But I don't know if it affects something else in the module.

RgnYLDZ’s picture

Status: Active » Needs review
RgnYLDZ’s picture

Title: Uncaught TypeError: undefined is not a function » .live() is not a function error
formatC'vt’s picture

formatC'vt’s picture

Status: Needs review » Reviewed & tested by the community
david_garcia’s picture

Works!!

formatC'vt’s picture

yes, works, but maintainers not works

  • 2ea0f5e committed on 7.x-1.x
    Issue #2294195 by formatC'vt | RgnYLDZ: Fixed .live() is not a function...
jessebeach’s picture

Status: Reviewed & tested by the community » Fixed

Thanks formatC'vt, RgnYLDZ and david_garcia!

jessebeach’s picture

Sorry, reverted then reapplied. Forgot the --author flag.

2ea0f5e..66f4827

  • formatC'vt authored 66f4827 on 7.x-1.x
    Issue #2294195 by formatC'vt | RgnYLDZ: Fixed .live() is not a function...
  • a45d79d committed on 7.x-1.x
    Revert "Issue #2294195 by formatC'vt | RgnYLDZ: Fixed .live() is not a...
Alan Evans’s picture

Status: Fixed » Needs work

Unfortunately, this patch causes an error similar to the one it intends to fix when using a bare Drupal 7 (jQuery 1.4.4).

Options:

  • make the next release depend on jquery update to at least 1.7
  • find a way to support both
Alan Evans’s picture

Simplest (cop-out) solution seems to be to support both for now. I have a working solution tested on D7 core only. Will re-test now with jquery_update 1.7+

formatC'vt’s picture

i create a patch for both, but i little confused, why we need this javascript code? for doing what?

formatC'vt’s picture

Status: Needs work » Needs review

i found why we need #1777802: Disable submit actions while the comment body is empty.
Anyway, my patch needs review =)

Alan Evans’s picture

Tested
- WYSIWYG comment area with jQuery 1.10 OK
- WYSIWYG comment area with jQuery 1.4 OK
- plain comment area with jQuery 1.4 OK
- plain comment area with jQuery 1.10 OK
- minimal testing on 1.5, 1.7 , 1.8 and 1.9 also seems ok

Will need a review/independent testing still.

Alan Evans’s picture

Gah ... just realised we were working on the same thing.

formatC'vt’s picture

Your patch tested more deeply than mine =)
why you doesn't use elements variable for jQuery >= 1.6?

Alan Evans’s picture

@formatC'vt : So, I had to make a couple of assumptions in trying to work out what this code was doing, as there are no useful comments in it. It seemed to me that the only possible thing it could be doing is handling WYSIWYG areas (because of the iframe reference on comment bodies), and I'm increasingly convinced that this is the case, following a bit of testing.

What I'm assuming is that the #states handling of disabling submit buttons doesn't work with WYSIWYGs, so this code was added to handle those. Further, if you try to attach the handling code directly in Drupal behaviors, the handler will fail to attach because the iframe is not yet present in the DOM. So I'm thinking at this point, the author of this code found a way to attach the event just a little later - by adding the mouseover handler to do the attaching. The assumption is that the user always has to click into the comment textarea before using it, and so the handler gets attached at that point. What the final handler seems to do is trigger a keyup() event in the underlying textarea whenever there is an edit in the WYSIWYG editor.

There is a flaw in the original code also in that it assumes you're navigating to the textarea using a mouse, so I'm adding "focus" to the handled events also to cover this.

Alan Evans’s picture

The reason for not using elements in >= 1.6 is that I need a slightly different selector to get on() to work correctly there - the iframe is not part of that first selector, because the iframe is not yet present in the DOM when that executes. However, the on() syntax allows you to filter down more specifically to the iframe at the point where the mouseover handler is invoked.

If I use the full selector (what's stored in the elements var), then I'll fail to attach the handler, as the iframe doesn't exist at this point of code execution.

There may still be a nicer way of writing this bit of code though.

apaderno’s picture

Version: 7.x-1.4 » 7.x-1.x-dev
Status: Needs review » Reviewed & tested by the community

The patch in comment #16 fixes the issue.

apaderno’s picture

Status: Reviewed & tested by the community » Needs work
+    // jQuery >= 1.6 can use this ...
+    if (typeof elements.on === 'function') {
+      $('form.comment-form div.field-name-comment-body div.text-format-wrapper').on('mouseover focus', 'iframe:not(.cgprocessed)', null, function() {
+        Drupal.behaviors.comment_goodness.handleEditors($(this));
+      })
+    }
+    // jQuery < 1.6
+    else if (typeof elements.live === 'function') {
+      elements.live('mouseover focus', function () {
+        Drupal.behaviors.comment_goodness.handleEditors($(this));
       });
+    }

Since Drupal 7 uses jQuery 1.4.4, the code should first verify live() exists.

Ursegol’s picture

Adjusted patch #16 for 7.x-1.4

apaderno’s picture

+    // Compatibility for Drupal 7 core (jQuery 1.4.4) and later versions. The
+    // live() function was removed in jQuery 1.9, but on() was only added in
+    // 1.6.
+    var elements = $('form.comment-form div.field-name-comment-body div.text-format-wrapper iframe:not(.cgprocessed)');
+    // jQuery >= 1.6 can use this ...
+    if (typeof elements.on === 'function') {
+      $('form.comment-form div.field-name-comment-body div.text-format-wrapper').on('mouseover focus', 'iframe:not(.cgprocessed)', null, function() {
+        Drupal.behaviors.comment_goodness.handleEditors($(this));
+      })
+    }
+    // jQuery < 1.6
+    else if (typeof elements.live === 'function') {
+      elements.live('mouseover focus', function () {
+        Drupal.behaviors.comment_goodness.handleEditors($(this));
       });
+    }
+  },

Since Drupal 7 uses jQuery 1.4.4 (< 1.6), the code should first check elements.live is a function, then check elements.on is a function, which is exactly the opposite of what the patch does.