-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (27 loc) · 1.26 KB
/
index.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
'use strict';
var postcss = require('postcss');
module.exports = postcss.plugin('postcss-media-legacy', function mediaLegacy(options) {
options = options || {};
return function(css, result) {
css.walkAtRules(function(atRule) {
if(atRule.name === 'media' && atRule.params !== 'print') {
atRule.nodes.forEach(function( node ) {
if(node.type === 'rule') {
var clonedNode = node.clone(),
clonedNodeArray = clonedNode.selector.split(','),
selector = '.lt-ie9 ',
selectorLength = selector.length;
for (var i = 0; i < clonedNodeArray.length; i++) {
if(clonedNodeArray[i].substring(0, selectorLength) == selector) {
clonedNodeArray[i] = clonedNodeArray[i].substring(selectorLength);
}
clonedNodeArray[i] = selector + clonedNodeArray[i];
}
clonedNode.selector = clonedNodeArray.join(',');
result.root.insertBefore( atRule, clonedNode );
}
});
}
});
};
});