Skip to content
Merged
Show file tree
Hide file tree
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: 15 additions & 24 deletions js/workersrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,21 @@ function redirectIfNotDisplayedInFrame () {
}
redirectIfNotDisplayedInFrame();

// When "PDFViewerApplication.initialize" is executed it overwrites the value of
// "PDFJS.workerSrc", so the custom initialization has to be executed after
// that. As "PDFViewerApplication" does not provide any hookable point for
// custom initialization in its initialization routine a dirty hack has to be
// used.
//
// When "vendor/pdfjs/web/viewer.js" is parsed at the end it calls
// "PDFViewerApplication.initialize" (either directly or as a "DOMContentLoaded"
// event handler), and "PDFViewerApplication.initialize" sends an asynchronous
// XHR request to initialize the locales, which causes the execution flow to
// continue with the next script or the next "DOMContentLoaded" handler. Thanks
// to this "initializeCustomPDFViewerApplication" can be executed at that point
// by parsing "js/workersrc.js" after "vendor/pdfjs/web/viewer.js" and either
// calling it directly or adding it as a "DOMContentLoaded" event handler (using
// the same conditions as in "vendor/pdfjs/web/viewer.js").
// When "PDFViewerApplication.webViewerInitialized" is executed (once
// "PDFViewerApplication.initialize" is done) it opens the PDF file via URL,
// which requires the PDFViewerApplication to be properly configured, so the
// custom initialization has to be executed before that. This can be done by
// listening to the "webviewerloaded" event, which is emitted after
// "PDFViewerApplication" and "PDFViewerApplicationOptions" are globally set and
// before "PDFViewerApplication.initialize" is executed.
function initializeCustomPDFViewerApplication() {
PDFJS.openExternalLinksInNewWindow = true;
PDFJS.isEvalSupported = false;
PDFJS.workerSrc = document.getElementsByTagName('head')[0].getAttribute('data-workersrc');
PDFJS.cMapUrl = document.getElementsByTagName('head')[0].getAttribute('data-cmapurl');
// Preferences override options, so they must be disabled for
// "externalLinkTarget" to take effect.
PDFViewerApplicationOptions.set('disablePreferences', true);
PDFViewerApplicationOptions.set('externalLinkTarget', pdfjsLib.LinkTarget.BLANK);
PDFViewerApplicationOptions.set('isEvalSupported', false);
PDFViewerApplicationOptions.set('workerSrc', document.getElementsByTagName('head')[0].getAttribute('data-workersrc'));
PDFViewerApplicationOptions.set('cMapUrl', document.getElementsByTagName('head')[0].getAttribute('data-cmapurl'));

// The download has to be forced to use the URL of the file; by default
// "PDFViewerApplication.download" uses a blob, but this causes a CSP error
Expand Down Expand Up @@ -77,8 +72,4 @@ function initializeCustomPDFViewerApplication() {
};
}

if (document.readyState === 'interactive' || document.readyState === 'complete') {
initializeCustomPDFViewerApplication();
} else {
document.addEventListener('DOMContentLoaded', initializeCustomPDFViewerApplication, true);
}
document.addEventListener('webviewerloaded', initializeCustomPDFViewerApplication, true);
42 changes: 39 additions & 3 deletions templates/viewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

See https://github.com/adobe-type-tools/cmap-resources
-->
<html dir="ltr" mozdisallowselectionprint moznomarginboxes>
<html dir="ltr" mozdisallowselectionprint>
<head data-workersrc="<?php p($urlGenerator->linkTo('files_pdfviewer', 'vendor/pdfjs/build/pdf.worker.js')) ?>?v=<?php p($version) ?>"
data-cmapurl="<?php p($urlGenerator->linkTo('files_pdfviewer', 'vendor/pdfjs/web/cmaps/')) ?>">
<meta charset="utf-8">
Expand Down Expand Up @@ -74,6 +74,7 @@
<div id="attachmentsView" class="hidden">
</div>
</div>
<div id="sidebarResizer" class="hidden"></div>
</div> <!-- sidebarContainer -->

