feat(media): add external media library support, Uploadcare integration (#1602)
This commit is contained in:
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