Skip to content

Commit

Permalink
Avoid computing the existing offsets in the case of background-positi…
Browse files Browse the repository at this point in the history
…on: !important
  • Loading branch information
papandreou committed Nov 13, 2015
1 parent 6626098 commit 33a0915
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/spriteBackgroundImages.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,17 +372,19 @@ module.exports = function () {
var backgroundPositionImportant = false;
if (existingBackgroundPositionDecls.length === 1) {
// FIXME: Silently ignores other units than px
existingOffsets = existingBackgroundPositionDecls[0].value.split(' ').map(function (item) {
return parseInt(item, 10);
});
backgroundPositionImportant = existingBackgroundPositionDecls[0].value === '!important' || existingBackgroundPositionDecls[0].important;

if (existingOffsets.length !== 2 || isNaN(existingOffsets[0]) || isNaN(existingOffsets[1])) {
var err = new Error('WARNING: trying to sprite ' + imageInfo.asset.url + ' with background-position: ' + existingBackgroundPositionDecls[0].value);
assetGraph.emit('warn', err);
} else {
offsets[0] -= existingOffsets[0];
offsets[1] -= existingOffsets[1];
if (existingBackgroundPositionDecls[0].value !== '!important') {
existingOffsets = existingBackgroundPositionDecls[0].value.split(' ').map(function (item) {
return parseInt(item, 10);
});
if (existingOffsets.length !== 2 || isNaN(existingOffsets[0]) || isNaN(existingOffsets[1])) {
var err = new Error('WARNING: trying to sprite ' + imageInfo.asset.url + ' with background-position: ' + existingBackgroundPositionDecls[0].value);
assetGraph.emit('warn', err);
} else {
offsets[0] -= existingOffsets[0];
offsets[1] -= existingOffsets[1];
}
}
}
var newBackgroundPositionValue = offsets.map(function (item) {
Expand Down

0 comments on commit 33a0915

Please sign in to comment.