forked from stealjs/steal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcss.js
47 lines (39 loc) · 1.28 KB
/
css.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
if( steal.config('env') === 'production' ) {
exports.fetch = function(load) {
// return a thenable for fetching (as per specification)
// alternatively return new Promise(function(resolve, reject) { ... })
var cssFile = load.address;
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = cssFile;
document.head.appendChild(link);
return "";
};
} else {
exports.instantiate = function(load) {
load.metadata.deps = [];
load.metadata.execute = function(){
if(load.source) {
var head = document.head || document.getElementsByTagName('head')[0],
style = document.createElement('style'),
source = load.source+"/*# sourceURL="+load.address+" */";
// make source load relative to the current page
source = source.replace(/url\(['"]?([^'"\)]*)['"]?\)/g, function( whole, part ) {
return "url(" + steal.joinURIs( load.address, part) + ")";
});
style.type = 'text/css';
if (style.styleSheet){
style.styleSheet.cssText = source;
} else {
style.appendChild(document.createTextNode(source));
}
head.appendChild(style);
}
return System.newModule({});
};
load.metadata.format = "css";
};
}
exports.tildeModules = /url\(['"](~\/.+)['"]/g;
exports.buildType = "css";
exports.includeInBuild = true;