Created
July 13, 2012 04:33
-
-
Save louisje/3102735 to your computer and use it in GitHub Desktop.
A RequireJS plugin to load css file
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
/** | |
* RequireJS Plugin - CSS Loader | |
* | |
* [ex.] | |
* define(['css!jquery-ui-css', 'jquery', 'jquery-ui'], { }); | |
* | |
* Its better to put 'css!' in front of other js dependencies to get | |
* faster loading speed | |
* | |
*/ | |
;(function() { | |
define({ | |
load: function(name, req, load, config) { | |
var url = req.toUrl(name + '.css'); | |
var css = document.createElement('link'); | |
css.type = "text/css"; | |
css.rel = "stylesheet"; | |
css.href = url; | |
var heads = document.getElementsByTagName('head') | |
if (heads && heads.length > 0) { | |
heads[0].appendChild(css); | |
load(css); | |
} else { | |
load.error(); | |
} | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Has no load detection though, doing some testing with DOM events, will link you to my version if I get it working