1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Adds/modifies examples for node.js and webpack.

This commit is contained in:
Yury Delendik 2015-12-21 13:46:50 -06:00
parent 9228e1ffcf
commit 79c2f69c32
15 changed files with 170 additions and 19 deletions

View file

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals NetworkManager */
/* globals NetworkManager, module */
'use strict';
@ -648,7 +648,8 @@ var workerConsole = {
// Worker thread?
if (typeof window === 'undefined' && typeof require === 'undefined') {
if (typeof window === 'undefined' &&
!(typeof module !== 'undefined' && module.require)) {
if (!('console' in globalScope)) {
globalScope.console = workerConsole;
}

View file

@ -58,6 +58,14 @@ var globalScope = sharedGlobal.globalScope;
var DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
//#if PRODUCTION && !SINGLE_FILE
//#if GENERIC
//#include ../src/frameworks.js
//#else
//var fakeWorkerFilesLoader = null;
//#endif
//#endif
/**
* The maximum allowed image size in total pixels e.g. width * height. Images
* above this value will not be drawn. Use -1 for no limit.
@ -1192,7 +1200,10 @@ var PDFWorker = (function PDFWorkerClosure() {
// PDFJS.fakeWorkerFilesLoadedCapability.resolve();
//#endif
//#if PRODUCTION && !SINGLE_FILE
// Util.loadScript(PDFJS.workerSrc, function() {
// var loader = fakeWorkerFilesLoader || function (callback) {
// Util.loadScript(PDFJS.workerSrc, callback);
// };
// loader(function () {
// PDFJS.fakeWorkerFilesLoadedCapability.resolve();
// });
//#endif
@ -1295,8 +1306,10 @@ var PDFWorker = (function PDFWorkerClosure() {
},
_setupFakeWorker: function PDFWorker_setupFakeWorker() {
warn('Setting up fake worker.');
globalScope.PDFJS.disableWorker = true;
if (!globalScope.PDFJS.disableWorker) {
warn('Setting up fake worker.');
globalScope.PDFJS.disableWorker = true;
}
setupFakeWorkerGlobal().then(function () {
if (this.destroyed) {

40
src/frameworks.js Normal file
View file

@ -0,0 +1,40 @@
/* Copyright 2015 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals PDFJS, require, module */
// included from api.js for GENERIC build
'use strict';
var useRequireEnsure = false;
if (typeof module !== 'undefined' && module.require) {
// node.js - disable worker and set require.ensure.
PDFJS.disableWorker = true;
if (typeof require.ensure === 'undefined') {
require.ensure = require('node-ensure');
}
useRequireEnsure = true;
}
if (typeof __webpack_require__ !== 'undefined') {
// Webpack - get/bundle pdf.worker.js as additional file.
PDFJS.workerSrc = require('entry?name=[hash]-worker.js!./pdf.worker.js');
useRequireEnsure = true;
}
var fakeWorkerFilesLoader = useRequireEnsure && function (callback) {
require.ensure([], function () {
require('./pdf.worker.js');
callback();
});
};

View file

@ -12,12 +12,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*jshint globalstrict: false */
/* globals PDFJS */
/* jshint globalstrict: false */
/* globals PDFJS, global */
// Initializing PDFJS global object (if still undefined)
if (typeof PDFJS === 'undefined') {
(typeof window !== 'undefined' ? window : this).PDFJS = {};
(typeof window !== 'undefined' ? window :
typeof global !== 'undefined' ? global : this).PDFJS = {};
}
//#if BUNDLE_VERSION