Skip to content

Commit

Permalink
Allows requirejs and node load fake worker files.
Browse files Browse the repository at this point in the history
  • Loading branch information
yurydelendik committed Dec 11, 2015
1 parent 328fde5 commit e51285b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/core/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ var workerConsole = {


// Worker thread?
if (typeof window === 'undefined') {
if (typeof window === 'undefined' && typeof require === 'undefined') {
if (!('console' in globalScope)) {
globalScope.console = workerConsole;
}
Expand Down
15 changes: 12 additions & 3 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
if (typeof define === 'function' && define.amd) {
define('pdfjs/display/api', ['exports', 'pdfjs/shared/util',
'pdfjs/display/font_loader', 'pdfjs/display/canvas',
'pdfjs/shared/global'], factory);
'pdfjs/shared/global', 'require'], factory);
} else if (typeof exports !== 'undefined') {
factory(exports, require('../shared/util.js'), require('./font_loader.js'),
require('./canvas.js'), require('../shared/global.js'));
Expand All @@ -29,7 +29,7 @@
root.pdfjsSharedGlobal);
}
}(this, function (exports, sharedUtil, displayFontLoader, displayCanvas,
sharedGlobal) {
sharedGlobal, amdRequire) {

var InvalidPDFException = sharedUtil.InvalidPDFException;
var MessageHandler = sharedUtil.MessageHandler;
Expand Down Expand Up @@ -1169,7 +1169,16 @@ var PDFWorker = (function PDFWorkerClosure() {
// other files and resolves the promise. In production only the
// pdf.worker.js file is needed.
//#if !PRODUCTION
Util.loadScript(PDFJS.workerSrc);
if (typeof amdRequire === 'function') {
amdRequire(['pdfjs/core/worker'], function () {
PDFJS.fakeWorkerFilesLoadedCapability.resolve();
});
} else if (typeof require === 'function') {
require('../core/worker.js');
PDFJS.fakeWorkerFilesLoadedCapability.resolve();
} else {
Util.loadScript(PDFJS.workerSrc);
}
//#endif
//#if PRODUCTION && SINGLE_FILE
// PDFJS.fakeWorkerFilesLoadedCapability.resolve();
Expand Down

0 comments on commit e51285b

Please sign in to comment.