Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #12882 - Moved the admin's jQuery into our own namespace to low…

…er the risk of a clash with third party apps that use jQuery.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12966 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 1fcf747b131308c5573de23858e6116f8630ee45 1 parent 35f4150
Jannis Leidel authored April 13, 2010
3  django/contrib/admin/helpers.py
@@ -76,7 +76,8 @@ def __init__(self, form, name=None, readonly_fields=(), fields=(), classes=(),
76 76
 
77 77
     def _media(self):
78 78
         if 'collapse' in self.classes:
79  
-            return forms.Media(js=['%sjs/collapse.min.js' % settings.ADMIN_MEDIA_PREFIX])
  79
+            js = ['js/jquery.min.js', 'js/jquery.init.js', 'js/collapse.min.js']
  80
+            return forms.Media(js=['%s%s' % (settings.ADMIN_MEDIA_PREFIX, url) for url in js])
80 81
         return forms.Media()
81 82
     media = property(_media)
82 83
 
2  django/contrib/admin/media/js/actions.js
@@ -108,4 +108,4 @@
108 108
 		allToggle: "#action-toggle",
109 109
 		selectedClass: "selected"
110 110
 	}
111  
-})(jQuery);
  111
+})(django.jQuery);
2  django/contrib/admin/media/js/actions.min.js
@@ -2,4 +2,4 @@
2 2
 a(b.allContainer).hide()};showClear=function(){a(b.acrossClears).show();a(b.acrossQuestions).hide();a(b.actionContainer).toggleClass(b.selectedClass);a(b.allContainer).show();a(b.counterContainer).hide()};reset=function(){a(b.acrossClears).hide();a(b.acrossQuestions).hide();a(b.allContainer).hide();a(b.counterContainer).show()};clearAcross=function(){reset();a(b.acrossInput).val(0);a(b.actionContainer).removeClass(b.selectedClass)};a(b.counterContainer).show();a(this).filter(":checked").each(function(){a(this).parent().parent().toggleClass(b.selectedClass);
3 3
 updateCounter();a(b.acrossInput).val()==1&&showClear()});a(b.allToggle).show().click(function(){checker(a(this).attr("checked"));updateCounter()});a("div.actions span.question a").click(function(c){c.preventDefault();a(b.acrossInput).val(1);showClear()});a("div.actions span.clear a").click(function(c){c.preventDefault();a(b.allToggle).attr("checked",false);clearAcross();checker(0);updateCounter()});lastChecked=null;a(e).click(function(c){if(!c)c=window.event;var d=c.target?c.target:c.srcElement;if(lastChecked&&
4 4
 a.data(lastChecked)!=a.data(d)&&c.shiftKey==true){var f=false;a(lastChecked).attr("checked",d.checked).parent().parent().toggleClass(b.selectedClass,d.checked);a(e).each(function(){if(a.data(this)==a.data(lastChecked)||a.data(this)==a.data(d))f=f?false:true;f&&a(this).attr("checked",d.checked).parent().parent().toggleClass(b.selectedClass,d.checked)})}a(d).parent().parent().toggleClass(b.selectedClass,d.checked);lastChecked=d;updateCounter()})};a.fn.actions.defaults={actionContainer:"div.actions",
5  
-counterContainer:"span.action-counter",allContainer:"div.actions span.all",acrossInput:"div.actions input.select-across",acrossQuestions:"div.actions span.question",acrossClears:"div.actions span.clear",allToggle:"#action-toggle",selectedClass:"selected"}})(jQuery);
  5
+counterContainer:"span.action-counter",allContainer:"div.actions span.all",acrossInput:"div.actions input.select-across",acrossQuestions:"div.actions span.question",acrossClears:"div.actions span.clear",allToggle:"#action-toggle",selectedClass:"selected"}})(django.jQuery);
2  django/contrib/admin/media/js/collapse.js
@@ -24,4 +24,4 @@
24 24
 			}
25 25
 		);
26 26
 	});
27  
-})(jQuery);
  27
+})(django.jQuery);
2  django/contrib/admin/media/js/collapse.min.js
... ...
@@ -1,2 +1,2 @@
1 1
 (function(a){a(document).ready(function(){a("fieldset.collapse").each(function(c,b){if(a(b).find("div.errors").length==0){a(b).addClass("collapsed");a(b).find("h2").first().append(' (<a id="fieldsetcollapser'+c+'" class="collapse-toggle" href="#">'+gettext("Show")+"</a>)")}});a("fieldset.collapse a.collapse-toggle").toggle(function(){a(this).text(gettext("Hide"));a(this).closest("fieldset").removeClass("collapsed");return false},function(){a(this).text(gettext("Show"));a(this).closest("fieldset").addClass("collapsed");
2  
-return false})})})(jQuery);
  2
+return false})})})(django.jQuery);
2  django/contrib/admin/media/js/inlines.js
@@ -145,4 +145,4 @@
145 145
 		added: null,					// Function called each time a new form is added
146 146
 		removed: null					// Function called each time a form is deleted
147 147
 	}
148  
-})(jQuery);
  148
