views:

90

answers:

4

I'm unable to remove prototype from a JSF framework (RichFaces 3.3.3). And if I try noConflict and try to take over $ it breaks my application framework because its tightly coupled with prototype.

So is there a way that I can do this:

jQuery(function() {
    /*
        some code that within this domready function 
        allows me to use $() within this function
        and not interfere with $ being used for prototype
        outside?
    */
});
+7  A: 

Yes, it's already passed in as the first parameter to your ready handler, just use:

jQuery(function($) { 
  $("selector").doSomething();
});
//$ is still prototype here
Nick Craver
+1  A: 

In general, you can write var $ = jQuery; to replace the $ symbol within a single function.

In your specific case, you can also use the first parameter of the callback.

SLaks
A: 

taking this link as a reference, you could do something like this:

jQuery(function($) { // like Nick Craver
});

and call the functions you need to have jQuery with:

var yourFunction = function(){
   var $ = this;
};

yourFunction.call(jQuery);

...

var yourFunction = (function($){

   return function() {

       // $ -> jQuery

   };

})(jQuery);

...

var yourFunction = (function(){

   var $ = this;

   return function() {

       // $ -> jQuery

   };

}).call(jQuery);
andres descalzo
A: 

The standard within my working group:

jQuery.noConflict();
(function ($) {
    //Do jQuery stuff using $ here.
})(jQuery);
//Do prototype stuff using $ here
Fordi