Last active
July 28, 2016 17:57
-
-
Save p34eu/7f9d06ed56ad7cb1aa20c7294ec675da to your computer and use it in GitHub Desktop.
This file contains 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 characters
/* | |
<a class="btn btn-link" data-checkall=".chst">check all</a> | |
<a class="btn btn-link" data-uncheckall=".chst">uncheck all</a> | |
*/ | |
var changeBoxesEvent = document.createEvent('HTMLEvents'); | |
changeBoxesEvent.initEvent('change', true, false); | |
var t = document.querySelectorAll('[data-uncheckall]'); | |
if (t) { | |
[].forEach.call(t, function (el) { | |
var targets = document.querySelectorAll(el.getAttribute('data-uncheckall')) || []; | |
if (targets.length) { | |
el.addEventListener('click', function () { | |
targets.forEach(function (target) { | |
if (!target.checked == false) { | |
target.checked = false; | |
target.dispatchEvent(changeBoxesEvent); | |
} | |
}); | |
}); | |
} | |
}); | |
} | |
var t = document.querySelectorAll('[data-checkall]'); | |
if (t) { | |
[].forEach.call(t, function (el) { | |
var targets = document.querySelectorAll(el.getAttribute('data-checkall')) || []; | |
if (targets.length) { | |
el.addEventListener('click', function () { | |
targets.forEach(function (target) { | |
if (!target.checked) { | |
target.checked = true; | |
target.dispatchEvent(changeBoxesEvent); | |
} | |
}); | |
}); | |
} | |
}); | |
} | |
delete(t); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment