Add OpenAction destination support, off by default, to the viewer
Given that it's really not clear to me if this is actually desired functionality in the default viewer, and considering that it doesn't fit in *great* with the way that `PDFHistory` is initialized, this feature is currently off by default[1]. --- [1] It's controlled with the `disableOpenActionDestination` Preference/AppOption.
This commit is contained in:
parent
b05f053287
commit
a7e70a50f5
@ -117,6 +117,10 @@
|
||||
],
|
||||
"default": 0
|
||||
},
|
||||
"disableOpenActionDestination": {
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"disablePageLabels": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
|
17
web/app.js
17
web/app.js
@ -867,7 +867,9 @@ let PDFViewerApplication = {
|
||||
|
||||
// Since the `setInitialView` call below depends on this being resolved,
|
||||
// fetch it early to avoid delaying initial rendering of the PDF document.
|
||||
let pageModePromise = pdfDocument.getPageMode().catch(
|
||||
const pageModePromise = pdfDocument.getPageMode().catch(
|
||||
function() { /* Avoid breaking initial rendering; ignoring errors. */ });
|
||||
const openActionDestPromise = pdfDocument.getOpenActionDestination().catch(
|
||||
function() { /* Avoid breaking initial rendering; ignoring errors. */ });
|
||||
|
||||
this.toolbar.setPagesCount(pdfDocument.numPages, false);
|
||||
@ -923,8 +925,17 @@ let PDFViewerApplication = {
|
||||
}).catch(() => { /* Unable to read from storage; ignoring errors. */ });
|
||||
|
||||
Promise.all([
|
||||
storePromise, pageModePromise,
|
||||
]).then(async ([values = {}, pageMode]) => {
|
||||
storePromise, pageModePromise, openActionDestPromise,
|
||||
]).then(async ([values = {}, pageMode, openActionDest]) => {
|
||||
if (openActionDest && !this.initialBookmark &&
|
||||
!AppOptions.get('disableOpenActionDestination')) {
|
||||
// Always let the browser history/document hash take precedence.
|
||||
this.initialBookmark = JSON.stringify(openActionDest);
|
||||
// TODO: Re-factor the `PDFHistory` initialization to remove this hack
|
||||
// that's currently necessary to prevent weird initial history state.
|
||||
this.pdfHistory.push({ explicitDest: openActionDest,
|
||||
pageNumber: null, });
|
||||
}
|
||||
const initialBookmark = this.initialBookmark;
|
||||
// Initialize the default values, from user preferences.
|
||||
const zoom = AppOptions.get('defaultZoomValue');
|
||||
|
@ -48,6 +48,11 @@ const defaultOptions = {
|
||||
value: false,
|
||||
kind: OptionKind.VIEWER,
|
||||
},
|
||||
disableOpenActionDestination: {
|
||||
/** @type {boolean} */
|
||||
value: true,
|
||||
kind: OptionKind.VIEWER,
|
||||
},
|
||||
disablePageLabels: {
|
||||
/** @type {boolean} */
|
||||
value: false,
|
||||
|
@ -16,6 +16,7 @@
|
||||
"renderer": "canvas",
|
||||
"renderInteractiveForms": false,
|
||||
"enablePrintAutoRotate": false,
|
||||
"disableOpenActionDestination": true,
|
||||
"disablePageMode": false,
|
||||
"disablePageLabels": false,
|
||||
"scrollModeOnLoad": 0,
|
||||
|
@ -94,7 +94,7 @@ class IPDFHistory {
|
||||
/**
|
||||
* @param {Object} params
|
||||
*/
|
||||
push({ namedDest, explicitDest, pageNumber, }) {}
|
||||
push({ namedDest = null, explicitDest, pageNumber, }) {}
|
||||
|
||||
pushCurrentPosition() {}
|
||||
|
||||
|
@ -158,16 +158,27 @@ class PDFHistory {
|
||||
* Push an internal destination to the browser history.
|
||||
* @param {PushParameters}
|
||||
*/
|
||||
push({ namedDest, explicitDest, pageNumber, }) {
|
||||
push({ namedDest = null, explicitDest, pageNumber, }) {
|
||||
if (!this.initialized) {
|
||||
return;
|
||||
}
|
||||
if ((namedDest && typeof namedDest !== 'string') ||
|
||||
!Array.isArray(explicitDest) ||
|
||||
!(Number.isInteger(pageNumber) &&
|
||||
pageNumber > 0 && pageNumber <= this.linkService.pagesCount)) {
|
||||
console.error('PDFHistory.push: Invalid parameters.');
|
||||
if (namedDest && typeof namedDest !== 'string') {
|
||||
console.error('PDFHistory.push: ' +
|
||||
`"${namedDest}" is not a valid namedDest parameter.`);
|
||||
return;
|
||||
} else if (!Array.isArray(explicitDest)) {
|
||||
console.error('PDFHistory.push: ' +
|
||||
`"${explicitDest}" is not a valid explicitDest parameter.`);
|
||||
return;
|
||||
} else if (!(Number.isInteger(pageNumber) &&
|
||||
pageNumber > 0 && pageNumber <= this.linkService.pagesCount)) {
|
||||
// Allow an unset `pageNumber` if and only if the history is still empty;
|
||||
// please refer to the `this._destination.page = null;` comment above.
|
||||
if (pageNumber !== null || this._destination) {
|
||||
console.error('PDFHistory.push: ' +
|
||||
`"${pageNumber}" is not a valid pageNumber parameter.`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let hash = namedDest || JSON.stringify(explicitDest);
|
||||
|
Loading…
x
Reference in New Issue
Block a user