snappymail/dev/Common/Jassl.js
djmaze ea48f5060b isArray to native Array.isArray
isUnd(*) to native undefined === *
isFunc to native typeof * === 'function'
isObject to native typeof * === 'object'
microtime() to native Date().getTime();
noop to native ()=>{}
noopFalse to native ()=>false
noopTrue to native ()=>true
boolToAjax to native *?'1':'0'
Underscore.js to native
2020-07-29 21:49:41 +02:00

44 lines
931 B
JavaScript

import window from 'window';
// let rainloopCaches = window.caches && window.caches.open ? window.caches : null;
/**
* @param {src} src
* @param {boolean} async = false
* @returns {Promise}
*/
export function jassl(src, async = false) {
if (!src) {
throw new Error('src should not be empty.');
}
return new window.Promise((resolve, reject) => {
const element = window.document.createElement('script');
element.onload = () => {
resolve(src);
};
element.onerror = () => {
reject(new Error(src));
};
element.async = !!async;
element.src = src;
window.document.body.appendChild(element);
}) /* .then((s) => {
const found = s && rainloopCaches ? s.match(/rainloop\/v\/([^\/]+)\/static\//) : null;
if (found && found[1])
{
rainloopCaches.open('rainloop-offline-' + found[1]).then(
(cache) => cache.add(s)
).catch(() => {
rainloopCaches = null;
});
}
return s;
})*/;
}