How do I change the jQuery namespace?
I am working on a library that uses jQuery internally which works fine. But I don't want to force the user to use my version of jQuery just because they are using my library in their code.
So the question is, how can I use jQuery under a different name?
Is it enough to do something like this:
var mylib.jQuery = {};
mylib.jQuery = jQuery.noConflict(true);
This will make jQuery available under mylib.jQuery
and free the symbol $
, but the original symbol jQuery
still works (which I think is not that good).
source to share
You will need to go into the source code because window.jQuery is defined here and just update the link name.
This looks like an unfounded request.
Edit: It looks like all you have to do is set a link to $ .noConflict:
<script src="jquery.js"></script>
<script>
var foo = {};
foo.jQuery = jQuery.noConflict( true );
alert( typeof jQuery );
alert( typeof $ );
alert( typeof foo.jQuery );
</script>
You will need to do this right after including the script. My previous path did it directly in the script:
source to share
By jQuery.noConflict(true);
setting it to true , it sets the extreme mode to noConflict and should make sure it doesn't conflict with any other library. This should be the first thing you define anywhere I guess, so the jQuery / plugin code shouldn't appear beforevar mylib.jQuery = jQuery.noConflict(true);
source to share