views:

356

answers:

2

I'm working on a library which uses jQuery internally which work fine. But i don't want force the user to use my jQuery-Version just because he uses my library in his code.

So the question is, how can i use jQuery under a different name?

Is it sufficient to do something like this:

    var mylib.jQuery = {};  
    mylib.jQuery = jQuery.noConflict(true);

This will make jQquery available under mylib.jQuery and free the $-Symbol, but the original jQuery Symbol still works (which i think is not so good).

Peter

+1  A: 

You'd have to go into the source because window.jQuery is defined there, and just update the reference name.

This seems like an unreasonable request though.

Edit: Looks like all you have to do is set the reference 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'd have to do this right after you include the script though. My previous way did it directly in the script:

http://173.45.226.115/jquery.html

meder
thanks, but why is my request unreasonable?
rag
Well, noConflict is sufficient for most I suppose, hehe. but yeah I'd update all window. statements in the source code.
meder
updated after playing around a bit.
meder
thx for confirming my original thoughts.
rag
+1  A: 

By specifying true in the jQuery.noConflict(true);, it sets the noConflict to extreme mode and should make it so it won't conflict with any other library. It should be the first thing you define anywhere I'm guessing, so no jQuery code/plugin should appear before the var mylib.jQuery = jQuery.noConflict(true);

Jojo