You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/snap-toolbox/src/DomTargeter/README.md
+43Lines changed: 43 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -202,6 +202,22 @@ Default: `false`
202
202
}
203
203
```
204
204
205
+
Note: Click listeners use the capture phase to ensure they fire even when frameworks call `stopPropagation()` on click events.
206
+
207
+
### `navigationRetarget`
208
+
When `true`, listens for SPA navigation events using the [Navigation API](https://developer.mozilla.org/en-US/docs/Web/API/Navigation_API) (`navigate` event). When a navigation occurs, the retargeting checker is restarted. This is useful for single-page applications that use `pushState` or `replaceState` for client-side routing.
209
+
210
+
Falls back gracefully in browsers that do not support the Navigation API.
211
+
212
+
Default: `false`
213
+
214
+
```js
215
+
{
216
+
selector:'#content',
217
+
navigationRetarget:true
218
+
}
219
+
```
220
+
205
221
### `unsetTargetMinHeight`
206
222
When `true`, removes any `min-height` CSS property from the target element after successful targeting. This is useful for removing placeholder styles.
207
223
@@ -259,6 +275,31 @@ Returns the array of targets specified during construction.
259
275
consttargets=contentTarget.getTargets();
260
276
```
261
277
278
+
### `getTargetedElems` method
279
+
Returns a read-only array of elements currently tracked by this DomTargeter instance. Automatically prunes disconnected elements before returning.
280
+
281
+
```js
282
+
constelems=contentTarget.getTargetedElems();
283
+
```
284
+
285
+
### `releaseTargets` method
286
+
Releases elements from both instance and global tracking, allowing them to be retargeted by other DomTargeter instances. Can release all tracked elements or a specific subset.
287
+
288
+
```js
289
+
// release all tracked elements
290
+
contentTarget.releaseTargets();
291
+
292
+
// release specific elements
293
+
contentTarget.releaseTargets([elem1, elem2]);
294
+
```
295
+
296
+
### `destroy` method
297
+
Fully cleans up the DomTargeter instance. Aborts all event listeners (click, navigation, DOMContentLoaded), releases all tracked elements, and removes any style blocks created by `hideTarget`.
298
+
299
+
```js
300
+
contentTarget.destroy();
301
+
```
302
+
262
303
## Complete Example
263
304
264
305
```js
@@ -272,6 +313,8 @@ const targeter = new DomTargeter(
0 commit comments