budgit/assets/js/checkbox.min.js
2026-01-18 22:23:21 +00:00

1 line
1.3 KiB
JavaScript

(()=>{(function(){"use strict";function o(t){if(!t._tuiCheckbox){t._tuiCheckbox=!0;var e=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"checked");!e||!e.set||Object.defineProperty(t,"checked",{get:e.get,set:function(c){var n=e.get.call(this);e.set.call(this,c),n!==c&&this.dispatchEvent(new Event("change",{bubbles:!0}))},configurable:!0})}}function r(t){var e=document.querySelector('[data-tui-checkbox-group="'+t+'"][data-tui-checkbox-parent]'),c=document.querySelectorAll('[data-tui-checkbox-group="'+t+'"]:not([data-tui-checkbox-parent])');if(!(!e||!c.length)){var n=0;c.forEach(function(i){i.checked&&n++}),e.checked=n===c.length,e.indeterminate=n>0&&n<c.length}}function u(t,e){document.querySelectorAll('[data-tui-checkbox-group="'+t+'"]:not([data-tui-checkbox-parent])').forEach(function(c){c.checked=e})}document.addEventListener("change",function(t){var e=t.target;if(e.matches("[data-tui-checkbox-group]")){var c=e.getAttribute("data-tui-checkbox-group");e.hasAttribute("data-tui-checkbox-parent")?u(c,e.checked):r(c)}});function a(){var t=new Set;document.querySelectorAll("[data-tui-checkbox-group]").forEach(function(e){t.add(e.getAttribute("data-tui-checkbox-group")),o(e)}),t.forEach(r)}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",a):a()})();})();