Browse Source

Uses document.currentScript for pdf.worker.js path.

Yury Delendik 10 years ago
parent
commit
28d340679a
  1. 6
      src/pdf.js
  2. 16
      web/compatibility.js

6
src/pdf.js

@ -42,10 +42,8 @@ if (!PDFJS.workerSrc && typeof document !== 'undefined') { @@ -42,10 +42,8 @@ if (!PDFJS.workerSrc && typeof document !== 'undefined') {
// workerSrc is not set -- using last script url to define default location
PDFJS.workerSrc = (function () {
'use strict';
var scriptTagContainer = document.body ||
document.getElementsByTagName('head')[0];
var pdfjsSrc = scriptTagContainer.lastChild.src;
return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
var pdfJsSrc = document.currentScript.src;
return pdfJsSrc && pdfJsSrc.replace(/\.js$/i, '.worker.js');
})();
}
//#endif

16
web/compatibility.js

@ -577,3 +577,19 @@ if (typeof PDFJS === 'undefined') { @@ -577,3 +577,19 @@ if (typeof PDFJS === 'undefined') {
PDFJS.disableFullscreen = true;
}
})();
// Provides document.currentScript support
// Support: IE, Chrome<29.
(function checkCurrentScript() {
if ('currentScript' in document) {
return;
}
Object.defineProperty(document, 'currentScript', {
get: function () {
var scripts = document.getElementsByTagName('script');
return scripts[scripts.length - 1];
},
enumerable: true,
configurable: true
});
})();

Loading…
Cancel
Save