Last active
December 17, 2015 09:29
-
-
Save ckimrie/5587884 to your computer and use it in GitHub Desktop.
Lightweight CSS loader
This file contains hidden or 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
| /** | |
| * Lightweight CSS Loader | |
| * | |
| * Even prepends the correct theme URL location to allow easy script loading | |
| * | |
| * @param {string} name URL to CSS file | |
| * @param {Function} cb Callback function | |
| * @return {null} | |
| */ | |
| function loadCss(name, cb) { | |
| var def = new jQuery.Deferred(), | |
| url = String(name), | |
| eed = document.createElement('link'); | |
| eed.type = 'text/css'; | |
| eed.rel = 'stylesheet'; | |
| eed.href = url; | |
| //Listen for script load | |
| eed.onload = eed.onreadystatechange = function () { | |
| if (typeof cb === "function") { | |
| cb(); | |
| } | |
| }; | |
| document.getElementsByTagName('head')[0].appendChild(eed); | |
| } | |
| /** | |
| * Usage | |
| */ | |
| loadCss('http://path/to/file.css', function(){ | |
| //Code to run once CSS is loaded | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment