Sha256: 7a22b065367434d384f093c79128418726a715484286305a24dd4dac65ad4ec4
Contents?: true
Size: 1.75 KB
Versions: 1
Compression:
Stored size: 1.75 KB
Contents
Spotlight.onLoad(function() { // Add Select/Deselect all button behavior addCheckboxToggleBehavior(); }); // Add Select/Deselect all button behavior function addCheckboxToggleBehavior() { $("[data-behavior='metadata-select']").each(function(){ var button = $(this) var parentCell = button.parents("th"); var table = parentCell.closest("table"); var columnRows = $("tr td:nth-child(" + (parentCell.index() + 1) + ")", table); var checkboxes = $("input[type='checkbox']", columnRows); swapSelectAllButtonText(button, columnRows); // Add the check/uncheck behavior to the button // and swap the button text if necessary button.on('click', function(e){ e.preventDefault(); var allChecked = allCheckboxesChecked(columnRows); columnRows.each(function(){ $("input[type='checkbox']", $(this)).prop('checked', !allChecked); swapSelectAllButtonText(button, columnRows); }); }); // Swap button text when a checkbox value changes checkboxes.each(function(){ $(this).on('change', function(){ swapSelectAllButtonText(button, columnRows); }); }); }); // Check number of checkboxes against the number of checked // checkboxes to determine if all of them are checked or not function allCheckboxesChecked(elements) { return ($("input[type='checkbox']", elements).length == $("input[type='checkbox']:checked", elements).length) } // Swap the button text to "Deselect all" // when all the checkboxes are checked and // "Select all" when any are unchecked function swapSelectAllButtonText(button, elements) { if ( allCheckboxesChecked(elements) ) { button.text(button.data('deselect-text')); } else { button.text(button.data('select-text')); } } }
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
blacklight-spotlight-0.4.1 | app/assets/javascripts/spotlight/blacklight_configuration.js |