Last active
September 19, 2020 16:43
-
-
Save mcaskill/df6e703178d81c813f2f4b01818a315c to your computer and use it in GitHub Desktop.
Revisions
-
mcaskill revised this gist
Sep 19, 2020 . No changes.There are no files selected for viewing
-
mcaskill created this gist
Sep 19, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ (function () { const table = document.getElementById('my-table'); let lastInput = null; table.addEventListener('click', function (event) { const currInput = event.target; if (currInput.type !== 'checkbox') { return; } if (event.shiftKey && lastInput !== null && lastInput !== currInput) { const inputs = table.querySelectorAll('input[type="checkbox"]'); lastInput.checked = currInput.checked; lastInput.dispatchEvent(new Event('change', { bubbles: true, cancelable: true })); let inBetween = false; inputs.forEach(function (input) { if (input === lastInput || input === currInput) { inBetween = !inBetween; } else if (inBetween) { input.checked = currInput.checked; input.dispatchEvent(new Event('change', { bubbles: true, cancelable: true })); } }); } lastInput = currInput; }, { passive: true }); })();