1"use strict"; 2 3// Utility functions 4 5function nodeListToArray(nodeList) { 6 return Array.prototype.slice.call(nodeList); 7} 8 9function checks() { 10 return nodeListToArray( 11 document.querySelectorAll("[data-role=check]") 12 ); 13} 14 15function checkedValues(checkedInputs) { 16 return checkedInputs.map(function (i) { 17 return i.getAttribute('data-id'); 18 }); 19} 20 21// Receive an array of controls as argument and returns just the ones 22// with the checked attribute setted to true 23function checkedControls(controls) { 24 return controls.filter(function (control) { 25 return control.checked == true; 26 }); 27} 28 29(function ($) { 30 // When a checkbox is changed, the closest <tr> class is setted to 31 // active-row depending on the checkbox checked attribute 32 function toggleRowState(e) { 33 var checkbox = e.target, 34 $row = $(checkbox).closest("tr"); 35 36 if (checkbox.checked) { 37 $row.addClass("active-row"); 38 } else { 39 $row.removeClass("active-row"); 40 } 41 } 42 43 function check(checkbox, allCheckbox) { 44 var $row = $(checkbox).closest("tr"); 45 46 if (allCheckbox.checked) { 47 checkbox.checked = true; 48 $row.addClass("active-row"); 49 } else { 50 checkbox.checked = false; 51 $row.removeClass("active-row"); 52 } 53 } 54 55 // SIDE EFFECTS!! 56 $("[data-role=check]").on("change", toggleRowState); 57 58 $("[data-role=check-all]").on("change", function (e) { 59 var allCheckbox = e.target, 60 controls = checks(); 61 62 controls.forEach(function (control) { 63 check(control, allCheckbox); 64 }) 65 }); 66}(jQuery));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.