<div id="mainContainer">
Expand All @@ -91,11 +92,15 @@
</div>
</div>

<div id="findbarOptionsContainer">
<div id="findbarOptionsOneContainer">
<input type="checkbox" id="findHighlightAll" class="toolbarField" tabindex="94">
<label for="findHighlightAll" class="toolbarLabel" data-l10n-id="find_highlight">Highlight all</label>
<input type="checkbox" id="findMatchCase" class="toolbarField" tabindex="95">
<label for="findMatchCase" class="toolbarLabel" data-l10n-id="find_match_case_label">Match case</label>
</div>
<div id="findbarOptionsTwoContainer">
<input type="checkbox" id="findEntireWord" class="toolbarField" tabindex="96">
<label for="findEntireWord" class="toolbarLabel" data-l10n-id="find_entire_word_label">Whole words</label>
<span id="findResultsCount" class="toolbarLabel hidden"></span>
</div>

Expand Down Expand Up @@ -155,7 +160,31 @@

<div class="horizontalToolbarSeparator"></div>

<button id="documentProperties" class="secondaryToolbarButton documentProperties" title="Document Properties…" tabindex="62" data-l10n-id="document_properties">
<button id="scrollVertical" class="secondaryToolbarButton scrollModeButtons scrollVertical toggled" title="Use Vertical Scrolling" tabindex="62" data-l10n-id="scroll_vertical">
<span data-l10n-id="scroll_vertical_label">Vertical Scrolling</span>
</button>
<button id="scrollHorizontal" class="secondaryToolbarButton scrollModeButtons scrollHorizontal" title="Use Horizontal Scrolling" tabindex="63" data-l10n-id="scroll_horizontal">
<span data-l10n-id="scroll_horizontal_label">Horizontal Scrolling</span>
</button>
<button id="scrollWrapped" class="secondaryToolbarButton scrollModeButtons scrollWrapped" title="Use Wrapped Scrolling" tabindex="64" data-l10n-id="scroll_wrapped">
<span data-l10n-id="scroll_wrapped_label">Wrapped Scrolling</span>
</button>

<div class="horizontalToolbarSeparator scrollModeButtons"></div>

<button id="spreadNone" class="secondaryToolbarButton spreadModeButtons spreadNone toggled" title="Do not join page spreads" tabindex="65" data-l10n-id="spread_none">
<span data-l10n-id="spread_none_label">No Spreads</span>
</button>
<button id="spreadOdd" class="secondaryToolbarButton spreadModeButtons spreadOdd" title="Join page spreads starting with odd-numbered pages" tabindex="66" data-l10n-id="spread_odd">
<span data-l10n-id="spread_odd_label">Odd Spreads</span>
</button>
<button id="spreadEven" class="secondaryToolbarButton spreadModeButtons spreadEven" title="Join page spreads starting with even-numbered pages" tabindex="67" data-l10n-id="spread_even">
<span data-l10n-id="spread_even_label">Even Spreads</span>
</button>

<div class="horizontalToolbarSeparator spreadModeButtons"></div>

<button id="documentProperties" class="secondaryToolbarButton documentProperties" title="Document Properties…" tabindex="68" data-l10n-id="document_properties">
<span data-l10n-id="document_properties_label">Document Properties…</span>
</button>
</div>
Expand Down Expand Up @@ -342,6 +371,13 @@
<div class="row">
<span data-l10n-id="document_properties_page_count">Page Count:</span> <p id="pageCountField">-</p>
</div>
<div class="row">
<span data-l10n-id="document_properties_page_size">Page Size:</span> <p id="pageSizeField">-</p>
</div>
<div class="separator"></div>
<div class="row">
<span data-l10n-id="document_properties_linearized">Fast Web View:</span> <p id="linearizedField">-</p>
</div>
<div class="buttonRow">
<button id="documentPropertiesClose" class="overlayButton"><span data-l10n-id="document_properties_close">Close</span></button>
</div>
Expand Down
Loading