+})(django.jQuery);
2  django/contrib/admin/media/js/inlines.min.js
@@ -3,4 +3,4 @@ if(a(this).length&&g){var i;if(a(this).attr("tagName")=="TR"){g=this.eq(0).child
3 3
 j=a("#"+b.prefix+"-empty"),d=j.clone(true);d.removeClass(b.emptyCssClass).addClass(b.formCssClass).attr("id",b.prefix+f).insertBefore(a(j));d.find("*").filter(function(){var c=a(this);return c.attr("id")&&c.attr("id").search(/__prefix__/)>=0}).each(function(){var c=a(this);c.attr("id",c.attr("id").replace(/__prefix__/g,f))}).end().filter(function(){var c=a(this);return c.attr("name")&&c.attr("name").search(/__prefix__/)>=0}).each(function(){var c=a(this);c.attr("name",c.attr("name").replace(/__prefix__/g,
4 4
 f))});if(d.is("tr"))d.children(":last").append('<div><a class="'+b.deleteCssClass+'" href="javascript:void(0)">'+b.deleteText+"</a></div>");else d.is("ul")||d.is("ol")?d.append('<li><a class="'+b.deleteCssClass+'" href="javascript:void(0)">'+b.deleteText+"</a></li>"):d.children(":first").append('<span><a class="'+b.deleteCssClass+'" href="javascript:void(0)">'+b.deleteText+"</a></span>");d.find("input,select,textarea,label,a").each(function(){l(this,b.prefix,e.val())});a(e).val(f+1);h.val()!=""&&
5 5
 h.val()<=e.val()&&i.parent().hide();d.find("a."+b.deleteCssClass).click(function(){var c=a(this).parents("."+b.formCssClass);c.remove();b.removed&&b.removed(c);c=a("."+b.formCssClass);a("#id_"+b.prefix+"-TOTAL_FORMS").val(c.length);if(h.val()==""||h.val()>=c.length)i.parent().show();for(var k=0,m=c.length;k<m;k++)a(c.get(k)).find("input,select,textarea,label,a").each(function(){l(this,b.prefix,k)});return false});b.added&&b.added(d);return false})}return this};a.fn.formset.defaults={prefix:"form",
6  
-addText:"add another",deleteText:"remove",addCssClass:"add-row",deleteCssClass:"delete-row",emptyCssClass:"empty-row",formCssClass:"dynamic-form",added:null,removed:null}})(jQuery);
  6
+addText:"add another",deleteText:"remove",addCssClass:"add-row",deleteCssClass:"delete-row",emptyCssClass:"empty-row",formCssClass:"dynamic-form",added:null,removed:null}})(django.jQuery);
4  django/contrib/admin/media/js/jquery.init.js
... ...
@@ -0,0 +1,4 @@
  1
+// Puts the included jQuery into our own namespace
  2
+var django = {
  3
+    "jQuery": jQuery.noConflict(true)
  4
+};
2  django/contrib/admin/media/js/prepopulate.js
@@ -31,4 +31,4 @@
31 31
             dependencies.keyup(populate).change(populate).focus(populate);
32 32
         });
33 33
     };
34  
-})(jQuery.noConflict());
  34
+})(django.jQuery);
4  django/contrib/admin/options.py
@@ -271,7 +271,7 @@ def _media(self):
271 271
 
272 272
         js = ['js/core.js', 'js/admin/RelatedObjectLookups.js']
273 273
         if self.actions is not None:
274  
-            js.extend(['js/jquery.min.js', 'js/actions.min.js'])
  274
+            js.extend(['js/jquery.min.js', 'js/jquery.init.js', 'js/actions.min.js'])
275 275
         if self.prepopulated_fields:
276 276
             js.append('js/urlify.js')
277 277
             js.append('js/prepopulate.js')
@@ -1199,7 +1199,7 @@ def __init__(self, parent_model, admin_site):
1199 1199
 
1200 1200
     def _media(self):
1201 1201
         from django.conf import settings
1202  
-        js = ['js/jquery.min.js', 'js/inlines.min.js']
  1202
+        js = ['js/jquery.min.js', 'js/jquery.init.js', 'js/inlines.min.js']
1203 1203
         if self.prepopulated_fields:
1204 1204
             js.append('js/urlify.js')
1205 1205
             js.append('js/prepopulate.js')
5  django/contrib/admin/templates/admin/change_list.html
@@ -9,7 +9,7 @@
9 9
     {% url admin:jsi18n as jsi18nurl %}
10 10
     <script type="text/javascript" src="{{ jsi18nurl|default:'../../jsi18n/' }}"></script>
11 11
   {% endif %}
12  
-  {{ media }}
  12
+  {{ media.css }}
13 13
   {% if not actions_on_top and not actions_on_bottom %}
14 14
     <style>
15 15
       #changelist table thead th:first-child {width: inherit}
@@ -19,13 +19,14 @@
19 19
 
20 20
 {% block extrahead %}
21 21
 {{ block.super }}
  22
+{{ media.js }}
22 23
 {% if action_form %}{% if actions_on_top or actions_on_bottom %}
23 24
 <script type="text/javascript">
24 25
 (function($) {
25 26
     $(document).ready(function($) {
26 27
         $("tr input.action-select").actions();
27 28
     });
28  
-})(jQuery.noConflict());
  29
+})(django.jQuery);
29 30
 </script>
30 31
 {% endif %}{% endif %}
31 32
 {% endblock %}
2  django/contrib/admin/templates/admin/edit_inline/stacked.html
@@ -75,5 +75,5 @@
75 75
             })
76 76
         });
77 77
     });
78  
-})(jQuery.noConflict());
  78
+})(django.jQuery);
79 79
 </script>
2  django/contrib/admin/templates/admin/edit_inline/tabular.html
@@ -121,5 +121,5 @@
121 121
             })
122 122
         });
123 123
     });
124  
-})(jQuery.noConflict());
  124
+})(django.jQuery);
125 125
 </script>
2  django/contrib/admin/templates/admin/prepopulated_fields_js.html
@@ -19,5 +19,5 @@
19 19
     $(field.id).data('dependency_list', field['dependency_list'])
20 20
                .prepopulate($(field['dependency_ids'].join(',')), field.maxLength);
21 21
 {% endfor %}
22  
-})(jQuery.noConflict());
  22
+})(django.jQuery);
23 23
 </script>

0 notes on commit 1fcf747

Please sign in to comment.
Something went wrong with that request. Please try again.