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

Fix: define check #668

Merged
merged 1 commit into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/lib/__tests__/util-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('lib/util', () => {

return util.get(url, 'any').then((response) => {
expect(fetchMock.called(url)).to.be.true;
expect(response).to.be.an.object;
expect(typeof response === 'object').to.be.true;
});
});
});
Expand Down Expand Up @@ -398,15 +398,15 @@ describe('lib/util', () => {
});

it('should disable AMD until scripts are loaded or fail to load', () => {
const func = () => {};
func.amd = ['jquery'];
window.define = func;
const defineFunc = () => {};
defineFunc.amd = { jquery: '' };
window.define = defineFunc;

const promise = util.loadScripts(['foo', 'bar'], true);
expect(define).to.equal(undefined);

return promise.then(() => {
expect(define).to.equal(func);
expect(define).to.equal(defineFunc);
});
});
});
Expand Down
14 changes: 10 additions & 4 deletions src/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,10 @@ export function loadScripts(urls, disableAMD = false) {
// scripts are loaded.

/* eslint-disable no-undef */
const defineRef = typeof define === 'function' ? define : undefined;
if (disableAMD && typeof define === 'function' && define.amd) {
const amdPresent = !!window.define && typeof define === 'function' && !!define.amd;
const defineRef = amdPresent ? define : undefined;

if (disableAMD && amdPresent) {
define = undefined;
}

Expand All @@ -509,10 +511,14 @@ export function loadScripts(urls, disableAMD = false) {

return Promise.all(promises)
.then(() => {
define = defineRef || define;
if (disableAMD && amdPresent) {
define = defineRef;
}
})
.catch(() => {
define = defineRef || define;
if (disableAMD && amdPresent) {
define = defineRef;
}
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/viewers/doc/docAssets.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DOC_STATIC_ASSETS_VERSION } from '../../constants';

const STATIC_URI = `third-party/doc/${DOC_STATIC_ASSETS_VERSION}/`;
export const JS = [`${STATIC_URI}pdf.js`, `${STATIC_URI}pdf_viewer.min.js`, `${STATIC_URI}exif.min.js`];
export const JS = [`${STATIC_URI}pdf.min.js`, `${STATIC_URI}pdf_viewer.min.js`, `${STATIC_URI}exif.min.js`];
export const PRELOAD_JS = [`${STATIC_URI}pdf.worker.min.js`];
export const CSS = [`${STATIC_URI}pdf_viewer.min.css`];