From 1e1cff7411182699e92e0d541715cfb26961fbc6 Mon Sep 17 00:00:00 2001 From: Peter Ramsing Date: Sat, 17 Mar 2018 19:33:49 -0500 Subject: [PATCH] #382 Refactors lost-offset to use new lgCloneAllBefore --- lib/lost-offset.js | 52 ++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 36 deletions(-) diff --git a/lib/lost-offset.js b/lib/lost-offset.js index 68067df6..1043ecb7 100644 --- a/lib/lost-offset.js +++ b/lib/lost-offset.js @@ -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(' '); @@ -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]; @@ -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', @@ -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', @@ -162,10 +142,10 @@ module.exports = function lostOffsetDecl(css, settings) { }); } } else { - cloneAllBefore({ + lgCloneAllBefore({ 'margin-left': '0 !important', 'margin-right': lostOffsetGutter + ' !important' - }); + }, decl); } decl.remove();