(function($) {
$(document).ready(function() {
// 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 ) {
// if extra-class open do not collapse initially
if ( !$(elem).hasClass('open') ) {
$(elem).addClass("collapsed");
$(elem).find("h2").first().append(' (' + gettext("Show") +
')');
} else {
$(elem).find("h2").first().append(' (' + gettext("Hide") +
')');
}
}
});
hide = function() {
$(this).text(gettext("Show"));
$(this).closest("fieldset").addClass("collapsed");
return false;
};
show = function() {
$(this).text(gettext("Hide"));
$(this).closest("fieldset").removeClass("collapsed");
return false;
};
// Add close-toggle to anchor tag
$("fieldset.collapse:not(.open) a.collapse-toggle").toggle(
show,
hide
);
// Add open-toggle to anchor tag
$("fieldset.collapse.open a.collapse-toggle").toggle(
hide,
show
);
});
})(django.jQuery);