Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add jQuery closure for compatibility when using concurrent jQuery instances #6

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

totten
Copy link

@totten totten commented Nov 5, 2014

When a page includes 2+ copies of jQuery, the common pattern is:

<script type="text/javascript" src="jquery-1.8.js"></script>
<script type="text/javascript" src="plugin-1.js"></script>
<script type="text/javascript" src="plugin-2.js"></script>

<script type="text/javascript">
var jQuery_1_8 = $.noConflict(true);
</script>

<script type="text/javascript" src="jquery-1.9.js"></script>
<script type="text/javascript" src="plugin-3.js"></script>
<script type="text/javascript" src="plugin-4.js"></script>

In this example, plugin-1 is bound to jQuery 1.8 while plugin-3 is bound to
jQuery 1.9. This pattern only works reliably when plugin-*.js include
closures.

Without the closure, plugin-1.js is liable to skip around senselessly among
v1.8 and v1.9 (depending on the details of how it's coded).

…tances

When a page includes 2+ copies of jQuery, the common pattern is:

```
<script type="text/javascript" src="jquery-1.8.js"></script>
<script type="text/javascript" src="plugin-1.js"></script>
<script type="text/javascript" src="plugin-2.js"></script>

<script type="text/javascript">
var jQuery_1_8 = $.noConflict(true);
</script>

<script type="text/javascript" src="jquery-1.9.js"></script>
<script type="text/javascript" src="plugin-3.js"></script>
<script type="text/javascript" src="plugin-4.js"></script>
```

In this example, plugin-1 is bound to jQuery 1.8 while plugin-3 is bound to
jQuery 1.9.  This pattern only works reliably when plugin-*.js include
closures.

Without the closure, plugin-1.js is liable to skip around senselessly among
v1.8 and v1.9 (depending on the details of how it's coded).
@colemanw
Copy link

Agreed. Without closures you rely on $ being a global variable, which is not the case in many environments - not just when there are 2 copies of jQuery but anytime jQuery.noConflict() has been called, e.g. on any Drupal site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants