Skip to content

Commit

Permalink
Less decl iterations
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound committed Aug 12, 2015
1 parent 1cc8f73 commit a062147
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,25 @@ module.exports = postcss.plugin('postcss-opacity', function (opts) {
return function (css) {

css.eachRule(function (rule) {
rule.eachDecl(PROP, function (decl) {

// get amount and create value
var amount = Math.floor(decl.value * 100);
var VAL_REPLACE = '"progid:DXImageTransform.Microsoft.Alpha(Opacity=' + amount + ')"';

// find if a filter opacity is already present
var isFilterAlreadyPresent = false;
rule.eachDecl(PROP_REPLACE, function (d) {
if (d.value === VAL_REPLACE) {
isFilterAlreadyPresent = true;
}
});

// adds new property only if it's not present yet
if (!isFilterAlreadyPresent) {
// find if a filter opacity is already present
var isFilterAlreadyPresent = false;
rule.eachDecl(PROP_REPLACE, function () {
isFilterAlreadyPresent = true;
});

if (!isFilterAlreadyPresent) {
rule.eachDecl(PROP, function (decl) {

// get amount and create value
var amount = Math.floor(decl.value * 100);
var VAL_REPLACE = '"progid:DXImageTransform.Microsoft.Alpha(Opacity=' + amount + ')"';

// adds new property only if it's not present yet
rule.insertAfter(decl, {prop: PROP_REPLACE, value: VAL_REPLACE});
}

});
});
}
});

};
Expand Down

0 comments on commit a062147

Please sign in to comment.