mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 17:55:37 +02:00
Merge pull request #12432 from calixteman/scripting_api
JS - Add the basic architecture to be able to execute embedded js
This commit is contained in:
commit
1eaf9c961b
18 changed files with 823 additions and 0 deletions
|
@ -468,6 +468,8 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
|
|||
element.setAttribute("value", textContent);
|
||||
}
|
||||
|
||||
element.setAttribute("id", id);
|
||||
|
||||
element.addEventListener("input", function (event) {
|
||||
storage.setValue(id, event.target.value);
|
||||
});
|
||||
|
@ -476,6 +478,35 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
|
|||
event.target.setSelectionRange(0, 0);
|
||||
});
|
||||
|
||||
if (this.data.actions) {
|
||||
element.addEventListener("updateFromSandbox", function (event) {
|
||||
const data = event.detail;
|
||||
if ("value" in data) {
|
||||
event.target.value = event.detail.value;
|
||||
} else if ("focus" in data) {
|
||||
event.target.focus({ preventScroll: false });
|
||||
}
|
||||
});
|
||||
|
||||
for (const eventType of Object.keys(this.data.actions)) {
|
||||
switch (eventType) {
|
||||
case "Format":
|
||||
element.addEventListener("blur", function (event) {
|
||||
window.dispatchEvent(
|
||||
new CustomEvent("dispatchEventInSandbox", {
|
||||
detail: {
|
||||
id,
|
||||
name: "Format",
|
||||
value: event.target.value,
|
||||
},
|
||||
})
|
||||
);
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
element.disabled = this.data.readOnly;
|
||||
element.name = this.data.fieldName;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue