feat(media): add external media library support, Uploadcare integration (#1602)
This commit is contained in:
@ -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';
|
||||
|
24
packages/netlify-cms-lib-util/src/loadScript.js
Normal file
24
packages/netlify-cms-lib-util/src/loadScript.js
Normal 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);
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user