Skip to content

Instantly share code, notes, and snippets.

@Jaesin
Last active August 29, 2015 14:11
Show Gist options
  • Save Jaesin/cef2ad9110658671eff5 to your computer and use it in GitHub Desktop.
Save Jaesin/cef2ad9110658671eff5 to your computer and use it in GitHub Desktop.
Add Select All on the drupal permissions page.
(function ($) {
var columns = $("#permissions tr.even").first().find("input.form-checkbox").length;
var heads = $("#permissions thead th");
for (var i=1; i<columns+1; i++) {
var cbToggler = $("<input type=checkbox>").data('column', i);
cbToggler.click(function(e) {
var checked = this.checked;
var allCheckboxes = $("#permissions tbody input.form-checkbox");
for (var n=$(this).data('column')-1; n<allCheckboxes.length; n+=columns) {
var chkbox = allCheckboxes.get(n);
chkbox.checked = checked;
}
});
heads.eq(i).append( $('<div class="checkbox-toggler"/>').append(cbToggler) );
}
// Also add hover toggling (The Jedi Effect)
$('input[type=checkbox]').mouseenter(function() {
$(this).attr('checked', (!$(this).attr('checked') ? 'checked' : false));
});
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment