Changed admin/js/collapse.js to take advantage of jQuery chaining in three places. Should make for a slight performance boost.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17180 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2011-12-09 21:30:53 +00:00
parent ce247476af
commit 5c1c1a1254
2 changed files with 5 additions and 8 deletions

View File

@ -3,9 +3,8 @@
// Add anchor tag for Show/Hide link
$("fieldset.collapse").each(function(i, elem) {
// Don't hide if fields in this fieldset have errors
if ( $(elem).find("div.errors").length == 0 ) {
$(elem).addClass("collapsed");
$(elem).find("h2").first().append(' (<a id="fieldsetcollapser' +
if ($(elem).find("div.errors").length == 0) {
$(elem).addClass("collapsed").find("h2").first().append(' (<a id="fieldsetcollapser' +
i +'" class="collapse-toggle" href="#">' + gettext("Show") +
'</a>)');
}
@ -13,13 +12,11 @@
// Add toggle to anchor tag
$("fieldset.collapse a.collapse-toggle").toggle(
function() { // Show
$(this).text(gettext("Hide"));
$(this).closest("fieldset").removeClass("collapsed");
$(this).text(gettext("Hide")).closest("fieldset").removeClass("collapsed");
return false;
},
function() { // Hide
$(this).text(gettext("Show"));
$(this).closest("fieldset").addClass("collapsed");
$(this).text(gettext("Show")).closest("fieldset").addClass("collapsed");
return false;
}
);

View File

@ -1,2 +1,2 @@
(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");
(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").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")).closest("fieldset").removeClass("collapsed");return false},function(){a(this).text(gettext("Show")).closest("fieldset").addClass("collapsed");
return false})})})(django.jQuery);