Hi Rob,

On Feb 19, 11:58 am, Rob Hudson <r...@cogit8.org> wrote:
> On Fri, Feb 19, 2010 at 8:58 AM, Luke Plant <l.plant...@cantab.net> wrote:
> 1) Do we put jQuery in base.html and have Django's widgets and plugins
> assume it will be there?
>
> * Benefits: Javascript admin customizations are simpler and can use
> the jQuery already on the page.
> * Trade off: If someone wants to override base.html and put in
> mootools, e.g., Django's widgets break.

You can do this without breaking other javascript libraries or jQuery
versions by scoping Django's version of jQuery immediately after it is
included in base.html. An an example to illustrate:

If this is in the head:

<script type='text/javascript' src='django/jquery.js'></script>
<script type='text/javascript'>
  var $jQD = jQuery.noConflict();
</script>

And somebody else includes this:

<script type='text/javascript' src='someone-elses/jquery.js'></script>

Then Django's version of jQuery would be available to all widgets as
$jQD and the other jQuery version would still be available as $ or
jQuery. This would work whether the other jQuery include or any other
javascript library was included before or after the Django include.
The only possible problem is if someone's custom javascript happens to
use $jQD as a global variable. Using a unique enough variable name
would mitigate potential conflicts.


> 2) Or do we put jQuery in each widget's media setting and encapsulate
> both jQuery and the plugin code in a closure?  Which seems like where
> Django has been heading by default and the one I would advocate.
>
> * Benefit: Users can override base.html and add their own JS library
> of choice, even if it's jQuery for easy development or things outside
> of widgets.
> * Trade off: A bit trickier to develop admin widgets.  But perhaps
> this could be worked on -- something like jQuery UI's widget factory
> methods?

I agree that this makes a nice sandbox for the widgets. A second
advantage is that if a new widget was created it could use a new
version of jQuery, or even a different javascript library, without
interfering with anything else that exists. Whereas, if a global
Django admin jQuery is ever updated then the person who does it has to
test that all of the widgets depending upon it are still working.

Preston

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-develop...@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to