Skip to content

Commit

Permalink
fix: disallow nested data-checkswipe
Browse files Browse the repository at this point in the history
Handlers must be applied from bottom-up in order to get some effect of
nested groups that do not interact with each other. Even so, the CSS
enlarges all checkboxes, even if they "shouldn't"
  • Loading branch information
vladdeSV committed Jul 6, 2024
1 parent fbb3ed3 commit 5af0e5e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions checkswipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ function checkswipe(parent, checkbox) {
return
}

if (parent.parentElement?.closest('[data-checkswipe]') || parent.querySelector('[data-checkswipe]')) {
console.error('checkswipe: invalid structure for', parent,'; nested `data-checkswipe` elements are not allowed.')
return
}

if (!(checkbox instanceof HTMLInputElement) || checkbox.type !== 'checkbox') {
console.error('checkswipe: element', checkbox, `must be an html input element (type checkbox); is '${typeof checkbox}'.`)
return
Expand Down Expand Up @@ -86,6 +91,11 @@ function checkswipe(parent, checkbox) {
return
}

if (group.parentElement?.closest('[data-checkswipe]') || group.querySelector('[data-checkswipe]')) {
console.error('checkswipe: invalid structure for', group,'; nested `data-checkswipe` elements are not allowed.')
return
}

const hasSpecificCheckbox = group.querySelector('input[type=checkbox][data-checkswipe-use]') !== null
if (hasSpecificCheckbox && group.dataset.checkswipeSpecify === undefined) {
console.error('checkswipe: element', group, 'is missing attribute `data-checkswipe-specify`; has checkboxes with attribute `data-checkswipe-use`. this is not allowed.')
Expand Down

0 comments on commit 5af0e5e

Please sign in to comment.