Home > Missing Answers > Drupal 5 and strange behavior of jQuery

Drupal 5 and strange behavior of jQuery

We have some jQuery code, that we use on all our company sites, however, this code did not work on Drupal sites. jQuery call to position() was returning “static” instead of expected object with top and left properties. We thought we should use newer jQuery (instead of 1.2.6), but this throwed “too much recursion” error in Firebug – which we tried to solve with patch from bug http://drupal.org/node/335741 . However, neither upgrade nor that patch really helped. The reason why position() did not work was hidden here: /sites/all/modules/jquery_update/compat.js (I was looking at linked files and this one sounded suspiciously).

And indeed, these helpers caused the problem:

// UPGRADE: The following css helpers should now be used as:
// .css("top") or .css("top","30px")
jQuery.each("top,left,position,float,overflow,color,background".split(","), function(i,n){
  jQuery.fn[ n ] = function(h) {
    return h == undefined ?
      ( this.length ? jQuery.css( this[0], n ) : null ) :
      this.css( n, h );
  };
});

We have replaced position with xposition and our jQuery works as expected even with version 1.2.6.

Categories: Missing Answers Tags: