Skip to content

Instantly share code, notes, and snippets.

@rctay
Created July 11, 2010 11:39
Show Gist options
  • Save rctay/471483 to your computer and use it in GitHub Desktop.
Save rctay/471483 to your computer and use it in GitHub Desktop.
[django] uncollapse all collapsible fieldsets
/**
* Provides the function 'uncollapse_all' that expands/uncollapses all
* unexpanded/uncollapsed fieldsets.
*
* Known to work with django 1.2<=, <=1.3.0a0.
*/
django.jQuery(document).ready(function($) {
var e = $("fieldset.collapse a.collapse-toggle");
// obtain the jquery click handler that toggles the groups; we assume
// that the first handler is that
var fn = $.data(e[0]).events['click'][0].handler;
// if odd, the group is shown - trigger the handler to hide it.
var filter = function() {
return ($.data(this, "lastToggle"+fn.guid) || 0) % 2;
};
var handler = function() { $(this).trigger('click'); }
uncollapse_all = function() {
e.filter(filter).each(handler);
return false;
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment