Skip to content

Replace element ids with custom attributes in the xfaLayer #15154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions src/display/xfa_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,28 +107,34 @@ class XfaLayer {
attributes.name = `${attributes.name}-${intent}`;
}
for (const [key, value] of Object.entries(attributes)) {
// We don't need to add dataId in the html object but it can
// be useful to know its value when writing printing tests:
// in this case, don't skip dataId to have its value.
if (value === null || value === undefined || key === "dataId") {
if (value === null || value === undefined) {
continue;
}

if (key !== "style") {
if (key === "textContent") {
html.textContent = value;
} else if (key === "class") {
switch (key) {
case "class":
if (value.length) {
html.setAttribute(key, value.join(" "));
}
} else {
if (isHTMLAnchorElement && (key === "href" || key === "newWindow")) {
continue; // Handled below.
break;
case "dataId":
// We don't need to add dataId in the html object but it can
// be useful to know its value when writing printing tests:
// in this case, don't skip dataId to have its value.
break;
case "id":
html.setAttribute("data-element-id", value);
break;
case "style":
Object.assign(html.style, value);
break;
case "textContent":
html.textContent = value;
break;
default:
if (!isHTMLAnchorElement || (key !== "href" && key !== "newWindow")) {
html.setAttribute(key, value);
}
html.setAttribute(key, value);
}
} else {
Object.assign(html.style, value);
}
}

Expand All @@ -140,8 +146,7 @@ class XfaLayer {
);
}

// Set the value after the others to be sure overwrite
// any other values.
// Set the value after the others to be sure to overwrite any other values.
if (storage && attributes.dataId) {
this.setupStorage(html, attributes.dataId, element, storage);
}
Expand Down