Created
April 16, 2018 21:00
-
-
Save luislobo14rap/de6e57242d5d3af3b7c26cdefeb32280 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function waitBy(byThis, diffThis = 'undefined', maxWait = 10000){ | |
return new Promise(function(resolve, reject){ | |
if( typeof byThis == 'string' ){ | |
let waitPromise = setInterval(function(){ | |
if( typeof top[byThis] != diffThis ){ | |
clearInterval(waitPromise); | |
resolve(true); | |
}; | |
}, 10); | |
let waitPromiseReject = setTimeout(function(){ | |
resolve(false); | |
}, maxWait); | |
}else{ | |
let waitPromise = setInterval(function(){ | |
let continuee = true; | |
byThis.forEach(function( thisVar, i ){ | |
if( typeof top[thisVar] == diffThis ){ | |
continuee = false; | |
}; | |
}); | |
if( continuee == true ){ | |
clearInterval(waitPromise); | |
resolve(true); | |
}; | |
}, 10); | |
let waitPromiseReject = setTimeout(function(){ | |
resolve(false); | |
}, maxWait); | |
}; | |
}); | |
}; | |
/* | |
$('<script src="https://fastcdn.org/FileSaver.js/1.1.20151003/FileSaver.min.js"></script>').appendTo('head'); | |
$('<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.5/jszip.min.js"></script>').appendTo('head'); | |
$('<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip-utils/0.0.2/jszip-utils.min.js"></script>').appendTo('head'); | |
waitJZipUtils = waitBy(['saveAs', 'JSZip', 'JSZipUtdils']); | |
waitJZipUtils.then(function(val){ | |
if( val == true ){ | |
//... | |
}else{ | |
console.error('promise error on load saveAs, JSZip and JSZipUtdils'); | |
}; | |
}); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment