mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
JS -- Plug PageOpen and PageClose actions
This commit is contained in:
parent
ed3758f84d
commit
6523f8880b
5 changed files with 172 additions and 16 deletions
|
@ -1136,9 +1136,8 @@ class PDFPageProxy {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {GetAnnotationsParameters} params - Annotation parameters.
|
||||
* @returns {Promise<Array<any>>} A promise that is resolved with an
|
||||
* {Array} of the annotation objects.
|
||||
* @returns {Promise<Object>} A promise that is resolved with an
|
||||
* {Object} with JS actions.
|
||||
*/
|
||||
getJSActions() {
|
||||
if (!this._jsActionsPromise) {
|
||||
|
|
|
@ -91,6 +91,7 @@ class Doc extends PDFObject {
|
|||
this._zoom = data.zoom || 100;
|
||||
this._actions = createActionsMap(data.actions);
|
||||
this._globalEval = data.globalEval;
|
||||
this._pageActions = new Map();
|
||||
}
|
||||
|
||||
_dispatchDocEvent(name) {
|
||||
|
@ -114,22 +115,28 @@ class Doc extends PDFObject {
|
|||
}
|
||||
}
|
||||
|
||||
_dispatchPageEvent(name, action, pageNumber) {
|
||||
_dispatchPageEvent(name, actions, pageNumber) {
|
||||
if (name === "PageOpen") {
|
||||
if (!this._pageActions.has(pageNumber)) {
|
||||
this._pageActions.set(pageNumber, createActionsMap(actions));
|
||||
}
|
||||
this._pageNum = pageNumber - 1;
|
||||
}
|
||||
|
||||
this._globalEval(action);
|
||||
actions = this._pageActions.get(pageNumber)?.get(name);
|
||||
if (actions) {
|
||||
for (const action of actions) {
|
||||
this._globalEval(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_runActions(name) {
|
||||
if (!this._actions.has(name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const actions = this._actions.get(name);
|
||||
for (const action of actions) {
|
||||
this._globalEval(action);
|
||||
if (actions) {
|
||||
for (const action of actions) {
|
||||
this._globalEval(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -73,11 +73,10 @@ class EventDispatcher {
|
|||
}
|
||||
if (id === "doc") {
|
||||
this._document.obj._dispatchDocEvent(event.name);
|
||||
}
|
||||
if (id === "page") {
|
||||
} else if (id === "page") {
|
||||
this._document.obj._dispatchPageEvent(
|
||||
event.name,
|
||||
baseEvent.action,
|
||||
baseEvent.actions,
|
||||
baseEvent.pageNumber
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue