I need a converter to make any jquery code/plugin to make with no.conflict mode?
or it's just possible with find and replace.
I need a converter to make any jquery code/plugin to make with no.conflict mode?
or it's just possible with find and replace.
As for the $
shortcut: if you place the code e.g. in a properly crafted anonymous function, you can still use it. Like:
(function ($, undefined) {
//Use $ shortcut for jQuery in this scope
$("input").val("clickme");
})(jQuery.noConflict());
The same works for the "extreme" variant of noConflict()
:
(function (jQuery, undefined) {
var $ = jQuery;
//Use jQuery and $ shortcut for jQuery in this scope
$("input").val("clickme");
})(jQuery.noConflict(true));
You would have to manually do this. There are no converters out there to do this automatically. The jQuery guide to authoring plugins specifically describes how plugins should bind to jQuery
as opposed to the $
specifically to ensure they remain working if jQuery.noConflict()
is called.
Basically it comes down to wrapping your code like this:
(function($) {
// jQuery can be used freely using
// the "$" within this code block
})(jQuery);
Keep in mind that this will remove any accidental (and some intentional) global variables from the global scope. To make variables global, assign them to the window
object, like this:
(function($) {
var myGlobalObj = "hello world";
window.myGlobalObj = myGlobalObj;
// Now "myGlobalObj" can be accessed globally
})(jQuery);