feat(media): add external media library support, Uploadcare integration (#1602)

This commit is contained in:
Shawn Erquhart
2018-08-30 16:24:28 -04:00
committed by GitHub
parent ae28f6301e
commit 0596904e0b
34 changed files with 715 additions and 135 deletions

View File

@ -6,3 +6,4 @@ export { resolvePath, basename, fileExtensionWithSeparator, fileExtension } from
export { filterPromises, resolvePromiseProperties, then } from './promise';
export unsentRequest from './unsentRequest';
export { filterByPropExtension, parseResponse, responseParser } from './backendUtil';
export loadScript from './loadScript';

View File

@ -0,0 +1,24 @@
/**
* Simple script loader that returns a promise.
*/
export default function loadScript(url) {
return new Promise((resolve, reject) => {
let done = false;
const head = document.getElementsByTagName('head')[0];
const script = document.createElement('script');
script.src = url;
script.onload = script.onreadystatechange = function() {
if (
!done &&
(!this.readyState || this.readyState === 'loaded' || this.readyState === 'complete')
) {
done = true;
resolve();
} else {
reject();
}
};
script.onerror = error => reject(error);
head.appendChild(script);
});
}