mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-30 19:07:22 +02:00
Merge pull request #21653 from Snuffleupagus/jsActions-_getElementsByName-shorten
Shorten `Catalog.prototype.jsActions getter` and `AnnotationElement.prototype._getElementsByName` a tiny bit
This commit is contained in:
commit
0299cdcab9
@ -1241,13 +1241,9 @@ class Catalog {
|
||||
let javaScript = null;
|
||||
|
||||
function appendIfJavaScriptDict(name, jsDict) {
|
||||
if (!(jsDict instanceof Dict)) {
|
||||
if (!(jsDict instanceof Dict) || !isName(jsDict.get("S"), "JavaScript")) {
|
||||
return;
|
||||
}
|
||||
if (!isName(jsDict.get("S"), "JavaScript")) {
|
||||
return;
|
||||
}
|
||||
|
||||
let js = jsDict.get("JS");
|
||||
if (js instanceof BaseStream) {
|
||||
js = js.getString();
|
||||
@ -1260,7 +1256,7 @@ class Catalog {
|
||||
);
|
||||
// Skip empty entries, similar to the `_collectJS` function.
|
||||
if (js) {
|
||||
(javaScript ||= new Map()).set(name, js);
|
||||
(javaScript ??= new Map()).set(name, js);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1291,14 +1287,10 @@ class Catalog {
|
||||
);
|
||||
|
||||
if (javaScript) {
|
||||
actions ||= Object.create(null);
|
||||
actions ??= Object.create(null);
|
||||
|
||||
for (const [key, val] of javaScript) {
|
||||
if (key in actions) {
|
||||
actions[key].push(val);
|
||||
} else {
|
||||
actions[key] = [val];
|
||||
}
|
||||
(actions[key] ??= []).push(val);
|
||||
}
|
||||
}
|
||||
return shadow(this, "jsActions", actions);
|
||||
|
||||
@ -803,27 +803,24 @@ class AnnotationElement {
|
||||
const fields = [];
|
||||
|
||||
if (this._fieldObjects) {
|
||||
const fieldObj = this._fieldObjects[name];
|
||||
if (fieldObj) {
|
||||
for (const { page, id, exportValues } of fieldObj) {
|
||||
if (page === -1) {
|
||||
continue;
|
||||
}
|
||||
if (id === skipId) {
|
||||
continue;
|
||||
}
|
||||
const exportValue =
|
||||
typeof exportValues === "string" ? exportValues : null;
|
||||
const fieldObj = this._fieldObjects[name] || [];
|
||||
|
||||
const domElement = document.querySelector(
|
||||
`[data-element-id="${id}"]`
|
||||
);
|
||||
if (domElement && !GetElementsByNameSet.has(domElement)) {
|
||||
warn(`_getElementsByName - element not allowed: ${id}`);
|
||||
continue;
|
||||
}
|
||||
fields.push({ id, exportValue, domElement });
|
||||
for (const { page, id, exportValues } of fieldObj) {
|
||||
if (page === -1) {
|
||||
continue;
|
||||
}
|
||||
if (id === skipId) {
|
||||
continue;
|
||||
}
|
||||
const exportValue =
|
||||
typeof exportValues === "string" ? exportValues : null;
|
||||
|
||||
const domElement = document.querySelector(`[data-element-id="${id}"]`);
|
||||
if (domElement && !GetElementsByNameSet.has(domElement)) {
|
||||
warn(`_getElementsByName - element not allowed: ${id}`);
|
||||
continue;
|
||||
}
|
||||
fields.push({ id, exportValue, domElement });
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user