jQuery.noConflict for logged in users problem
Hello everyone,
is there some js guru who can help identify a possible issue with multiple jQuery instances please?
The problem (short version) is: (on a certain frontend controller-rendered view)
- load jquery-1.8.3.min.js
- load jquery.chosen plugin (
http://harvesthq.github.com/chosen/)
- init chosen
but when I'm logged in as admin (and the fuel edit bar is loaded together with jquery 1.5) the chosen plugin stops working, with an "method 'chosen' does not exist" error (which usually comes from jquery conflicts).
I've tried isolating both my script and /fuel/modules/fuel/js/edit_mode.js with a noConflict wrapper like so
(my script)
var jq18 = jQuery.noConflict;
(function($) {
..
}(jq18);
and
var jq15 = jQuery.noConflict;
(function($) {
..
}(jq15);
(also i've made sure this works by alerting the $().jquery version and it does indeed work)
but the problem still persits.
If i log out the plugin works again so I'm assuming the cause MUST be with the older jquery version conflict spawned by the fuel bar...
any clues?
thanks!
Comments
so it seems that the cause is indeed the older jquery version being included by inline_edit_bar.php. If i remove 'jquery/jquery' from the js() call chosen works again (and so does the inline editing bar, since jquery is being also loaded by my view (albeit v 1.8 )
Having said that, I've resorted to wrapping the whole jquery 1.5 within a
if (typeof jQuery == 'undefined') {
[jquery 1.5 source here ...]
}
But it's (w)hack-y! I wish there was a cleaner solution... ! cheers
jQuery.noConflict() method allows you to use multiple frameworks , while using jQuery. The noConflict() method releases the hold on the $ shortcut identifier, so that other scripts can use it. In jQuery's case, $ is just an alias for jQuery, so all functionality is available without using $. In case of multiple versions of jQuery are loaded (which is not recommended), calling $.noConflict(true) from the second version will return the globally scoped jQuery variables to those of the first version.