Initial Commit after switching from SVN to git
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
/*! onloadCSS. (onload callback for loadCSS) [c]2017 Filament Group, Inc. MIT License */
|
||||
/* global navigator */
|
||||
/* exported onloadCSS */
|
||||
function onloadCSS(ss, options ) {
|
||||
options = options || {};
|
||||
let f = function (si) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let called, success = false;
|
||||
function newcbs() {
|
||||
if (!called) {
|
||||
called = true;
|
||||
resolve(true);
|
||||
}
|
||||
} function newcbe() {
|
||||
if (!called && callback) {
|
||||
called = true;
|
||||
resolve(false);
|
||||
}
|
||||
}
|
||||
if (ss.addEventListener) {
|
||||
si.addEventListener('load', newcb);
|
||||
} else if (ss.attachEvent) {
|
||||
si.attachEvent('onload', newcb);
|
||||
}
|
||||
|
||||
// This code is for browsers that don’t support onload
|
||||
// No support for onload (it'll bind but never fire):
|
||||
// * Android 4.3 (Samsung Galaxy S4, Browserstack)
|
||||
// * Android 4.2 Browser (Samsung Galaxy SIII Mini GT-I8200L)
|
||||
// * Android 2.3 (Pantech Burst P9070)
|
||||
|
||||
// Weak inference targets Android < 4.4
|
||||
if ('isApplicationInstalled' in navigator && 'onloadcssdefined' in ss) {
|
||||
si.onloadcssdefined(newcb);
|
||||
}
|
||||
});
|
||||
};
|
||||
let fin = async function (success) {
|
||||
if (success === true && typeof options.success === 'function') {
|
||||
options.success();
|
||||
} else if (success === true && typeof options.success === 'object' && options.success instanceof Promise) {
|
||||
await options.success();
|
||||
}
|
||||
options.complete()
|
||||
}
|
||||
if (Array.isArray(ss)) {
|
||||
let total = ss.length;
|
||||
Promise.all(ss.map(f)).then(function (resolveValues) {
|
||||
var ok = resolveValues.reduce((sum, x) => sum + (x === true ? 1 : 0));
|
||||
fin(total === ok);
|
||||
});
|
||||
} else {
|
||||
f(ss);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user