diff --git a/build/demo/index.mjs b/build/demo/index.mjs
index c46459d..3a07f91 100644
--- a/build/demo/index.mjs
+++ b/build/demo/index.mjs
@@ -17,7 +17,7 @@ import { processFragmentDirective } from "../vendor/treora-text-fragment/index.j
function copyPreContent(event) {
// Get the pre element containing the text to be copied
var preElement = event.target.nextSibling;
- while (preElement && preElement.nodeName !== 'PRE') {
+ while (preElement && preElement.nodeName !== 'pre') {
preElement = preElement.nextSibling;
}
if (!preElement)
@@ -40,7 +40,7 @@ preElements.forEach(function (preElement) {
// Create a button element
var button = document.createElement('button');
button.innerHTML = ' Copy';
- button.onclick = copyPreContent;
+ button.addEventListener('click', copyPreContent);
// Add the button just before the pre element
preElement.parentNode.insertBefore(button, preElement);
});
@@ -58,8 +58,7 @@ function createXPathSelectorMatcher(selector) {
return async function* matchAll(scope) {
const scopeRange = toRange(scope);
const document = ownerDocument(scopeRange);
- const scopeRangeElement = scopeRange.commonAncestorContainer;
- const element = nodeFromXPath(selector.value, scopeRangeElement);
+ const element = nodeFromXPath(selector.value);
console.log("XPath node found :", element);
if (!element)
throw new Error("XPath node not found !:");
@@ -196,10 +195,9 @@ const describeRangeXPathSelector = async (range) => {
if (!commonAncestorHTMLElement) {
return undefined;
}
- const source = document.getElementById("source");
return {
type: "XPathSelector",
- value: xpathFromNode(commonAncestorHTMLElement, source),
+ value: xpathFromNode(commonAncestorHTMLElement),
refinedBy: await describeTextPosition(rangeNormalize, commonAncestorHTMLElement),
};
};
@@ -408,5 +406,5 @@ const debounceInputChange = debounce(async (e) => {
}, 500);
inputTextArea.addEventListener("change", debounceInputChange);
const inputButton = document.getElementById("inputButton");
-inputButton.onclick = () => debounceInputChange();
-;
+inputButton.addEventListener("click", debounceInputChange);
+// inputButton.onclick = () => debounceInputChange();;
diff --git a/build/vendor/anchoring/xpath.js b/build/vendor/anchoring/xpath.js
index 0020d4c..789cf8f 100644
--- a/build/vendor/anchoring/xpath.js
+++ b/build/vendor/anchoring/xpath.js
@@ -31,7 +31,7 @@ function getPathSegment(node) {
* @param node - The node to generate a path to
* @param root - Root node to which the returned path is relative
*/
-export function xpathFromNode(node, root) {
+export function xpathFromNode(node, root = document.body) {
let xpath = '';
let elem = node;
while (elem !== root) {
diff --git a/demo/index.mts b/demo/index.mts
index dc3e32e..1a2b69a 100644
--- a/demo/index.mts
+++ b/demo/index.mts
@@ -37,7 +37,7 @@ interface TextFragmentSelector extends Selector {
function copyPreContent(event: any) {
// Get the pre element containing the text to be copied
var preElement = event.target.nextSibling;
- while (preElement && preElement.nodeName !== 'PRE') {
+ while (preElement && preElement.nodeName !== 'pre') {
preElement = preElement.nextSibling;
}
if (!preElement) return;
@@ -63,7 +63,7 @@ preElements.forEach(function (preElement) {
// Create a button element
var button = document.createElement('button');
button.innerHTML = ' Copy';
- button.onclick = copyPreContent;
+ button.addEventListener('click', copyPreContent);
// Add the button just before the pre element
preElement.parentNode!.insertBefore(button, preElement);
});
@@ -85,8 +85,7 @@ function createXPathSelectorMatcher(
return async function* matchAll(scope) {
const scopeRange = toRange(scope);
const document = ownerDocument(scopeRange);
- const scopeRangeElement = scopeRange.commonAncestorContainer as HTMLElement;
- const element = nodeFromXPath(selector.value, scopeRangeElement);
+ const element = nodeFromXPath(selector.value);
console.log("XPath node found :", element);
if (!element) throw new Error("XPath node not found !:");
const range = document.createRange();
@@ -261,10 +260,9 @@ const describeRangeXPathSelector = async (range: Range): Promise {
inputTextArea.addEventListener("change", debounceInputChange);
const inputButton = document.getElementById("inputButton") as HTMLElement;
+inputButton.addEventListener("click", debounceInputChange);
-
-inputButton.onclick = () => debounceInputChange();;
+// inputButton.onclick = () => debounceInputChange();;
diff --git a/vendor/anchoring/xpath.ts b/vendor/anchoring/xpath.ts
index 28886c7..fc1fcfd 100644
--- a/vendor/anchoring/xpath.ts
+++ b/vendor/anchoring/xpath.ts
@@ -34,7 +34,7 @@ function getPathSegment(node: Node): string {
* @param node - The node to generate a path to
* @param root - Root node to which the returned path is relative
*/
-export function xpathFromNode(node: Node, root: Node) {
+export function xpathFromNode(node: Node, root: Node = document.body) {
let xpath = '';
let elem: Node | null = node;
diff --git a/web/index.js b/web/index.js
index 5d7c3f0..bc01322 100644
--- a/web/index.js
+++ b/web/index.js
@@ -1674,7 +1674,7 @@ function getPathSegment(node) {
const pos = getNodePosition(node);
return `${name}[${pos}]`;
}
-function xpathFromNode(node, root) {
+function xpathFromNode(node, root = document.body) {
let xpath = "";
let elem = node;
while (elem !== root) {
@@ -2321,7 +2321,7 @@ function firstBoundaryPointAfter([node, offset]) {
// build/demo/index.mjs
function copyPreContent(event) {
var preElement = event.target.nextSibling;
- while (preElement && preElement.nodeName !== "PRE") {
+ while (preElement && preElement.nodeName !== "pre") {
preElement = preElement.nextSibling;
}
if (!preElement)
@@ -2337,7 +2337,7 @@ var preElements = document.body.querySelectorAll("pre");
preElements.forEach(function(preElement) {
var button = document.createElement("button");
button.innerHTML = ' Copy';
- button.onclick = copyPreContent;
+ button.addEventListener("click", copyPreContent);
preElement.parentNode.insertBefore(button, preElement);
});
function debounce(func, timeout) {
@@ -2353,8 +2353,7 @@ function createXPathSelectorMatcher(selector2) {
return async function* matchAll(scope) {
const scopeRange = toRange(scope);
const document2 = ownerDocument(scopeRange);
- const scopeRangeElement = scopeRange.commonAncestorContainer;
- const element = nodeFromXPath(selector2.value, scopeRangeElement);
+ const element = nodeFromXPath(selector2.value);
console.log("XPath node found :", element);
if (!element)
throw new Error("XPath node not found !:");
@@ -2474,10 +2473,9 @@ var describeRangeXPathSelector = async (range) => {
if (!commonAncestorHTMLElement) {
return void 0;
}
- const source = document.getElementById("source");
return {
type: "XPathSelector",
- value: xpathFromNode(commonAncestorHTMLElement, source),
+ value: xpathFromNode(commonAncestorHTMLElement),
refinedBy: await describeTextPosition2(rangeNormalize, commonAncestorHTMLElement)
};
};
@@ -2671,7 +2669,7 @@ var debounceInputChange = debounce(async (e) => {
}, 500);
inputTextArea.addEventListener("change", debounceInputChange);
var inputButton = document.getElementById("inputButton");
-inputButton.onclick = () => debounceInputChange();
+inputButton.addEventListener("click", debounceInputChange);
/**
* @license
* Licensed to the Apache Software Foundation (ASF) under one