Skip to content

Commit

Permalink
#382 Refactors lost-offset to use new lgCloneAllBefore
Browse files Browse the repository at this point in the history
  • Loading branch information
peterramsing committed Apr 7, 2018
1 parent cbc0725 commit 1e1cff7
Showing 1 changed file with 16 additions and 36 deletions.
52 changes: 16 additions & 36 deletions lib/lost-offset.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var lgCloneAllBefore = require('./_lg-clone-all-before');

module.exports = function lostOffsetDecl(css, settings) {
css.walkDecls('lost-offset', function lostOffsetDeclFunction(decl) {
var declArr = decl.value.split(' ');
Expand All @@ -7,15 +9,6 @@ module.exports = function lostOffsetDecl(css, settings) {
var lostOffsetRounder = settings.rounder;
var lostOffsetGutter = settings.gutter;

function cloneAllBefore(props) {
Object.keys(props).forEach(function traverseProps(prop) {
decl.cloneBefore({
prop: prop,
value: props[prop]
});
});
}

lostOffset = declArr[0];
lostOffsetNumerator = declArr[0].split('/')[0];

Expand Down Expand Up @@ -53,14 +46,10 @@ module.exports = function lostOffsetDecl(css, settings) {

if (lostOffsetDirection === 'column') {
if (lostOffset === 'clear') {
decl.cloneBefore({
prop: 'margin-top',
value: 'auto!important'
});
decl.cloneBefore({
prop: 'margin-bottom',
value: 'auto!important'
});
lgCloneAllBefore({
'margin-top': 'auto!important',
'margin-bottom': 'auto!important'
}, decl);
} else if (lostOffset === 'clear-top') {
decl.cloneBefore({
prop: 'margin-top',
Expand Down Expand Up @@ -102,25 +91,16 @@ module.exports = function lostOffsetDecl(css, settings) {
});
}
} else {
decl.cloneBefore({
prop: 'margin-top',
value: '0 !important'
});

decl.cloneBefore({
prop: 'margin-bottom',
value: lostOffsetGutter + ' !important'
});
lgCloneAllBefore({
'margin-top': '0 !important',
'margin-bottom': lostOffsetGutter + ' !important'
}, decl);
}
} else if (lostOffset === 'clear') {
decl.cloneBefore({
prop: 'margin-left',
value: 'auto!important'
});
decl.cloneBefore({
prop: 'margin-right',
value: 'auto!important'
});
lgCloneAllBefore({
'margin-left': 'auto!important',
'margin-right': 'auto!important'
}, decl);
} else if (lostOffset === 'clear-left') {
decl.cloneBefore({
prop: 'margin-left',
Expand Down Expand Up @@ -162,10 +142,10 @@ module.exports = function lostOffsetDecl(css, settings) {
});
}
} else {
cloneAllBefore({
lgCloneAllBefore({
'margin-left': '0 !important',
'margin-right': lostOffsetGutter + ' !important'
});
}, decl);
}

decl.remove();
Expand Down

0 comments on commit 1e1cff7

Please sign in to comment.