views:

245

answers:

2

I have a complex bookmarklet that does many things, and rely
heavily on jQuery and some plugins (ui, easing, ect. )

Thing is, I don't know if jQuery or any other plugins are already
included in the current page, so I mustn't conflict them,
but also needs my files to be maintainable.

Do anyone have any ideas how to accomplish this?
some sort of Clousers perhaps?

it is VERY important that my appended jQuery.UI library won't collide with the page's ones.

A: 

Check the Documentation entry about this.

jQuery usually works nicely together with prototype and other libs that use the $ keyword.

Edit: Using the jQuery.noConflict() trick will prevent trouble with other libraries (prototype, mootools, etcetera).

You can always check if jQuery is already included before including it yourself:

<script language="javascript">
    if(!jQuery){
        document.write('<script type="text/javascript" src="/js/jQuery.js"></script>');
    }
</script>
Powertieke
and what about plugins conflicts with the page's own ones ?
vsync
Do you have an idea which the pages own ones could be? The procedures in the documentation are the only ones I know of to to prevent conflicts.One way to avoid collission is to try and put everything in function (as little global vars as possible), and if you use globals, make sure that they have an unique name (same with your function names).
Powertieke
How can I put all my plugins in a Closure if they are all in they're each .js file ? copy them to a huge un-maintainable Closure ?
vsync
A: 

The easiest way is to include this at the beginning of your bookmarklet:

$myjq = jQuery.noConflict();

For the rest of the program, use $myjq instead of just $, like so:

$myjq("#someId");
inkedmn
I know this, but this does not solve plug-ins conflicts..because they address jQuery and not the noConlict one
vsync