mikeyhill
mikeyhill

Reputation: 1

Jquery + Prototype conflict

I recently inherited a site which is botched in all sorts of ways. I'm more of a php guy and initially the js was working just fine. I made no changes to the javascript or the any of the include files but after making a few content edits I'm getting errors from firebug.

a.dispatchEvent is not a function
emptyFunction()protot...ects.js (line 2)
emptyFunction()protot...ects.js (line 2)
fireContentLoadedEvent()protot...ects.js (line 2)

[Break on this error] var Prototype={Version:'1.6.0.2',Brows...pe,Enumerable);Element.addMethods();
protot...ects.js (line 2)
this.m_eTarget.setStyle is not a function

[Break on this error] this.m_eTarget.setStyle( { position: 'relative', overflow:'hidden'} );
protot...ects.js (line 43)
uncaught exception: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE)" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: js/prototype_effects.js :: anonymous :: line 2" data: no]

Googling around I found several posts that sometimes jquery+prototype don't play well and rearranging the scripts could fix this issue, however being that I didn't touch these sections I'm not sure where I even need to begin to debug. The previous developer incorporated a head.inc file which loads up prototype, scriptaculous and then many of the pages are in a sub-template loading up jquery for functions like lightbox.

The site is temp housed at http://dawn.mikeyhill.com

Any help is appreciated.

Upvotes: 0

Views: 453

Answers (1)

Itay Maman
Itay Maman

Reputation: 30723

The prototype library is intrusive: it adds all sort of methods to core object of Javascript. When objects are then iterated over via for(var k in o) the iteration will include these new methods (because Javascript does not support, yet, non-iterable attributes). That's why in Prototype iteation is always performed via facilities such as each() that are immune to this problem.

The problem is with other code that is still using the good old "for-var-in" loops. This code will break. In 99% of the cases where Prototype does not work with some other library the problem is due to iteration.

You're saying that you didn't touch the code and I believe you so this leaves three options:

  • The problem was there before but you did not notice it
  • The problematic code is executed just in special cases (due to some special input). Previous programmer never tried this input.
  • You are in the 1% where the problem is due to some other factor :)

Upvotes: 1

Related Questions