Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support almond.js #7177

Closed
iloire opened this issue Apr 11, 2016 · 2 comments
Closed

Support almond.js #7177

iloire opened this issue Apr 11, 2016 · 2 comments

Comments

@iloire
Copy link

iloire commented Apr 11, 2016

Configuration:

  • Web browser and its version: This problem can be reproduced in IE 11, when PDF.js is loaded from a different origin (CDN).
  • Operating system and its version: Windows 7
  • PDF.js version: 1.4.215

If PDF.js is loaded from a CDN and fail safe mode is triggered (hence making PDF.js trying to initialise a fake worker), if the current AMD loader is almond.js instead of requirejs, loading pdf.worker.js will fail since almond.js does not support dynamic script loading.

This is the code where the exception is thrown:

var fakeWorkerFilesLoader = useRequireEnsure ? (function (callback) {
  require.ensure([], function () {
    var worker = require('./pdf.worker.js');
    callback(worker.WorkerMessageHandler);
  });
}) : (typeof requirejs !== 'undefined') ? (function (callback) {

  // THIS WILL FAIL IF THE CURRENT AMD LOADER IS ALMOND.JS INSTEAD OF REQUIRE.JS 
  requirejs(['pdfjs-dist/build/pdf.worker'], function (worker) {
    callback(worker.WorkerMessageHandler);
  });
}) : null;

One potential solution would be to only dynamic load the dependency if the AMD loader supports it:

}) : (typeof requirejs !== 'undefined' && requirejs.load) ? (function (callback) { 

instead of

}) : (typeof requirejs !== 'undefined') ? (function (callback) { 

This change will set fakeWorkerFilesLoader to null when the ADM loader does not support dynamic loading and worker.js will be loaded using Util.loadScript instead:

      var loader = fakeWorkerFilesLoader || function (callback) {
        Util.loadScript(getWorkerSrc(), function () {
          callback(window.pdfjsDistBuildPdfWorker.WorkerMessageHandler);
        });
      };
@iloire iloire changed the title Don almond.js Support almond.js Apr 11, 2016
@iloire
Copy link
Author

iloire commented Apr 12, 2016

Raised a PR for this:
#7185

yurydelendik added a commit that referenced this issue Apr 12, 2016
@yurydelendik
Copy link
Contributor

Fixed by #7185

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants