v1.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. window.handleCheckboxGroupClick = function(event)
  2. {
  3. const $target = $(event.target);
  4. const $checkboxGroup = $target.closest('.checkbox-group');
  5. if($target.closest('.checkbox-title').length > 0)
  6. {
  7. const $checkboxTitle = $target.closest('.checkbox-title');
  8. $checkboxGroup
  9. .find('.checkbox-child')
  10. .prop('checked', $checkboxTitle.prop('checked'));
  11. return;
  12. }
  13. if($target.closest('.checkbox-child').length > 0)
  14. {
  15. let checkedCount = 0;
  16. const $checkboxChildren = $checkboxGroup.find('.checkbox-child');
  17. $checkboxChildren.each((_i, input) =>
  18. {
  19. if(input.checked === true) checkedCount++;
  20. });
  21. const checkboxTitle = $checkboxGroup.find('.checkbox-title')[0];
  22. if(checkedCount === 0)
  23. {
  24. checkboxTitle.checked = false;
  25. checkboxTitle.indeterminate = false;
  26. }
  27. else if(checkedCount === $checkboxChildren.length)
  28. {
  29. $checkboxGroup.find('.checkbox-title').prop('checked', true);
  30. checkboxTitle.checked = true;
  31. checkboxTitle.indeterminate = false;
  32. }
  33. else
  34. {
  35. checkboxTitle.checked = false;
  36. checkboxTitle.indeterminate = true;
  37. }
  38. }
  39. }