From 8ffe945094c0fc50aa91225a778cbd43c195fd36 Mon Sep 17 00:00:00 2001
From: Harry Marr
Date: Fri, 18 Dec 2020 11:39:48 -0500
Subject: [PATCH] Add elementFilter option
---
example/example.js | 11 ++++++++
example/index.html | 1 +
src/element-overlay.ts | 1 +
src/element-picker.ts | 57 +++++++++++++++++++++++++++++-------------
4 files changed, 53 insertions(+), 17 deletions(-)
diff --git a/example/example.js b/example/example.js
index 540d611..28a57d0 100644
--- a/example/example.js
+++ b/example/example.js
@@ -3,6 +3,7 @@ import { ElementPicker } from "pick-dom-element";
function main() {
const status = document.getElementById("status");
const startButton = document.getElementById("start");
+ const onlyEmphasisCheckbox = document.getElementById("only-emphasis");
const setElement = (el) => {
const tags = [];
@@ -17,6 +18,10 @@ function main() {
};
const picker = new ElementPicker();
+ let onlyEmphasis = onlyEmphasisCheckbox.checked;
+ onlyEmphasisCheckbox.onchange = (ev) => {
+ onlyEmphasis = ev.target.checked;
+ }
const start = () => {
startButton.disabled = true;
picker.start({
@@ -25,6 +30,12 @@ function main() {
picker.stop();
startButton.disabled = false;
},
+ elementFilter: (el) => {
+ if (!onlyEmphasis) {
+ return true;
+ }
+ return ['I', 'B'].includes(el.tagName);
+ }
});
};
diff --git a/example/index.html b/example/index.html
index a58bf4b..e9e9d55 100644
--- a/example/index.html
+++ b/example/index.html
@@ -22,5 +22,6 @@ Element Picker example
Click "start" to activate the picker.
+