Created
March 23, 2015 11:38
-
-
Save dbushell/beb25b8352ed896d85d4 to your computer and use it in GitHub Desktop.
Poll Stylesheets until they exist in document.styleSheets
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
var stylesheets = Array.prototype.slice.call(document.querySelectorAll('link[href*=".css"]')) | |
var sheets = document.styleSheets; | |
function pollSheets() { | |
var i, j, load_count = 0; | |
for (i = 0; i < stylesheets.length; i++) { | |
for (j = 0; j < sheets.length; j++) { | |
// check if stylesheet exists in document.styleSheets | |
if (sheets[j].href && sheets[j].href.indexOf( stylesheets[i].href ) > -1) { | |
console.log('ready: ' + stylesheets[i].href); | |
load_count++; | |
} | |
} | |
} | |
if (load_count >= stylesheets.length) { | |
// done | |
console.log('all ready'); | |
return; | |
} | |
// poll again | |
setTimeout(pollSheets); | |
} | |
pollSheets(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment