diff --git a/example/example.js b/example/example.js index c82bfe5..f00cee9 100644 --- a/example/example.js +++ b/example/example.js @@ -4,6 +4,7 @@ function main() { const status = document.getElementById("status"); const startButton = document.getElementById("start"); const onlyEmphasisCheckbox = document.getElementById("only-emphasis"); + const onlyParagraphsCheckbox = document.getElementById("only-paragraphs"); const setElement = (el) => { const tags = []; @@ -27,6 +28,10 @@ function main() { onlyEmphasisCheckbox.onchange = (ev) => { onlyEmphasis = ev.target.checked; } + let onlyParagraphs = onlyParagraphsCheckbox.checked; + onlyParagraphsCheckbox.onchange = (ev) => { + onlyParagraphs = ev.target.checked; + } const start = () => { startButton.disabled = true; picker.start({ @@ -36,10 +41,14 @@ function main() { startButton.disabled = false; }, elementFilter: (el) => { - if (!onlyEmphasis) { - return true; + if (onlyEmphasis) { + return ['I', 'B'].includes(el.tagName); + } + else if (onlyParagraphs) { + const paragraph = el.closest("p, h1") + return paragraph ?? false } - return ['I', 'B'].includes(el.tagName); + return true; } }); }; diff --git a/example/index.html b/example/index.html index c7a2b55..a179993 100644 --- a/example/index.html +++ b/example/index.html @@ -23,5 +23,6 @@