Ticket #12882: 12882.3.diff

File 12882.3.diff, 11.0 KB (added by Jannis Leidel, 10 years ago)

Moved admin jQuery into our own namespace to lower the risk of clash with third party apps that use jQuery.

  • django/contrib/admin/helpers.py

    diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py
    index 52d0183..41c2c54 100644
    a b class Fieldset(object): 
    7676
    7777    def _media(self):
    7878        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])
    8081        return forms.Media()
    8182    media = property(_media)
    8283
  • django/contrib/admin/media/js/actions.js

    diff --git a/django/contrib/admin/media/js/actions.js b/django/contrib/admin/media/js/actions.js
    index 1c78cb1..67881bb 100644
    a b  
    108108                allToggle: "#action-toggle",
    109109                selectedClass: "selected"
    110110        }
    111 })(jQuery);
     111})(django.jQuery);
  • django/contrib/admin/media/js/actions.min.js

    diff --git a/django/contrib/admin/media/js/actions.min.js b/django/contrib/admin/media/js/actions.min.js
    index 2ff8224..39e5ba4 100644
    a b  
    22a(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);
    33updateCounter();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&&
    44a.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);
     5counterContainer:"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);
  • django/contrib/admin/media/js/collapse.js

    diff --git a/django/contrib/admin/media/js/collapse.js b/django/contrib/admin/media/js/collapse.js
    index a2a642b..0a1e2d8 100644
    a b  
    2424                        }
    2525                );
    2626        });
    27 })(jQuery);
     27})(django.jQuery);
  • django/contrib/admin/media/js/collapse.min.js

    diff --git a/django/contrib/admin/media/js/collapse.min.js b/django/contrib/admin/media/js/collapse.min.js
    index 21f1b8b..428984e 100644
    a b  
    11(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);
     2return false})})})(django.jQuery);
  • django/contrib/admin/media/js/inlines.js

    diff --git a/django/contrib/admin/media/js/inlines.js b/django/contrib/admin/media/js/inlines.js
    index 9decaae..20bb160 100644
    a b  
    145145                added: null,                                    // Function called each time a new form is added
    146146                removed: null                                   // Function called each time a form is deleted
    147147        }
    148 })(jQuery);
     148})(django.jQuery);
  • django/contrib/admin/media/js/inlines.min.js

    diff --git a/django/contrib/admin/media/js/inlines.min.js b/django/contrib/admin/media/js/inlines.min.js
    index 891cc3f..ba8e633 100644
    a b if(a(this).length&&g){var i;if(a(this).attr("tagName")=="TR"){g=this.eq(0).child 
    33j=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,
    44f))});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()!=""&&
    55h.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);
     6addText:"add another",deleteText:"remove",addCssClass:"add-row",deleteCssClass:"delete-row",emptyCssClass:"empty-row",formCssClass:"dynamic-form",added:null,removed:null}})(django.jQuery);
  • new file django/contrib/admin/media/js/jquery.init.js

    diff --git a/django/contrib/admin/media/js/jquery.init.js b/django/contrib/admin/media/js/jquery.init.js
    new file mode 100644
    index 0000000..85a7973
    - +  
     1// Puts the included jQuery into our own namespace
     2var django = {
     3    "jQuery": jQuery.noConflict(true)
     4};
  • django/contrib/admin/media/js/prepopulate.js

    diff --git a/django/contrib/admin/media/js/prepopulate.js b/django/contrib/admin/media/js/prepopulate.js
    index 27375d4..09483bb 100644
    a b  
    3131            dependencies.keyup(populate).change(populate).focus(populate);
    3232        });
    3333    };
    34 })(jQuery.noConflict());
     34})(django.jQuery);
  • django/contrib/admin/options.py

    diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
    index ae90bce..e46bd30 100644
    a b class ModelAdmin(BaseModelAdmin): 
    271271
    272272        js = ['js/core.js', 'js/admin/RelatedObjectLookups.js']
    273273        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'])
    275275        if self.prepopulated_fields:
    276276            js.append('js/urlify.js')
    277277            js.append('js/prepopulate.js')
    class InlineModelAdmin(BaseModelAdmin): 
    11991199
    12001200    def _media(self):
    12011201        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']
    12031203        if self.prepopulated_fields:
    12041204            js.append('js/urlify.js')
    12051205            js.append('js/prepopulate.js')
  • django/contrib/admin/templates/admin/change_list.html

    diff --git a/django/contrib/admin/templates/admin/change_list.html b/django/contrib/admin/templates/admin/change_list.html
    index 5593128..591044b 100644
    a b  
    99    {% url admin:jsi18n as jsi18nurl %}
    1010    <script type="text/javascript" src="{{ jsi18nurl|default:'../../jsi18n/' }}"></script>
    1111  {% endif %}
    12   {{ media }}
     12  {{ media.css }}
    1313  {% if not actions_on_top and not actions_on_bottom %}
    1414    <style>
    1515      #changelist table thead th:first-child {width: inherit}
     
    1919
    2020{% block extrahead %}
    2121{{ block.super }}
     22{{ media.js }}
    2223{% if action_form %}{% if actions_on_top or actions_on_bottom %}
    2324<script type="text/javascript">
    2425(function($) {
    2526    $(document).ready(function($) {
    2627        $("tr input.action-select").actions();
    2728    });
    28 })(jQuery.noConflict());
     29})(django.jQuery);
    2930</script>
    3031{% endif %}{% endif %}
    3132{% endblock %}
  • django/contrib/admin/templates/admin/edit_inline/stacked.html

    diff --git a/django/contrib/admin/templates/admin/edit_inline/stacked.html b/django/contrib/admin/templates/admin/edit_inline/stacked.html
    index 6eb4492..eb22a53 100644
    a b  
    7575            })
    7676        });
    7777    });
    78 })(jQuery.noConflict());
     78})(django.jQuery);
    7979</script>
  • django/contrib/admin/templates/admin/edit_inline/tabular.html

    diff --git a/django/contrib/admin/templates/admin/edit_inline/tabular.html b/django/contrib/admin/templates/admin/edit_inline/tabular.html
    index 48be38d..c68cc79 100644
    a b  
    121121            })
    122122        });
    123123    });
    124 })(jQuery.noConflict());
     124})(django.jQuery);
    125125</script>
  • django/contrib/admin/templates/admin/prepopulated_fields_js.html

    diff --git a/django/contrib/admin/templates/admin/prepopulated_fields_js.html b/django/contrib/admin/templates/admin/prepopulated_fields_js.html
    index f0eb471..4aa6380 100644
    a b  
    1919    $(field.id).data('dependency_list', field['dependency_list'])
    2020               .prepopulate($(field['dependency_ids'].join(',')), field.maxLength);
    2121{% endfor %}
    22 })(jQuery.noConflict());
     22})(django.jQuery);
    2323</script>
Back to Top