mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-21 15:48:06 +02:00
Replaces all preprocessor directives with PDFJSDev calls.
This commit is contained in:
parent
bf52ff156d
commit
0576c9c6c6
32 changed files with 1145 additions and 904 deletions
661
web/app.js
661
web/app.js
|
@ -105,17 +105,18 @@ var DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
|
|||
|
||||
function configure(PDFJS) {
|
||||
PDFJS.imageResourcesPath = './images/';
|
||||
//#if (FIREFOX || MOZCENTRAL || GENERIC || CHROME)
|
||||
//PDFJS.workerSrc = '../build/pdf.worker.js';
|
||||
//#endif
|
||||
//#if !PRODUCTION
|
||||
PDFJS.cMapUrl = '../external/bcmaps/';
|
||||
PDFJS.cMapPacked = true;
|
||||
PDFJS.workerSrc = '../src/worker_loader.js';
|
||||
//#else
|
||||
//PDFJS.cMapUrl = '../web/cmaps/';
|
||||
//PDFJS.cMapPacked = true;
|
||||
//#endif
|
||||
if (typeof PDFJSDev !== 'undefined' &&
|
||||
PDFJSDev.test('FIREFOX || MOZCENTRAL || GENERIC || CHROME')) {
|
||||
PDFJS.workerSrc = '../build/pdf.worker.js';
|
||||
}
|
||||
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
|
||||
PDFJS.cMapUrl = '../external/bcmaps/';
|
||||
PDFJS.cMapPacked = true;
|
||||
PDFJS.workerSrc = '../src/worker_loader.js';
|
||||
} else {
|
||||
PDFJS.cMapUrl = '../web/cmaps/';
|
||||
PDFJS.cMapPacked = true;
|
||||
}
|
||||
}
|
||||
|
||||
var DefaultExernalServices = {
|
||||
|
@ -437,21 +438,22 @@ var PDFViewerApplication = {
|
|||
},
|
||||
|
||||
get supportsFullscreen() {
|
||||
//#if MOZCENTRAL
|
||||
// var support = document.fullscreenEnabled === true ||
|
||||
// document.mozFullScreenEnabled === true;
|
||||
//#else
|
||||
var doc = document.documentElement;
|
||||
var support = !!(doc.requestFullscreen || doc.mozRequestFullScreen ||
|
||||
doc.webkitRequestFullScreen || doc.msRequestFullscreen);
|
||||
var support;
|
||||
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('MOZCENTRAL')) {
|
||||
support = document.fullscreenEnabled === true ||
|
||||
document.mozFullScreenEnabled === true;
|
||||
} else {
|
||||
var doc = document.documentElement;
|
||||
support = !!(doc.requestFullscreen || doc.mozRequestFullScreen ||
|
||||
doc.webkitRequestFullScreen || doc.msRequestFullscreen);
|
||||
|
||||
if (document.fullscreenEnabled === false ||
|
||||
document.mozFullScreenEnabled === false ||
|
||||
document.webkitFullscreenEnabled === false ||
|
||||
document.msFullscreenEnabled === false) {
|
||||
support = false;
|
||||
if (document.fullscreenEnabled === false ||
|
||||
document.mozFullScreenEnabled === false ||
|
||||
document.webkitFullscreenEnabled === false ||
|
||||
document.msFullscreenEnabled === false) {
|
||||
support = false;
|
||||
}
|
||||
}
|
||||
//#endif
|
||||
if (support && pdfjsLib.PDFJS.disableFullscreen === true) {
|
||||
support = false;
|
||||
}
|
||||
|
@ -481,39 +483,42 @@ var PDFViewerApplication = {
|
|||
return this.externalServices.supportedMouseWheelZoomModifierKeys;
|
||||
},
|
||||
|
||||
//#if (FIREFOX || MOZCENTRAL || CHROME)
|
||||
initPassiveLoading: function pdfViewInitPassiveLoading() {
|
||||
this.externalServices.initPassiveLoading({
|
||||
onOpenWithTransport: function (url, length, transport) {
|
||||
PDFViewerApplication.open(url, {range: transport});
|
||||
if (typeof PDFJSDev !== 'undefined' &&
|
||||
PDFJSDev.test('FIREFOX || MOZCENTRAL || CHROME')) {
|
||||
this.externalServices.initPassiveLoading({
|
||||
onOpenWithTransport: function (url, length, transport) {
|
||||
PDFViewerApplication.open(url, {range: transport});
|
||||
|
||||
if (length) {
|
||||
PDFViewerApplication.pdfDocumentProperties.setFileSize(length);
|
||||
if (length) {
|
||||
PDFViewerApplication.pdfDocumentProperties.setFileSize(length);
|
||||
}
|
||||
},
|
||||
onOpenWithData: function (data) {
|
||||
PDFViewerApplication.open(data);
|
||||
},
|
||||
onOpenWithURL: function (url, length, originalURL) {
|
||||
var file = url, args = null;
|
||||
if (length !== undefined) {
|
||||
args = {length: length};
|
||||
}
|
||||
if (originalURL !== undefined) {
|
||||
file = {file: url, originalURL: originalURL};
|
||||
}
|
||||
PDFViewerApplication.open(file, args);
|
||||
},
|
||||
onError: function (e) {
|
||||
PDFViewerApplication.error(mozL10n.get('loading_error', null,
|
||||
'An error occurred while loading the PDF.'), e);
|
||||
},
|
||||
onProgress: function (loaded, total) {
|
||||
PDFViewerApplication.progress(loaded / total);
|
||||
}
|
||||
},
|
||||
onOpenWithData: function (data) {
|
||||
PDFViewerApplication.open(data);
|
||||
},
|
||||
onOpenWithURL: function (url, length, originalURL) {
|
||||
var file = url, args = null;
|
||||
if (length !== undefined) {
|
||||
args = {length: length};
|
||||
}
|
||||
if (originalURL !== undefined) {
|
||||
file = {file: url, originalURL: originalURL};
|
||||
}
|
||||
PDFViewerApplication.open(file, args);
|
||||
},
|
||||
onError: function (e) {
|
||||
PDFViewerApplication.error(mozL10n.get('loading_error', null,
|
||||
'An error occurred while loading the PDF.'), e);
|
||||
},
|
||||
onProgress: function (loaded, total) {
|
||||
PDFViewerApplication.progress(loaded / total);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
throw new Error('Not implemented: initPassiveLoading');
|
||||
}
|
||||
},
|
||||
//#endif
|
||||
|
||||
setTitleUsingUrl: function pdfViewSetTitleUsingUrl(url) {
|
||||
this.url = url;
|
||||
|
@ -584,12 +589,11 @@ var PDFViewerApplication = {
|
|||
* is opened.
|
||||
*/
|
||||
open: function pdfViewOpen(file, args) {
|
||||
//#if GENERIC
|
||||
if (arguments.length > 2 || typeof args === 'number') {
|
||||
if ((typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) &&
|
||||
(arguments.length > 2 || typeof args === 'number')) {
|
||||
return Promise.reject(
|
||||
new Error('Call of open() with obsolete signature.'));
|
||||
}
|
||||
//#endif
|
||||
if (this.pdfLoadingTask) {
|
||||
// We need to destroy already opened document.
|
||||
return this.close().then(function () {
|
||||
|
@ -707,27 +711,23 @@ var PDFViewerApplication = {
|
|||
},
|
||||
|
||||
fallback: function pdfViewFallback(featureId) {
|
||||
//#if !PRODUCTION
|
||||
if (true) {
|
||||
return;
|
||||
if (typeof PDFJSDev !== 'undefined' &&
|
||||
PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
||||
// Only trigger the fallback once so we don't spam the user with messages
|
||||
// for one PDF.
|
||||
if (this.fellback) {
|
||||
return;
|
||||
}
|
||||
this.fellback = true;
|
||||
var url = this.url.split('#')[0];
|
||||
this.externalServices.fallback({ featureId: featureId, url: url },
|
||||
function response(download) {
|
||||
if (!download) {
|
||||
return;
|
||||
}
|
||||
PDFViewerApplication.download();
|
||||
});
|
||||
}
|
||||
//#endif
|
||||
//#if (FIREFOX || MOZCENTRAL)
|
||||
// Only trigger the fallback once so we don't spam the user with messages
|
||||
// for one PDF.
|
||||
if (this.fellback) {
|
||||
return;
|
||||
}
|
||||
this.fellback = true;
|
||||
var url = this.url.split('#')[0];
|
||||
this.externalServices.fallback({ featureId: featureId, url: url },
|
||||
function response(download) {
|
||||
if (!download) {
|
||||
return;
|
||||
}
|
||||
PDFViewerApplication.download();
|
||||
});
|
||||
//#endif
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -763,43 +763,44 @@ var PDFViewerApplication = {
|
|||
}
|
||||
}
|
||||
|
||||
//#if !(FIREFOX || MOZCENTRAL)
|
||||
var errorWrapperConfig = this.appConfig.errorWrapper;
|
||||
var errorWrapper = errorWrapperConfig.container;
|
||||
errorWrapper.removeAttribute('hidden');
|
||||
if (typeof PDFJSDev === 'undefined' ||
|
||||
!PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
||||
var errorWrapperConfig = this.appConfig.errorWrapper;
|
||||
var errorWrapper = errorWrapperConfig.container;
|
||||
errorWrapper.removeAttribute('hidden');
|
||||
|
||||
var errorMessage = errorWrapperConfig.errorMessage;
|
||||
errorMessage.textContent = message;
|
||||
var errorMessage = errorWrapperConfig.errorMessage;
|
||||
errorMessage.textContent = message;
|
||||
|
||||
var closeButton = errorWrapperConfig.closeButton;
|
||||
closeButton.onclick = function() {
|
||||
errorWrapper.setAttribute('hidden', 'true');
|
||||
};
|
||||
var closeButton = errorWrapperConfig.closeButton;
|
||||
closeButton.onclick = function() {
|
||||
errorWrapper.setAttribute('hidden', 'true');
|
||||
};
|
||||
|
||||
var errorMoreInfo = errorWrapperConfig.errorMoreInfo;
|
||||
var moreInfoButton = errorWrapperConfig.moreInfoButton;
|
||||
var lessInfoButton = errorWrapperConfig.lessInfoButton;
|
||||
moreInfoButton.onclick = function() {
|
||||
errorMoreInfo.removeAttribute('hidden');
|
||||
moreInfoButton.setAttribute('hidden', 'true');
|
||||
lessInfoButton.removeAttribute('hidden');
|
||||
errorMoreInfo.style.height = errorMoreInfo.scrollHeight + 'px';
|
||||
};
|
||||
lessInfoButton.onclick = function() {
|
||||
errorMoreInfo.setAttribute('hidden', 'true');
|
||||
var errorMoreInfo = errorWrapperConfig.errorMoreInfo;
|
||||
var moreInfoButton = errorWrapperConfig.moreInfoButton;
|
||||
var lessInfoButton = errorWrapperConfig.lessInfoButton;
|
||||
moreInfoButton.onclick = function() {
|
||||
errorMoreInfo.removeAttribute('hidden');
|
||||
moreInfoButton.setAttribute('hidden', 'true');
|
||||
lessInfoButton.removeAttribute('hidden');
|
||||
errorMoreInfo.style.height = errorMoreInfo.scrollHeight + 'px';
|
||||
};
|
||||
lessInfoButton.onclick = function() {
|
||||
errorMoreInfo.setAttribute('hidden', 'true');
|
||||
moreInfoButton.removeAttribute('hidden');
|
||||
lessInfoButton.setAttribute('hidden', 'true');
|
||||
};
|
||||
moreInfoButton.oncontextmenu = noContextMenuHandler;
|
||||
lessInfoButton.oncontextmenu = noContextMenuHandler;
|
||||
closeButton.oncontextmenu = noContextMenuHandler;
|
||||
moreInfoButton.removeAttribute('hidden');
|
||||
lessInfoButton.setAttribute('hidden', 'true');
|
||||
};
|
||||
moreInfoButton.oncontextmenu = noContextMenuHandler;
|
||||
lessInfoButton.oncontextmenu = noContextMenuHandler;
|
||||
closeButton.oncontextmenu = noContextMenuHandler;
|
||||
moreInfoButton.removeAttribute('hidden');
|
||||
lessInfoButton.setAttribute('hidden', 'true');
|
||||
errorMoreInfo.value = moreInfoText;
|
||||
//#else
|
||||
// console.error(message + '\n' + moreInfoText);
|
||||
// this.fallback();
|
||||
//#endif
|
||||
errorMoreInfo.value = moreInfoText;
|
||||
} else {
|
||||
console.error(message + '\n' + moreInfoText);
|
||||
this.fallback();
|
||||
}
|
||||
},
|
||||
|
||||
progress: function pdfViewProgress(level) {
|
||||
|
@ -851,15 +852,14 @@ var PDFViewerApplication = {
|
|||
var id = this.documentFingerprint = pdfDocument.fingerprint;
|
||||
var store = this.store = new ViewHistory(id);
|
||||
|
||||
//#if GENERIC
|
||||
var baseDocumentUrl = null;
|
||||
//#endif
|
||||
//#if (FIREFOX || MOZCENTRAL)
|
||||
// var baseDocumentUrl = this.url.split('#')[0];
|
||||
//#endif
|
||||
//#if CHROME
|
||||
// var baseDocumentUrl = location.href.split('#')[0];
|
||||
//#endif
|
||||
var baseDocumentUrl;
|
||||
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
||||
baseDocumentUrl = null;
|
||||
} else if (PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
||||
baseDocumentUrl = this.url.split('#')[0];
|
||||
} else if (PDFJSDev.test('CHROME')) {
|
||||
baseDocumentUrl = location.href.split('#')[0];
|
||||
}
|
||||
this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
|
||||
|
||||
var pdfViewer = this.pdfViewer;
|
||||
|
@ -1017,39 +1017,35 @@ var PDFViewerApplication = {
|
|||
self.fallback(pdfjsLib.UNSUPPORTED_FEATURES.forms);
|
||||
}
|
||||
|
||||
//#if !PRODUCTION
|
||||
if (true) {
|
||||
return;
|
||||
if (typeof PDFJSDev !== 'undefined' &&
|
||||
PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
||||
var versionId = String(info.PDFFormatVersion).slice(-1) | 0;
|
||||
var generatorId = 0;
|
||||
var KNOWN_GENERATORS = [
|
||||
'acrobat distiller', 'acrobat pdfwriter', 'adobe livecycle',
|
||||
'adobe pdf library', 'adobe photoshop', 'ghostscript', 'tcpdf',
|
||||
'cairo', 'dvipdfm', 'dvips', 'pdftex', 'pdfkit', 'itext', 'prince',
|
||||
'quarkxpress', 'mac os x', 'microsoft', 'openoffice', 'oracle',
|
||||
'luradocument', 'pdf-xchange', 'antenna house', 'aspose.cells', 'fpdf'
|
||||
];
|
||||
if (info.Producer) {
|
||||
KNOWN_GENERATORS.some(function (generator, s, i) {
|
||||
if (generator.indexOf(s) < 0) {
|
||||
return false;
|
||||
}
|
||||
generatorId = i + 1;
|
||||
return true;
|
||||
}.bind(null, info.Producer.toLowerCase()));
|
||||
}
|
||||
var formType = !info.IsAcroFormPresent ? null : info.IsXFAPresent ?
|
||||
'xfa' : 'acroform';
|
||||
self.externalServices.reportTelemetry({
|
||||
type: 'documentInfo',
|
||||
version: versionId,
|
||||
generator: generatorId,
|
||||
formType: formType
|
||||
});
|
||||
}
|
||||
//#endif
|
||||
//#if (FIREFOX || MOZCENTRAL)
|
||||
var versionId = String(info.PDFFormatVersion).slice(-1) | 0;
|
||||
var generatorId = 0;
|
||||
var KNOWN_GENERATORS = [
|
||||
'acrobat distiller', 'acrobat pdfwriter', 'adobe livecycle',
|
||||
'adobe pdf library', 'adobe photoshop', 'ghostscript', 'tcpdf',
|
||||
'cairo', 'dvipdfm', 'dvips', 'pdftex', 'pdfkit', 'itext', 'prince',
|
||||
'quarkxpress', 'mac os x', 'microsoft', 'openoffice', 'oracle',
|
||||
'luradocument', 'pdf-xchange', 'antenna house', 'aspose.cells', 'fpdf'
|
||||
];
|
||||
if (info.Producer) {
|
||||
KNOWN_GENERATORS.some(function (generator, s, i) {
|
||||
if (generator.indexOf(s) < 0) {
|
||||
return false;
|
||||
}
|
||||
generatorId = i + 1;
|
||||
return true;
|
||||
}.bind(null, info.Producer.toLowerCase()));
|
||||
}
|
||||
var formType = !info.IsAcroFormPresent ? null : info.IsXFAPresent ?
|
||||
'xfa' : 'acroform';
|
||||
self.externalServices.reportTelemetry({
|
||||
type: 'documentInfo',
|
||||
version: versionId,
|
||||
generator: generatorId,
|
||||
formType: formType
|
||||
});
|
||||
//#endif
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -1132,16 +1128,12 @@ var PDFViewerApplication = {
|
|||
|
||||
printService.layout();
|
||||
|
||||
//#if !PRODUCTION
|
||||
if (true) {
|
||||
return;
|
||||
if (typeof PDFJSDev !== 'undefined' &&
|
||||
PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
||||
this.externalServices.reportTelemetry({
|
||||
type: 'print'
|
||||
});
|
||||
}
|
||||
//#endif
|
||||
//#if (FIREFOX || MOZCENTRAL)
|
||||
this.externalServices.reportTelemetry({
|
||||
type: 'print'
|
||||
});
|
||||
//#endif
|
||||
},
|
||||
|
||||
// Whether all pages of the PDF have the same width and height.
|
||||
|
@ -1272,42 +1264,43 @@ var PDFViewerApplication = {
|
|||
eventBus.on('documentproperties', webViewerDocumentProperties);
|
||||
eventBus.on('find', webViewerFind);
|
||||
eventBus.on('findfromurlhash', webViewerFindFromUrlHash);
|
||||
//#if GENERIC
|
||||
eventBus.on('fileinputchange', webViewerFileInputChange);
|
||||
//#endif
|
||||
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
||||
eventBus.on('fileinputchange', webViewerFileInputChange);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//#if GENERIC
|
||||
var HOSTED_VIEWER_ORIGINS = ['null',
|
||||
'http://mozilla.github.io', 'https://mozilla.github.io'];
|
||||
function validateFileURL(file) {
|
||||
try {
|
||||
var viewerOrigin = new URL(window.location.href).origin || 'null';
|
||||
if (HOSTED_VIEWER_ORIGINS.indexOf(viewerOrigin) >= 0) {
|
||||
// Hosted or local viewer, allow for any file locations
|
||||
return;
|
||||
}
|
||||
var fileOrigin = new URL(file, window.location.href).origin;
|
||||
// Removing of the following line will not guarantee that the viewer will
|
||||
// start accepting URLs from foreign origin -- CORS headers on the remote
|
||||
// server must be properly configured.
|
||||
if (fileOrigin !== viewerOrigin) {
|
||||
throw new Error('file origin does not match viewer\'s');
|
||||
}
|
||||
} catch (e) {
|
||||
var message = e && e.message;
|
||||
var loadingErrorMessage = mozL10n.get('loading_error', null,
|
||||
'An error occurred while loading the PDF.');
|
||||
var validateFileURL;
|
||||
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
||||
var HOSTED_VIEWER_ORIGINS = ['null',
|
||||
'http://mozilla.github.io', 'https://mozilla.github.io'];
|
||||
validateFileURL = function validateFileURL(file) {
|
||||
try {
|
||||
var viewerOrigin = new URL(window.location.href).origin || 'null';
|
||||
if (HOSTED_VIEWER_ORIGINS.indexOf(viewerOrigin) >= 0) {
|
||||
// Hosted or local viewer, allow for any file locations
|
||||
return;
|
||||
}
|
||||
var fileOrigin = new URL(file, window.location.href).origin;
|
||||
// Removing of the following line will not guarantee that the viewer will
|
||||
// start accepting URLs from foreign origin -- CORS headers on the remote
|
||||
// server must be properly configured.
|
||||
if (fileOrigin !== viewerOrigin) {
|
||||
throw new Error('file origin does not match viewer\'s');
|
||||
}
|
||||
} catch (e) {
|
||||
var message = e && e.message;
|
||||
var loadingErrorMessage = mozL10n.get('loading_error', null,
|
||||
'An error occurred while loading the PDF.');
|
||||
|
||||
var moreInfo = {
|
||||
message: message
|
||||
};
|
||||
PDFViewerApplication.error(loadingErrorMessage, moreInfo);
|
||||
throw e;
|
||||
}
|
||||
var moreInfo = {
|
||||
message: message
|
||||
};
|
||||
PDFViewerApplication.error(loadingErrorMessage, moreInfo);
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
}
|
||||
//#endif
|
||||
|
||||
function loadAndEnablePDFBug(enabledTabs) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
@ -1328,48 +1321,44 @@ function loadAndEnablePDFBug(enabledTabs) {
|
|||
}
|
||||
|
||||
function webViewerInitialized() {
|
||||
//#if GENERIC
|
||||
var queryString = document.location.search.substring(1);
|
||||
var params = parseQueryString(queryString);
|
||||
var file = 'file' in params ? params.file : DEFAULT_URL;
|
||||
validateFileURL(file);
|
||||
//#endif
|
||||
//#if (FIREFOX || MOZCENTRAL)
|
||||
//var file = window.location.href.split('#')[0];
|
||||
//#endif
|
||||
//#if CHROME
|
||||
//var file = DEFAULT_URL;
|
||||
//#endif
|
||||
var file;
|
||||
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
||||
var queryString = document.location.search.substring(1);
|
||||
var params = parseQueryString(queryString);
|
||||
file = 'file' in params ? params.file : DEFAULT_URL;
|
||||
validateFileURL(file);
|
||||
} else if (PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
||||
file = window.location.href.split('#')[0];
|
||||
} else if (PDFJSDev.test('CHROME')) {
|
||||
file = DEFAULT_URL;
|
||||
}
|
||||
|
||||
var waitForBeforeOpening = [];
|
||||
var appConfig = PDFViewerApplication.appConfig;
|
||||
//#if GENERIC
|
||||
var fileInput = document.createElement('input');
|
||||
fileInput.id = appConfig.openFileInputName;
|
||||
fileInput.className = 'fileInput';
|
||||
fileInput.setAttribute('type', 'file');
|
||||
fileInput.oncontextmenu = noContextMenuHandler;
|
||||
document.body.appendChild(fileInput);
|
||||
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
||||
var fileInput = document.createElement('input');
|
||||
fileInput.id = appConfig.openFileInputName;
|
||||
fileInput.className = 'fileInput';
|
||||
fileInput.setAttribute('type', 'file');
|
||||
fileInput.oncontextmenu = noContextMenuHandler;
|
||||
document.body.appendChild(fileInput);
|
||||
|
||||
if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
|
||||
if (!window.File || !window.FileReader ||
|
||||
!window.FileList || !window.Blob) {
|
||||
appConfig.toolbar.openFile.setAttribute('hidden', 'true');
|
||||
appConfig.secondaryToolbar.openFileButton.setAttribute('hidden', 'true');
|
||||
} else {
|
||||
fileInput.value = null;
|
||||
}
|
||||
} else {
|
||||
appConfig.toolbar.openFile.setAttribute('hidden', 'true');
|
||||
appConfig.secondaryToolbar.openFileButton.setAttribute('hidden', 'true');
|
||||
} else {
|
||||
fileInput.value = null;
|
||||
}
|
||||
|
||||
//#else
|
||||
//appConfig.toolbar.openFile.setAttribute('hidden', 'true');
|
||||
//appConfig.secondaryToolbar.openFileButton.setAttribute('hidden', 'true');
|
||||
//#endif
|
||||
|
||||
var PDFJS = pdfjsLib.PDFJS;
|
||||
|
||||
//#if !PRODUCTION
|
||||
if (true) {
|
||||
//#else
|
||||
//if (PDFViewerApplication.preferencePdfBugEnabled) {
|
||||
//#endif
|
||||
if ((typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) ||
|
||||
PDFViewerApplication.preferencePdfBugEnabled) {
|
||||
// Special debugging flags in the hash section of the URL.
|
||||
var hash = document.location.hash.substring(1);
|
||||
var hashParams = parseQueryString(hash);
|
||||
|
@ -1405,17 +1394,18 @@ function webViewerInitialized() {
|
|||
PDFJS.ignoreCurrentPositionOnZoom =
|
||||
(hashParams['ignorecurrentpositiononzoom'] === 'true');
|
||||
}
|
||||
//#if !PRODUCTION
|
||||
if ('disablebcmaps' in hashParams && hashParams['disablebcmaps']) {
|
||||
PDFJS.cMapUrl = '../external/cmaps/';
|
||||
PDFJS.cMapPacked = false;
|
||||
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
|
||||
if ('disablebcmaps' in hashParams && hashParams['disablebcmaps']) {
|
||||
PDFJS.cMapUrl = '../external/cmaps/';
|
||||
PDFJS.cMapPacked = false;
|
||||
}
|
||||
}
|
||||
//#endif
|
||||
//#if !(FIREFOX || MOZCENTRAL)
|
||||
if ('locale' in hashParams) {
|
||||
PDFJS.locale = hashParams['locale'];
|
||||
if (typeof PDFJSDev === 'undefined' ||
|
||||
!PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
||||
if ('locale' in hashParams) {
|
||||
PDFJS.locale = hashParams['locale'];
|
||||
}
|
||||
}
|
||||
//#endif
|
||||
if ('textlayer' in hashParams) {
|
||||
switch (hashParams['textlayer']) {
|
||||
case 'off':
|
||||
|
@ -1437,16 +1427,16 @@ function webViewerInitialized() {
|
|||
}
|
||||
}
|
||||
|
||||
//#if !(FIREFOX || MOZCENTRAL)
|
||||
mozL10n.setLanguage(PDFJS.locale);
|
||||
//#endif
|
||||
//#if (FIREFOX || MOZCENTRAL)
|
||||
if (!PDFViewerApplication.supportsDocumentFonts) {
|
||||
PDFJS.disableFontFace = true;
|
||||
console.warn(mozL10n.get('web_fonts_disabled', null,
|
||||
'Web fonts are disabled: unable to use embedded PDF fonts.'));
|
||||
if (typeof PDFJSDev === 'undefined' ||
|
||||
!PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
||||
mozL10n.setLanguage(PDFJS.locale);
|
||||
} else {
|
||||
if (!PDFViewerApplication.supportsDocumentFonts) {
|
||||
PDFJS.disableFontFace = true;
|
||||
console.warn(mozL10n.get('web_fonts_disabled', null,
|
||||
'Web fonts are disabled: unable to use embedded PDF fonts.'));
|
||||
}
|
||||
}
|
||||
//#endif
|
||||
|
||||
if (!PDFViewerApplication.supportsPrinting) {
|
||||
appConfig.toolbar.print.classList.add('hidden');
|
||||
|
@ -1539,44 +1529,45 @@ function webViewerInitialized() {
|
|||
});
|
||||
}
|
||||
|
||||
//#if GENERIC
|
||||
function webViewerOpenFileViaURL(file) {
|
||||
if (file && file.lastIndexOf('file:', 0) === 0) {
|
||||
// file:-scheme. Load the contents in the main thread because QtWebKit
|
||||
// cannot load file:-URLs in a Web Worker. file:-URLs are usually loaded
|
||||
// very quickly, so there is no need to set up progress event listeners.
|
||||
PDFViewerApplication.setTitleUsingUrl(file);
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onload = function() {
|
||||
PDFViewerApplication.open(new Uint8Array(xhr.response));
|
||||
};
|
||||
try {
|
||||
xhr.open('GET', file);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
xhr.send();
|
||||
} catch (e) {
|
||||
PDFViewerApplication.error(mozL10n.get('loading_error', null,
|
||||
'An error occurred while loading the PDF.'), e);
|
||||
var webViewerOpenFileViaURL;
|
||||
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
||||
webViewerOpenFileViaURL = function webViewerOpenFileViaURL(file) {
|
||||
if (file && file.lastIndexOf('file:', 0) === 0) {
|
||||
// file:-scheme. Load the contents in the main thread because QtWebKit
|
||||
// cannot load file:-URLs in a Web Worker. file:-URLs are usually loaded
|
||||
// very quickly, so there is no need to set up progress event listeners.
|
||||
PDFViewerApplication.setTitleUsingUrl(file);
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onload = function() {
|
||||
PDFViewerApplication.open(new Uint8Array(xhr.response));
|
||||
};
|
||||
try {
|
||||
xhr.open('GET', file);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
xhr.send();
|
||||
} catch (e) {
|
||||
PDFViewerApplication.error(mozL10n.get('loading_error', null,
|
||||
'An error occurred while loading the PDF.'), e);
|
||||
}
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (file) {
|
||||
PDFViewerApplication.open(file);
|
||||
}
|
||||
if (file) {
|
||||
PDFViewerApplication.open(file);
|
||||
}
|
||||
};
|
||||
} else if (PDFJSDev.test('FIREFOX || MOZCENTRAL || CHROME')) {
|
||||
webViewerOpenFileViaURL = function webViewerOpenFileViaURL(file) {
|
||||
PDFViewerApplication.setTitleUsingUrl(file);
|
||||
PDFViewerApplication.initPassiveLoading();
|
||||
};
|
||||
} else {
|
||||
webViewerOpenFileViaURL = function webViewerOpenFileURL(file) {
|
||||
if (file) {
|
||||
throw new Error('Not implemented: webViewerOpenFileURL');
|
||||
}
|
||||
};
|
||||
}
|
||||
//#elif (FIREFOX || MOZCENTRAL || CHROME)
|
||||
//function webViewerOpenFileViaURL(file) {
|
||||
// PDFViewerApplication.setTitleUsingUrl(file);
|
||||
// PDFViewerApplication.initPassiveLoading();
|
||||
//}
|
||||
//#else
|
||||
//function webViewerOpenFileURL(file) {
|
||||
// if (file) {
|
||||
// throw new Error('Not implemented: webViewerOpenFileURL');
|
||||
// }
|
||||
//}
|
||||
//#endif
|
||||
|
||||
function webViewerPageRendered(e) {
|
||||
var pageNumber = e.pageNumber;
|
||||
|
@ -1612,40 +1603,31 @@ function webViewerPageRendered(e) {
|
|||
'An error occurred while rendering the page.'), pageView.error);
|
||||
}
|
||||
|
||||
//#if !PRODUCTION
|
||||
if (true) {
|
||||
return;
|
||||
}
|
||||
//#endif
|
||||
//#if (FIREFOX || MOZCENTRAL)
|
||||
PDFViewerApplication.externalServices.reportTelemetry({
|
||||
type: 'pageInfo'
|
||||
});
|
||||
// It is a good time to report stream and font types.
|
||||
PDFViewerApplication.pdfDocument.getStats().then(function (stats) {
|
||||
if (typeof PDFJSDev !== 'undefined' &&
|
||||
PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
||||
PDFViewerApplication.externalServices.reportTelemetry({
|
||||
type: 'documentStats',
|
||||
stats: stats
|
||||
type: 'pageInfo'
|
||||
});
|
||||
});
|
||||
//#endif
|
||||
// It is a good time to report stream and font types.
|
||||
PDFViewerApplication.pdfDocument.getStats().then(function (stats) {
|
||||
PDFViewerApplication.externalServices.reportTelemetry({
|
||||
type: 'documentStats',
|
||||
stats: stats
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function webViewerTextLayerRendered(e) {
|
||||
//#if !PRODUCTION
|
||||
if (true) {
|
||||
return;
|
||||
}
|
||||
//#endif
|
||||
//#if (FIREFOX || MOZCENTRAL)
|
||||
if (e.numTextDivs > 0 && !PDFViewerApplication.supportsDocumentColors) {
|
||||
if (typeof PDFJSDev !== 'undefined' &&
|
||||
PDFJSDev.test('FIREFOX || MOZCENTRAL') &&
|
||||
e.numTextDivs > 0 && !PDFViewerApplication.supportsDocumentColors) {
|
||||
console.error(mozL10n.get('document_colors_not_allowed', null,
|
||||
'PDF documents are not allowed to use their own colors: ' +
|
||||
'\'Allow pages to choose their own colors\' ' +
|
||||
'is deactivated in the browser.'));
|
||||
PDFViewerApplication.fallback();
|
||||
}
|
||||
//#endif
|
||||
}
|
||||
|
||||
function webViewerPageMode(e) {
|
||||
|
@ -1803,43 +1785,45 @@ function webViewerHashchange(e) {
|
|||
}
|
||||
}
|
||||
|
||||
//#if GENERIC
|
||||
window.addEventListener('change', function webViewerChange(evt) {
|
||||
var files = evt.target.files;
|
||||
if (!files || files.length === 0) {
|
||||
return;
|
||||
}
|
||||
PDFViewerApplication.eventBus.dispatch('fileinputchange',
|
||||
{fileInput: evt.target});
|
||||
}, true);
|
||||
var webViewerFileInputChange;
|
||||
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
||||
window.addEventListener('change', function webViewerChange(evt) {
|
||||
var files = evt.target.files;
|
||||
if (!files || files.length === 0) {
|
||||
return;
|
||||
}
|
||||
PDFViewerApplication.eventBus.dispatch('fileinputchange',
|
||||
{fileInput: evt.target});
|
||||
}, true);
|
||||
|
||||
function webViewerFileInputChange(e) {
|
||||
var file = e.fileInput.files[0];
|
||||
webViewerFileInputChange = function webViewerFileInputChange(e) {
|
||||
var file = e.fileInput.files[0];
|
||||
|
||||
if (!pdfjsLib.PDFJS.disableCreateObjectURL &&
|
||||
typeof URL !== 'undefined' && URL.createObjectURL) {
|
||||
PDFViewerApplication.open(URL.createObjectURL(file));
|
||||
} else {
|
||||
// Read the local file into a Uint8Array.
|
||||
var fileReader = new FileReader();
|
||||
fileReader.onload = function webViewerChangeFileReaderOnload(evt) {
|
||||
var buffer = evt.target.result;
|
||||
var uint8Array = new Uint8Array(buffer);
|
||||
PDFViewerApplication.open(uint8Array);
|
||||
};
|
||||
fileReader.readAsArrayBuffer(file);
|
||||
}
|
||||
if (!pdfjsLib.PDFJS.disableCreateObjectURL &&
|
||||
typeof URL !== 'undefined' && URL.createObjectURL) {
|
||||
PDFViewerApplication.open(URL.createObjectURL(file));
|
||||
} else {
|
||||
// Read the local file into a Uint8Array.
|
||||
var fileReader = new FileReader();
|
||||
fileReader.onload = function webViewerChangeFileReaderOnload(evt) {
|
||||
var buffer = evt.target.result;
|
||||
var uint8Array = new Uint8Array(buffer);
|
||||
PDFViewerApplication.open(uint8Array);
|
||||
};
|
||||
fileReader.readAsArrayBuffer(file);
|
||||
}
|
||||
|
||||
PDFViewerApplication.setTitleUsingUrl(file.name);
|
||||
PDFViewerApplication.setTitleUsingUrl(file.name);
|
||||
|
||||
// URL does not reflect proper document location - hiding some icons.
|
||||
var appConfig = PDFViewerApplication.appConfig;
|
||||
appConfig.toolbar.viewBookmark.setAttribute('hidden', 'true');
|
||||
appConfig.secondaryToolbar.viewBookmarkButton.setAttribute('hidden', 'true');
|
||||
appConfig.toolbar.download.setAttribute('hidden', 'true');
|
||||
appConfig.secondaryToolbar.downloadButton.setAttribute('hidden', 'true');
|
||||
// URL does not reflect proper document location - hiding some icons.
|
||||
var appConfig = PDFViewerApplication.appConfig;
|
||||
appConfig.toolbar.viewBookmark.setAttribute('hidden', 'true');
|
||||
appConfig.secondaryToolbar.viewBookmarkButton.setAttribute('hidden',
|
||||
'true');
|
||||
appConfig.toolbar.download.setAttribute('hidden', 'true');
|
||||
appConfig.secondaryToolbar.downloadButton.setAttribute('hidden', 'true');
|
||||
};
|
||||
}
|
||||
//#endif
|
||||
|
||||
window.addEventListener('localized', function localized(evt) {
|
||||
PDFViewerApplication.eventBus.dispatch('localized');
|
||||
|
@ -2091,17 +2075,18 @@ window.addEventListener('keydown', function keydown(evt) {
|
|||
}
|
||||
}
|
||||
|
||||
//#if !(FIREFOX || MOZCENTRAL)
|
||||
// CTRL or META without shift
|
||||
if (cmd === 1 || cmd === 8) {
|
||||
switch (evt.keyCode) {
|
||||
case 83: // s
|
||||
PDFViewerApplication.download();
|
||||
handled = true;
|
||||
break;
|
||||
if (typeof PDFJSDev === 'undefined' ||
|
||||
!PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
||||
// CTRL or META without shift
|
||||
if (cmd === 1 || cmd === 8) {
|
||||
switch (evt.keyCode) {
|
||||
case 83: // s
|
||||
PDFViewerApplication.download();
|
||||
handled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//#endif
|
||||
|
||||
// CTRL+ALT or Option+Command
|
||||
if (cmd === 3 || cmd === 10) {
|
||||
|
|
|
@ -30,7 +30,11 @@
|
|||
root.pdfjsWebPDFJS);
|
||||
}
|
||||
}(this, function (exports, app, overlayManager, preferences, pdfjsLib) {
|
||||
//#if CHROME
|
||||
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('CHROME')) {
|
||||
throw new Error('Module "pdfjs-web/chromecom" shall not be used outside ' +
|
||||
'CHROME build.');
|
||||
}
|
||||
|
||||
var PDFViewerApplication = app.PDFViewerApplication;
|
||||
var DefaultExernalServices = app.DefaultExernalServices;
|
||||
var OverlayManager = overlayManager.OverlayManager;
|
||||
|
@ -198,7 +202,7 @@
|
|||
// because the shown string should match the UI at chrome://extensions.
|
||||
// These strings are from chrome/app/resources/generated_resources_*.xtb.
|
||||
var i18nFileAccessLabel =
|
||||
//#include $ROOT/web/chrome-i18n-allow-access-to-file-urls.json
|
||||
PDFJSDev.json('$ROOT/web/chrome-i18n-allow-access-to-file-urls.json')
|
||||
[chrome.i18n.getUILanguage && chrome.i18n.getUILanguage()];
|
||||
|
||||
if (i18nFileAccessLabel) {
|
||||
|
@ -352,5 +356,4 @@
|
|||
PDFViewerApplication.externalServices = ChromeExternalServices;
|
||||
|
||||
exports.ChromeCom = ChromeCom;
|
||||
//#endif
|
||||
}));
|
||||
|
|
|
@ -25,7 +25,8 @@
|
|||
factory((root.pdfjsWebDownloadManager = {}), root.pdfjsWebPDFJS);
|
||||
}
|
||||
}(this, function (exports, pdfjsLib) {
|
||||
//#if GENERIC || CHROME
|
||||
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC || CHROME')) {
|
||||
/* jshint -W082 */
|
||||
function download(blobUrl, filename) {
|
||||
var a = document.createElement('a');
|
||||
if (a.click) {
|
||||
|
@ -106,5 +107,5 @@
|
|||
};
|
||||
|
||||
exports.DownloadManager = DownloadManager;
|
||||
//#endif
|
||||
}
|
||||
}));
|
||||
|
|
|
@ -27,7 +27,12 @@
|
|||
root.pdfjsWebApp, root.pdfjsWebPDFJS);
|
||||
}
|
||||
}(this, function (exports, preferences, app, pdfjsLib) {
|
||||
//#if FIREFOX || MOZCENTRAL
|
||||
if (typeof PDFJSDev === 'undefined' ||
|
||||
!PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
||||
throw new Error('Module "pdfjs-web/firefoxcom" shall not be used outside ' +
|
||||
'FIREFOX and MOZCENTRAL builds.');
|
||||
}
|
||||
|
||||
var Preferences = preferences.Preferences;
|
||||
var PDFViewerApplication = app.PDFViewerApplication;
|
||||
|
||||
|
@ -288,5 +293,4 @@ document.mozL10n.setExternalLocalizerServices({
|
|||
|
||||
exports.DownloadManager = DownloadManager;
|
||||
exports.FirefoxCom = FirefoxCom;
|
||||
//#endif
|
||||
}));
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/* globals chrome */
|
||||
|
||||
'use strict';
|
||||
|
||||
|
@ -191,30 +192,30 @@
|
|||
|
||||
_pushOrReplaceState: function pdfHistory_pushOrReplaceState(stateObj,
|
||||
replace) {
|
||||
//#if CHROME
|
||||
// history.state.chromecomState is managed by chromecom.js.
|
||||
if (window.history.state && 'chromecomState' in window.history.state) {
|
||||
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('CHROME') &&
|
||||
window.history.state && 'chromecomState' in window.history.state) {
|
||||
stateObj = stateObj || {};
|
||||
stateObj.chromecomState = window.history.state.chromecomState;
|
||||
}
|
||||
//#endif
|
||||
if (replace) {
|
||||
//#if (GENERIC || CHROME)
|
||||
window.history.replaceState(stateObj, '', document.URL);
|
||||
//#else
|
||||
// window.history.replaceState(stateObj, '');
|
||||
//#endif
|
||||
if (typeof PDFJSDev === 'undefined' ||
|
||||
PDFJSDev.test('GENERIC || CHROME')) {
|
||||
window.history.replaceState(stateObj, '', document.URL);
|
||||
} else {
|
||||
window.history.replaceState(stateObj, '');
|
||||
}
|
||||
} else {
|
||||
//#if (GENERIC || CHROME)
|
||||
window.history.pushState(stateObj, '', document.URL);
|
||||
//#else
|
||||
// window.history.pushState(stateObj, '');
|
||||
//#endif
|
||||
//#if CHROME
|
||||
// if (top === window) {
|
||||
// chrome.runtime.sendMessage('showPageAction');
|
||||
// }
|
||||
//#endif
|
||||
if (typeof PDFJSDev === 'undefined' ||
|
||||
PDFJSDev.test('GENERIC || CHROME')) {
|
||||
window.history.pushState(stateObj, '', document.URL);
|
||||
} else {
|
||||
window.history.pushState(stateObj, '');
|
||||
}
|
||||
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('CHROME') &&
|
||||
top === window) {
|
||||
chrome.runtime.sendMessage('showPageAction');
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -362,9 +362,11 @@ var PDFPageView = (function PDFPageViewClosure() {
|
|||
}
|
||||
this.canvas = canvas;
|
||||
|
||||
//#if MOZCENTRAL || FIREFOX || GENERIC
|
||||
canvas.mozOpaque = true;
|
||||
//#endif
|
||||
if (typeof PDFJSDev === 'undefined' ||
|
||||
PDFJSDev.test('MOZCENTRAL || FIREFOX || GENERIC')) {
|
||||
canvas.mozOpaque = true;
|
||||
}
|
||||
|
||||
var ctx = canvas.getContext('2d', {alpha: false});
|
||||
var outputScale = getOutputScale(ctx);
|
||||
this.outputScale = outputScale;
|
||||
|
|
|
@ -485,11 +485,13 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
|
|||
|
||||
window.addEventListener('fullscreenchange', this.fullscreenChangeBind);
|
||||
window.addEventListener('mozfullscreenchange', this.fullscreenChangeBind);
|
||||
//#if !(FIREFOX || MOZCENTRAL)
|
||||
window.addEventListener('webkitfullscreenchange',
|
||||
this.fullscreenChangeBind);
|
||||
window.addEventListener('MSFullscreenChange', this.fullscreenChangeBind);
|
||||
//#endif
|
||||
if (typeof PDFJSDev === 'undefined' ||
|
||||
!PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
||||
window.addEventListener('webkitfullscreenchange',
|
||||
this.fullscreenChangeBind);
|
||||
window.addEventListener('MSFullscreenChange',
|
||||
this.fullscreenChangeBind);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -500,12 +502,13 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
|
|||
window.removeEventListener('fullscreenchange', this.fullscreenChangeBind);
|
||||
window.removeEventListener('mozfullscreenchange',
|
||||
this.fullscreenChangeBind);
|
||||
//#if !(FIREFOX || MOZCENTRAL)
|
||||
window.removeEventListener('webkitfullscreenchange',
|
||||
this.fullscreenChangeBind);
|
||||
window.removeEventListener('MSFullscreenChange',
|
||||
this.fullscreenChangeBind);
|
||||
//#endif
|
||||
if (typeof PDFJSDev === 'undefined' ||
|
||||
!PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
||||
window.removeEventListener('webkitfullscreenchange',
|
||||
this.fullscreenChangeBind);
|
||||
window.removeEventListener('MSFullscreenChange',
|
||||
this.fullscreenChangeBind);
|
||||
}
|
||||
|
||||
delete this.fullscreenChangeBind;
|
||||
}
|
||||
|
|
|
@ -63,9 +63,11 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
|
|||
|
||||
// Since this is a temporary canvas, we need to fill the canvas with a white
|
||||
// background ourselves. `_getPageDrawContext` uses CSS rules for this.
|
||||
//#if MOZCENTRAL || FIREFOX || GENERIC
|
||||
tempCanvas.mozOpaque = true;
|
||||
//#endif
|
||||
if (typeof PDFJSDev === 'undefined' ||
|
||||
PDFJSDev.test('MOZCENTRAL || FIREFOX || GENERIC')) {
|
||||
tempCanvas.mozOpaque = true;
|
||||
}
|
||||
|
||||
var ctx = tempCanvas.getContext('2d', {alpha: false});
|
||||
ctx.save();
|
||||
ctx.fillStyle = 'rgb(255, 255, 255)';
|
||||
|
@ -215,9 +217,10 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
|
|||
// until rendering/image conversion is complete, to avoid display issues.
|
||||
this.canvas = canvas;
|
||||
|
||||
//#if MOZCENTRAL || FIREFOX || GENERIC
|
||||
canvas.mozOpaque = true;
|
||||
//#endif
|
||||
if (typeof PDFJSDev === 'undefined' ||
|
||||
PDFJSDev.test('MOZCENTRAL || FIREFOX || GENERIC')) {
|
||||
canvas.mozOpaque = true;
|
||||
}
|
||||
var ctx = canvas.getContext('2d', {alpha: false});
|
||||
var outputScale = getOutputScale(ctx);
|
||||
|
||||
|
|
|
@ -567,8 +567,8 @@ var PDFViewer = (function pdfViewer() {
|
|||
if (!this.pdfDocument) {
|
||||
return;
|
||||
}
|
||||
//#if GENERIC
|
||||
if (arguments.length > 1 || typeof params === 'number') {
|
||||
if ((typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) &&
|
||||
(arguments.length > 1 || typeof params === 'number')) {
|
||||
console.warn('Call of scrollPageIntoView() with obsolete signature.');
|
||||
var paramObj = {};
|
||||
if (typeof params === 'number') {
|
||||
|
@ -579,7 +579,6 @@ var PDFViewer = (function pdfViewer() {
|
|||
}
|
||||
params = paramObj;
|
||||
}
|
||||
//#endif
|
||||
var pageNumber = params.pageNumber || 0;
|
||||
var dest = params.destArray || null;
|
||||
var allowNegativeOffset = params.allowNegativeOffset || false;
|
||||
|
|
|
@ -26,12 +26,12 @@
|
|||
}
|
||||
}(this, function (exports) {
|
||||
|
||||
//#if PRODUCTION
|
||||
//var defaultPreferences = Promise.resolve(
|
||||
//#include $ROOT/web/default_preferences.json
|
||||
//);
|
||||
//#else
|
||||
var defaultPreferences = new Promise(function (resolve) {
|
||||
var defaultPreferences;
|
||||
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('PRODUCTION')) {
|
||||
defaultPreferences = Promise.resolve(
|
||||
PDFJSDev.json('$ROOT/web/default_preferences.json'));
|
||||
} else {
|
||||
defaultPreferences = new Promise(function (resolve) {
|
||||
if (DEFAULT_PREFERENCES) {
|
||||
resolve(DEFAULT_PREFERENCES);
|
||||
return;
|
||||
|
@ -41,7 +41,7 @@
|
|||
document.removeEventListener('defaultpreferencesloaded', loaded);
|
||||
});
|
||||
});
|
||||
//#endif
|
||||
}
|
||||
|
||||
function cloneObj(obj) {
|
||||
var result = {};
|
||||
|
@ -197,21 +197,22 @@ var Preferences = {
|
|||
}
|
||||
};
|
||||
|
||||
//#if !(FIREFOX || MOZCENTRAL || CHROME)
|
||||
Preferences._writeToStorage = function (prefObj) {
|
||||
return new Promise(function (resolve) {
|
||||
localStorage.setItem('pdfjs.preferences', JSON.stringify(prefObj));
|
||||
resolve();
|
||||
});
|
||||
};
|
||||
if (typeof PDFJSDev === 'undefined' ||
|
||||
!PDFJSDev.test('FIREFOX || MOZCENTRAL || CHROME')) {
|
||||
Preferences._writeToStorage = function (prefObj) {
|
||||
return new Promise(function (resolve) {
|
||||
localStorage.setItem('pdfjs.preferences', JSON.stringify(prefObj));
|
||||
resolve();
|
||||
});
|
||||
};
|
||||
|
||||
Preferences._readFromStorage = function (prefObj) {
|
||||
return new Promise(function (resolve) {
|
||||
var readPrefs = JSON.parse(localStorage.getItem('pdfjs.preferences'));
|
||||
resolve(readPrefs);
|
||||
});
|
||||
};
|
||||
//#endif
|
||||
Preferences._readFromStorage = function (prefObj) {
|
||||
return new Promise(function (resolve) {
|
||||
var readPrefs = JSON.parse(localStorage.getItem('pdfjs.preferences'));
|
||||
resolve(readPrefs);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
exports.Preferences = Preferences;
|
||||
}));
|
||||
|
|
|
@ -333,58 +333,61 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
|||
div.addEventListener('mousedown', function (e) {
|
||||
if (self.enhanceTextSelection && self.textLayerRenderTask) {
|
||||
self.textLayerRenderTask.expandTextDivs(true);
|
||||
//#if !(MOZCENTRAL || FIREFOX)
|
||||
if (expandDivsTimer) {
|
||||
if ((typeof PDFJSDev === 'undefined' ||
|
||||
!PDFJSDev.test('FIREFOX || MOZCENTRAL')) &&
|
||||
expandDivsTimer) {
|
||||
clearTimeout(expandDivsTimer);
|
||||
expandDivsTimer = null;
|
||||
}
|
||||
//#endif
|
||||
return;
|
||||
}
|
||||
var end = div.querySelector('.endOfContent');
|
||||
if (!end) {
|
||||
return;
|
||||
}
|
||||
//#if !(MOZCENTRAL || FIREFOX)
|
||||
if (typeof PDFJSDev === 'undefined' ||
|
||||
!PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
||||
// On non-Firefox browsers, the selection will feel better if the height
|
||||
// of the endOfContent div will be adjusted to start at mouse click
|
||||
// location -- this will avoid flickering when selections moves up.
|
||||
// However it does not work when selection started on empty space.
|
||||
var adjustTop = e.target !== div;
|
||||
//#if GENERIC
|
||||
adjustTop = adjustTop && window.getComputedStyle(end).
|
||||
getPropertyValue('-moz-user-select') !== 'none';
|
||||
//#endif
|
||||
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
||||
adjustTop = adjustTop && window.getComputedStyle(end).
|
||||
getPropertyValue('-moz-user-select') !== 'none';
|
||||
}
|
||||
if (adjustTop) {
|
||||
var divBounds = div.getBoundingClientRect();
|
||||
var r = Math.max(0, (e.pageY - divBounds.top) / divBounds.height);
|
||||
end.style.top = (r * 100).toFixed(2) + '%';
|
||||
}
|
||||
//#endif
|
||||
}
|
||||
end.classList.add('active');
|
||||
});
|
||||
|
||||
div.addEventListener('mouseup', function (e) {
|
||||
if (self.enhanceTextSelection && self.textLayerRenderTask) {
|
||||
//#if !(MOZCENTRAL || FIREFOX)
|
||||
expandDivsTimer = setTimeout(function() {
|
||||
if (self.textLayerRenderTask) {
|
||||
self.textLayerRenderTask.expandTextDivs(false);
|
||||
}
|
||||
expandDivsTimer = null;
|
||||
}, EXPAND_DIVS_TIMEOUT);
|
||||
//#else
|
||||
// self.textLayerRenderTask.expandTextDivs(false);
|
||||
//#endif
|
||||
if (typeof PDFJSDev === 'undefined' ||
|
||||
!PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
||||
expandDivsTimer = setTimeout(function() {
|
||||
if (self.textLayerRenderTask) {
|
||||
self.textLayerRenderTask.expandTextDivs(false);
|
||||
}
|
||||
expandDivsTimer = null;
|
||||
}, EXPAND_DIVS_TIMEOUT);
|
||||
} else {
|
||||
self.textLayerRenderTask.expandTextDivs(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var end = div.querySelector('.endOfContent');
|
||||
if (!end) {
|
||||
return;
|
||||
}
|
||||
//#if !(MOZCENTRAL || FIREFOX)
|
||||
end.style.top = '';
|
||||
//#endif
|
||||
if (typeof PDFJSDev === 'undefined' ||
|
||||
!PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
||||
end.style.top = '';
|
||||
}
|
||||
end.classList.remove('active');
|
||||
});
|
||||
},
|
||||
|
|
|
@ -80,13 +80,15 @@ PDFJS.disableTextLayer = (PDFJS.disableTextLayer === undefined ?
|
|||
PDFJS.ignoreCurrentPositionOnZoom = (PDFJS.ignoreCurrentPositionOnZoom ===
|
||||
undefined ? false : PDFJS.ignoreCurrentPositionOnZoom);
|
||||
|
||||
//#if !(FIREFOX || MOZCENTRAL)
|
||||
/**
|
||||
* Interface locale settings.
|
||||
* @var {string}
|
||||
*/
|
||||
PDFJS.locale = (PDFJS.locale === undefined ? navigator.language : PDFJS.locale);
|
||||
//#endif
|
||||
if (typeof PDFJSDev === 'undefined' ||
|
||||
!PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
||||
/**
|
||||
* Interface locale settings.
|
||||
* @var {string}
|
||||
*/
|
||||
PDFJS.locale = (PDFJS.locale === undefined ? navigator.language :
|
||||
PDFJS.locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns scale factor for the canvas. It makes sense for the HiDPI displays.
|
||||
|
|
|
@ -73,27 +73,24 @@ var ViewHistory = (function ViewHistoryClosure() {
|
|||
return new Promise(function (resolve) {
|
||||
var databaseStr = JSON.stringify(this.database);
|
||||
|
||||
//#if FIREFOX || MOZCENTRAL
|
||||
// sessionStorage.setItem('pdfjsHistory', databaseStr);
|
||||
// resolve();
|
||||
//#endif
|
||||
|
||||
//#if !(FIREFOX || MOZCENTRAL)
|
||||
localStorage.setItem('database', databaseStr);
|
||||
if (typeof PDFJSDev !== 'undefined' &&
|
||||
PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
||||
sessionStorage.setItem('pdfjsHistory', databaseStr);
|
||||
} else {
|
||||
localStorage.setItem('database', databaseStr);
|
||||
}
|
||||
resolve();
|
||||
//#endif
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
_readFromStorage: function ViewHistory_readFromStorage() {
|
||||
return new Promise(function (resolve) {
|
||||
//#if FIREFOX || MOZCENTRAL
|
||||
// resolve(sessionStorage.getItem('pdfjsHistory'));
|
||||
//#endif
|
||||
|
||||
//#if !(FIREFOX || MOZCENTRAL)
|
||||
resolve(localStorage.getItem('database'));
|
||||
//#endif
|
||||
if (typeof PDFJSDev !== 'undefined' &&
|
||||
PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
||||
resolve(sessionStorage.getItem('pdfjsHistory'));
|
||||
} else {
|
||||
resolve(localStorage.getItem('database'));
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -18,37 +18,37 @@
|
|||
|
||||
var DEFAULT_URL = 'compressed.tracemonkey-pldi-09.pdf';
|
||||
|
||||
//#if CHROME
|
||||
//(function rewriteUrlClosure() {
|
||||
// // Run this code outside DOMContentLoaded to make sure that the URL
|
||||
// // is rewritten as soon as possible.
|
||||
// var queryString = document.location.search.slice(1);
|
||||
// var m = /(^|&)file=([^&]*)/.exec(queryString);
|
||||
// DEFAULT_URL = m ? decodeURIComponent(m[2]) : '';
|
||||
//
|
||||
// // Example: chrome-extension://.../http://example.com/file.pdf
|
||||
// var humanReadableUrl = '/' + DEFAULT_URL + location.hash;
|
||||
// history.replaceState(history.state, '', humanReadableUrl);
|
||||
// if (top === window) {
|
||||
// chrome.runtime.sendMessage('showPageAction');
|
||||
// }
|
||||
//})();
|
||||
//#endif
|
||||
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('CHROME')) {
|
||||
(function rewriteUrlClosure() {
|
||||
// Run this code outside DOMContentLoaded to make sure that the URL
|
||||
// is rewritten as soon as possible.
|
||||
var queryString = document.location.search.slice(1);
|
||||
var m = /(^|&)file=([^&]*)/.exec(queryString);
|
||||
DEFAULT_URL = m ? decodeURIComponent(m[2]) : '';
|
||||
|
||||
//#if PRODUCTION
|
||||
//var pdfjsWebLibs = {
|
||||
// pdfjsWebPDFJS: window.pdfjsDistBuildPdf
|
||||
//};
|
||||
//
|
||||
//(function () {
|
||||
// Example: chrome-extension://.../http://example.com/file.pdf
|
||||
var humanReadableUrl = '/' + DEFAULT_URL + location.hash;
|
||||
history.replaceState(history.state, '', humanReadableUrl);
|
||||
if (top === window) {
|
||||
chrome.runtime.sendMessage('showPageAction');
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
var pdfjsWebLibs;
|
||||
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('PRODUCTION')) {
|
||||
pdfjsWebLibs = {
|
||||
pdfjsWebPDFJS: window.pdfjsDistBuildPdf
|
||||
};
|
||||
(function () {
|
||||
//#expand __BUNDLE__
|
||||
//}).call(pdfjsWebLibs);
|
||||
//#endif
|
||||
}).call(pdfjsWebLibs);
|
||||
}
|
||||
|
||||
//#if FIREFOX || MOZCENTRAL
|
||||
//// FIXME the l10n.js file in the Firefox extension needs global FirefoxCom.
|
||||
//window.FirefoxCom = pdfjsWebLibs.pdfjsWebFirefoxCom.FirefoxCom;
|
||||
//#endif
|
||||
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
||||
// FIXME the l10n.js file in the Firefox extension needs global FirefoxCom.
|
||||
window.FirefoxCom = pdfjsWebLibs.pdfjsWebFirefoxCom.FirefoxCom;
|
||||
}
|
||||
|
||||
function getViewerConfiguration() {
|
||||
return {
|
||||
|
@ -169,21 +169,22 @@ function getViewerConfiguration() {
|
|||
|
||||
function webViewerLoad() {
|
||||
var config = getViewerConfiguration();
|
||||
//#if !PRODUCTION
|
||||
require.config({paths: {'pdfjs': '../src', 'pdfjs-web': '.'}});
|
||||
require(['pdfjs-web/pdfjs'], function () {
|
||||
// Ensure that src/main_loader.js has loaded all the necessary dependencies
|
||||
// *before* the viewer loads, to prevent issues in browsers relying on e.g.
|
||||
// the Promise/URL polyfill in src/shared/util.js (fixes issue 7448).
|
||||
require(['pdfjs-web/app', 'pdfjs-web/pdf_print_service'], function (web) {
|
||||
window.PDFViewerApplication = web.PDFViewerApplication;
|
||||
web.PDFViewerApplication.run(config);
|
||||
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
|
||||
require.config({paths: {'pdfjs': '../src', 'pdfjs-web': '.'}});
|
||||
require(['pdfjs-web/pdfjs'], function () {
|
||||
// Ensure that src/main_loader.js has loaded all the necessary
|
||||
// dependencies *before* the viewer loads, to prevent issues in browsers
|
||||
// relying on e.g. the Promise/URL polyfill in src/shared/util.js (fixes
|
||||
// issue 7448).
|
||||
require(['pdfjs-web/app', 'pdfjs-web/pdf_print_service'], function (web) {
|
||||
window.PDFViewerApplication = web.PDFViewerApplication;
|
||||
web.PDFViewerApplication.run(config);
|
||||
});
|
||||
});
|
||||
});
|
||||
//#else
|
||||
//window.PDFViewerApplication = pdfjsWebLibs.pdfjsWebApp.PDFViewerApplication;
|
||||
//pdfjsWebLibs.pdfjsWebApp.PDFViewerApplication.run(config);
|
||||
//#endif
|
||||
} else {
|
||||
window.PDFViewerApplication = pdfjsWebLibs.pdfjsWebApp.PDFViewerApplication;
|
||||
pdfjsWebLibs.pdfjsWebApp.PDFViewerApplication.run(config);
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', webViewerLoad, true);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue