Created
February 8, 2013 09:45
-
-
Save FL4TLiN3/4737761 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 (global) { | |
var dosomething = function () { | |
alert('do something'); | |
}; | |
var items = [], element, | |
i, size, waitForLoad, | |
interval = 100; | |
items.push('https://www.google.co.jp/extern_chrome/dd37e4e7f3ce9237.js'); | |
items.push('https://www.google.co.jp/images/nav_logo117.png'); | |
size = waitForLoad = items.length; | |
for (i = 0; i < size; i++) { | |
if (items[i].substr(-3) === '.js') { | |
element = global.document.createElement('script'); | |
element.type = 'text/javascript'; | |
element.src = items[i]; | |
} else if (items[i].substr(-4) === '.css') { | |
element = global.document.createElement('link'); | |
element.type = 'text/css'; | |
element.rel = 'stylesheet'; | |
element.href = items[i]; | |
} else if (items[i].substr(-4) === '.png') { | |
element = global.document.createElement('img'); | |
element.src = items[i]; | |
} else { | |
throw new Error('^^;'); | |
} | |
element.addEventListener('load', function (event) { | |
--waitForLoad; | |
}); | |
global.document.body.appendChild(element); | |
} | |
setTimeout(function () { | |
if (waitForLoad === 0) { | |
dosomething(); | |
} else { | |
setTimeout(arguments.callee, interval); | |
} | |
}, interval); | |
})(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment