views:

60

answers:

1

I've been using Mootools 1.2.4 as my JS framework of choice. I've added Checkout by Amazon to one of my pages, and they inject jQuery 1.2.6 into the page and messes up my dollar function (among other things).

I have control over Mootools, but not jQuery. I would rather not rewrite my existing code to accomodate jQuery since Checkout by Amazon was an afterthought and plug-in element.

Any thoughts or suggestions are recommended. Thanks!

+2  A: 

Take a look at jQuery.noConflict(). If they've written their code correctly, it won't rely upon $ being available in the global scope.

For your own code, you could strengthen it against this sort of problem by wrapping all your code in a closure. I don't know what the full name of prototype's $ function is, but I'll assume it's Prototype:

alert ($ instanceof jQuery); // true

(function($) {
    alert ($ instanceof Prototype);   // true
    // put all your Prototype code here

})(Prototype);

edit: uhhh, replace "Prototype" with 'Mootools'... brain not working today

nickf
Thanks very much. The noConflict was just what I needed. As for the function encapsulation, I'll write my code to accomodate it. FYI the MooTools namespace is document.idThanks again!
Vic
you don't need to noConflict jquery if you namespace mootools (which won't touch $ if jquery has it automatically), only one of them really needs to stay off of $, not both at same time :)
Dimitar Christoff