mirror of https://github.com/artf/grapesjs.git
nocodeframeworkdrag-and-dropsite-buildersite-generatortemplate-builderui-builderweb-builderweb-builder-frameworkwebsite-builderno-codepage-builder
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
986 B
33 lines
986 B
import Promise from 'promise-polyfill';
|
|
|
|
window.Promise = window.Promise || Promise;
|
|
|
|
export default (typeof fetch == 'function'
|
|
? fetch.bind()
|
|
: (url, options) => {
|
|
return new Promise((res, rej) => {
|
|
const req = new XMLHttpRequest();
|
|
req.open(options.method || 'get', url);
|
|
req.withCredentials = options.credentials == 'include';
|
|
|
|
for (let k in options.headers || {}) {
|
|
req.setRequestHeader(k, options.headers[k]);
|
|
}
|
|
|
|
req.onload = e =>
|
|
res({
|
|
status: req.status,
|
|
statusText: req.statusText,
|
|
text: () => Promise.resolve(req.responseText)
|
|
});
|
|
req.onerror = rej;
|
|
|
|
// Actually, fetch doesn't support onProgress feature
|
|
if (req.upload && options.onProgress) {
|
|
req.upload.onprogress = options.onProgress;
|
|
}
|
|
|
|
// Include body only if present
|
|
options.body ? req.send(options.body) : req.send();
|
|
});
|
|
});
|
|
|