Skip to content

Commit

Permalink
fixed loading optimized styles on IE
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Kravchenko committed May 16, 2013
1 parent 1a9383e commit 9ae1835
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ Features
* insert compiled CSS into <head>
* optimize support (resulting CSS will be compiled into resulting javascript)

Browser support
---------------
Development works on all major browsers.
IE7+ works after optimize.

Installation
------------
```bower install require-stylus```
Expand Down
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "require-stylus",
"version": "1.0.2",
"version": "1.0.7",
"main": "require-stylus.js"
}
25 changes: 22 additions & 3 deletions require-stylus.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,28 @@ define ['stylus'], ->
throw err if err
cssInsertString = """
define(function(){
var styleTag = document.createElement('style');
styleTag.innerHTML = #{JSON.stringify css};
document.head.appendChild(styleTag);
var css = #{JSON.stringify css},
head = document.getElementsByTagName('head')[0],
style = document.createElement('style');
var imports = css.match(new RegExp('@import\\\\s+url\\\\(.*\\\\);?', 'g'));
imports.forEach(function(i){
css = css.replace(i, '');
var url = i.match(new RegExp('url\\\\((.*)\\\\)'))[1];
var linkElement = document.createElement('link');
linkElement.rel = 'stylesheet';
linkElement.type = 'text/css';
linkElement.href = JSON.parse(url);
head.appendChild(linkElement);
});
style.type = 'text/css';
if (style.styleSheet){
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
head.appendChild(style);
});
"""
if config.isBuild
Expand Down
2 changes: 1 addition & 1 deletion require-stylus.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9ae1835

Please sign in to comment.