I'm trying to use certain jQuery plugins in my Django admin site.
Django admin sets the jQuery namespace to django.jQuery
(to avoid conflicts)
If I don't have the default $
namespace for jQuery, the plugins won't work, will they ?
Do I have to do something like
window.$ = django.jQuery
?
How & where can I change this namespace for the whole admin site ?
Actually, most plugins will require "jQuery" - not $ - to be available, and then provide $ themselves as in dmidz's answer.
Therefore, insert
var jQuery = django.jQuery;
before your external references. If you're loading a bunch of thirdparty jQuery plugins, put the above line in a script tag that preceeds the plugins.
See also my question five months ago How to provide $ to third-party, external jQuery plugins in Django admin
I suggest you to leave the jQuery in django.jQuery namespace wich is a good idea when using cms with different modules that could conflict. But you wrap your plugin within such :
;(function($){
// here $ is only in this scope and so totally inobrusive
// plugin code
})(django.jQuery);
Someone else had a similar problem and used the deconflict function: http://www.lokkju.com/blog/archives/143
I'm not sure what version Django uses, but I think the point of using the django namespace is that it can use its own version of jQuery for its internal operations, but still let you use a different version for your own work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With