Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Commit

Permalink
Fix browsers detection (IEs)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamvdo committed Jun 30, 2015
1 parent 8576499 commit 72452cf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
27 changes: 15 additions & 12 deletions lib/pixrem.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,19 @@ Pixrem.prototype.postcss = function (css) {
var vendor = require('postcss/lib/vendor');
var browsers = browserslist(_options.browsers);

// if IE9+
// detect IE versions needed
var isIElte8, isIEgte9, isIE9_10;
if (detectBrowser(browsers, 'ie <= 8')) {
isIElte8 = true;
}
if (detectBrowser(browsers, 'ie >= 9')) {
// if IE9 or IE10
var specialCaseIE = false;
if (detectBrowser(browsers, 'ie 9, ie 10')) {
specialCaseIE = true;
} else {
return;
}
isIEgte9 = true;
}
if (detectBrowser(browsers, 'ie 9, ie 10')) {
isIE9_10 = true;
}
// no IE versions needed, skip
if (!isIElte8 && !isIEgte9 && !isIE9_10) { return; }

if (_options.html) {
// First, check root font-size
Expand All @@ -65,7 +68,7 @@ Pixrem.prototype.postcss = function (css) {
css.eachRule(function (rule) {

// if options.at-rules is false AND it's not IE9-10: skip @rules
if (!_options.atrules && !specialCaseIE) {
if (!_options.atrules && !isIE9_10) {
if (rule.type === 'atrule' || (rule.parent && rule.parent.type === 'atrule')) { return; }
}

Expand All @@ -79,10 +82,10 @@ Pixrem.prototype.postcss = function (css) {
var prop = vendor.unprefixed(decl.prop);
// replace rems only if needed
var isFontShorthand = (prop === 'font');
var isSpecialCaseIE9 = (specialCaseIE && (isPseudoElement || isFontShorthand));
var isUseless = (!specialCaseIE && !(_VALUES.test(value) || _PROPS.test(prop)));
var isSpecialCaseIE9_10 = (isIE9_10 && (isPseudoElement || isFontShorthand));
var isUseless = (!isIE9_10 && !(_VALUES.test(value) || _PROPS.test(prop)));

if ( isSpecialCaseIE9 || isUseless ) {
if ( isSpecialCaseIE9_10 || isUseless ) {

value = value.replace(_remgex, function ($1) {
// Round decimal pixels down to match webkit and opera behavior:
Expand Down
4 changes: 2 additions & 2 deletions spec/pixrem-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ describe('pixrem', function () {
expect(processed).toBe(expected);
});

it('should not add fallback when IE8 is not in scope', function () {
it('should not add fallback when IE8- are not in scope', function () {
var css = '.rule{width: 2rem}';
var expected = '.rule{width: 2rem}';
var processed = pixrem.process(css, undefined, {browsers: 'last 2 versions'});
var processed = pixrem.process(css, undefined, {browsers: 'firefox 28'});
expect(processed).toBe(expected);
});

Expand Down

0 comments on commit 72452cf

Please sign in to comment.