mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 17:30:09 +02:00
Refactor the mobile viewer example
This mostly removes B2G-specific code and adds the styles from the B2G components.
This commit is contained in:
parent
a9dd2ab0ab
commit
a20f814265
4 changed files with 72 additions and 79 deletions
|
@ -1,4 +1,4 @@
|
|||
/* Copyright 2014 Mozilla Foundation
|
||||
/* Copyright 2016 Mozilla Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -17,13 +17,19 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
if (!PDFJS.PDFViewer || !PDFJS.getDocument) {
|
||||
alert('Please build the pdfjs-dist library using\n' +
|
||||
' `gulp dist`');
|
||||
}
|
||||
|
||||
PDFJS.useOnlyCssZoom = true;
|
||||
PDFJS.disableTextLayer = true;
|
||||
PDFJS.maxImageSize = 1024 * 1024;
|
||||
PDFJS.workerSrc = '../pdfjs-components/build/pdf.worker.js';
|
||||
PDFJS.cMapUrl = '../pdfjs-components/cmaps/';
|
||||
PDFJS.workerSrc = '../../build/dist/build/pdf.worker.js';
|
||||
PDFJS.cMapUrl = '../../build/dist/cmaps/';
|
||||
PDFJS.cMapPacked = true;
|
||||
|
||||
var DEFAULT_URL = '../../web/compressed.tracemonkey-pldi-09.pdf';
|
||||
var DEFAULT_SCALE_DELTA = 1.1;
|
||||
var MIN_SCALE = 0.25;
|
||||
var MAX_SCALE = 10.0;
|
||||
|
@ -36,9 +42,9 @@ var PDFViewerApplication = {
|
|||
pdfLinkService: null,
|
||||
|
||||
open: function (params) {
|
||||
var url = params.url, originalUrl = params.originalUrl;
|
||||
var url = params.url;
|
||||
var self = this;
|
||||
this.setTitleUsingUrl(originalUrl);
|
||||
this.setTitleUsingUrl(url);
|
||||
|
||||
// Loading document.
|
||||
var loadingTask = PDFJS.getDocument(url);
|
||||
|
@ -134,7 +140,7 @@ var PDFViewerApplication = {
|
|||
|
||||
setTitle: function pdfViewSetTitle(title) {
|
||||
document.title = title;
|
||||
document.getElementById('activityTitle').textContent = title;
|
||||
document.getElementById('title').textContent = title;
|
||||
},
|
||||
|
||||
error: function pdfViewError(message, moreInfo) {
|
||||
|
@ -273,10 +279,11 @@ var PDFViewerApplication = {
|
|||
|
||||
document.getElementById('pageNumber').addEventListener('change',
|
||||
function() {
|
||||
// Handle the user inputting a floating point number.
|
||||
PDFViewerApplication.page = (this.value | 0);
|
||||
|
||||
if (this.value !== (this.value | 0).toString()) {
|
||||
// Ensure that the page number input displays the correct value, even if the
|
||||
// value entered by the user was invalid (e.g. a floating point number).
|
||||
if (this.value !== PDFViewerApplication.page.toString()) {
|
||||
this.value = PDFViewerApplication.page;
|
||||
}
|
||||
});
|
||||
|
@ -310,38 +317,9 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||
});
|
||||
})();
|
||||
|
||||
// Support of the new version of navigator.mozL10n -- in PDF.js older/custom
|
||||
// version is used.
|
||||
var mozL10n = {
|
||||
get: function (id, args, fallback) {
|
||||
var s = (navigator.mozL10n && navigator.mozL10n.get(id)) || fallback;
|
||||
s = s.replace(/\{\{\s*(\w+)\s*\}\}/g, function (all, key) {
|
||||
return args[key] || '';
|
||||
});
|
||||
return s;
|
||||
},
|
||||
|
||||
translate: function (fragment) {
|
||||
if (navigator.mozL10n) {
|
||||
navigator.mozL10n.translateFragment(fragment);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
window.navigator.mozSetMessageHandler('activity', function(activity) {
|
||||
var blob = activity.source.data.blob;
|
||||
var fileURL = activity.source.data.url ||
|
||||
activity.source.data.filename ||
|
||||
' '; // if no url or filename, use a non-empty string
|
||||
|
||||
var url = URL.createObjectURL(blob);
|
||||
// We need to delay opening until all HTML is loaded.
|
||||
PDFViewerApplication.animationStartedPromise.then(function () {
|
||||
PDFViewerApplication.open({url: url, originalUrl: fileURL});
|
||||
|
||||
var header = document.getElementById('header');
|
||||
header.addEventListener('action', function() {
|
||||
activity.postResult('close');
|
||||
});
|
||||
// We need to delay opening until all HTML is loaded.
|
||||
PDFViewerApplication.animationStartedPromise.then(function () {
|
||||
PDFViewerApplication.open({
|
||||
url: DEFAULT_URL
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue