Skip to content

Commit

Permalink
Don't complain about missing l10n keys, if no translation is loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
jasny committed Nov 19, 2015
1 parent acc8da5 commit 83bb2d5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 97 deletions.
4 changes: 3 additions & 1 deletion pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -826,8 +826,10 @@ document.webL10n = (function(window, document, undefined) {
function getL10nData(key, args, fallback) {
var data = gL10nData[key];
if (!data) {
if (!fallback) {
if (Object.keys(gL10nData).length > 0) {
console.warn('#' + key + ' is undefined.');
}
if (!fallback) {
return null;
}
data = fallback;
Expand Down
150 changes: 54 additions & 96 deletions pdf.js.patch
Original file line number Diff line number Diff line change
@@ -1,96 +1,54 @@
--- pdf.orig.js 2015-11-19 00:10:27.980871274 -0400
+++ pdf.js 2015-11-19 00:09:05.996873377 -0400
@@ -826,8 +826,8 @@
function getL10nData(key, args, fallback) {
var data = gL10nData[key];
if (!data) {
- console.warn('#' + key + ' is undefined.');
if (!fallback) {
+ console.warn('#' + key + ' is undefined.');
return null;
}
data = fallback;
@@ -10289,10 +10289,17 @@
var PAGE_NUMBER_LOADING_INDICATOR = 'visiblePageIsLoading';
var DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;

-PDFJS.imageResourcesPath = './images/';
- PDFJS.workerSrc = '../build/pdf.worker.js';
- PDFJS.cMapUrl = '../web/cmaps/';
- PDFJS.cMapPacked = true;
+var scriptTagContainer = document.body ||
+ document.getElementsByTagName('head')[0];
+var pdfjsSrc = scriptTagContainer.lastChild.src;
+
+if (pdfjsSrc) {
+ PDFJS.imageResourcesPath = pdfjsSrc.replace(/pdf\.js$/i, 'images/');
+ PDFJS.workerSrc = pdfjsSrc.replace(/pdf\.js$/i, 'pdf.worker.js');
+ PDFJS.cMapUrl = pdfjsSrc.replace(/pdf\.js$/i, 'cmaps/');
+}
+
+PDFJS.cMapPacked = true;

var mozL10n = document.mozL10n || document.webL10n;

@@ -11740,7 +11747,7 @@
* @returns {number}
*/
get pagesCount() {
- return this.pdfDocument.numPages;
+ return this.pdfDocument ? this.pdfDocument.numPages : 0;
},

/**
@@ -16485,7 +16492,7 @@
},

get pagesCount() {
- return this.pdfDocument.numPages;
+ return this.pdfDocument ? this.pdfDocument.numPages : 0;
},

set page(val) {
@@ -17021,7 +17028,9 @@
cleanup: function pdfViewCleanup() {
this.pdfViewer.cleanup();
this.pdfThumbnailViewer.cleanup();
- this.pdfDocument.cleanup();
+ if (this.pdfDocument) {
+ this.pdfDocument.cleanup();
+ }
},

forceRendering: function pdfViewForceRendering() {
@@ -17462,7 +17471,12 @@
}
}

-document.addEventListener('DOMContentLoaded', webViewerLoad, true);
+// document.addEventListener('DOMContentLoaded', webViewerLoad, true);
+PDFJS.webViewerLoad = function (src) {
+ if (src) DEFAULT_URL = src;
+
+ webViewerLoad();
+}

document.addEventListener('pagerendered', function (e) {
var pageNumber = e.detail.pageNumber;
@@ -17585,7 +17599,7 @@
});

window.addEventListener('hashchange', function webViewerHashchange(evt) {
- if (PDFViewerApplication.pdfHistory.isHashChangeUnlocked) {
+ if (PDFViewerApplication.pdfHistory && PDFViewerApplication.pdfHistory.isHashChangeUnlocked) {
var hash = document.location.hash.substring(1);
if (!hash) {
return;
@@ -17738,6 +17752,9 @@
}, true);

function handleMouseWheel(evt) {
+ // Ignore mousewheel event if pdfViewer isn't loaded
+ if (!PDFViewerApplication.pdfViewer) return;
+
var MOUSE_WHEEL_DELTA_FACTOR = 40;
var ticks = (evt.type === 'DOMMouseScroll') ? -evt.detail :
evt.wheelDelta / MOUSE_WHEEL_DELTA_FACTOR;
829c829,831
< console.warn('#' + key + ' is undefined.');
---
> if (Object.keys(gL10nData).length > 0) {
> console.warn('#' + key + ' is undefined.');
> }
10292,10295c10294,10304
< PDFJS.imageResourcesPath = './images/';
< PDFJS.workerSrc = '../build/pdf.worker.js';
< PDFJS.cMapUrl = '../web/cmaps/';
< PDFJS.cMapPacked = true;
---
> var scriptTagContainer = document.body ||
> document.getElementsByTagName('head')[0];
> var pdfjsSrc = scriptTagContainer.lastChild.src;
>
> if (pdfjsSrc) {
> PDFJS.imageResourcesPath = pdfjsSrc.replace(/pdf\.js$/i, 'images/');
> PDFJS.workerSrc = pdfjsSrc.replace(/pdf\.js$/i, 'pdf.worker.js');
> PDFJS.cMapUrl = pdfjsSrc.replace(/pdf\.js$/i, 'cmaps/');
> }
>
> PDFJS.cMapPacked = true;
11743c11752
< return this.pdfDocument.numPages;
---
> return this.pdfDocument ? this.pdfDocument.numPages : 0;
16488c16497
< return this.pdfDocument.numPages;
---
> return this.pdfDocument ? this.pdfDocument.numPages : 0;
17024c17033,17035
< this.pdfDocument.cleanup();
---
> if (this.pdfDocument) {
> this.pdfDocument.cleanup();
> }
17465c17476,17481
< document.addEventListener('DOMContentLoaded', webViewerLoad, true);
---
> // document.addEventListener('DOMContentLoaded', webViewerLoad, true);
> PDFJS.webViewerLoad = function (src) {
> if (src) DEFAULT_URL = src;
>
> webViewerLoad();
> }
17588c17604
< if (PDFViewerApplication.pdfHistory.isHashChangeUnlocked) {
---
> if (PDFViewerApplication.pdfHistory && PDFViewerApplication.pdfHistory.isHashChangeUnlocked) {
17740a17757,17759
> // Ignore mousewheel event if pdfViewer isn't loaded
> if (!PDFViewerApplication.pdfViewer) return;
>

0 comments on commit 83bb2d5

Please sign in to comment.