Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
PR improvements
Browse files Browse the repository at this point in the history
calculateSize is renamed to sum. (better naming conventions are welcome). sum now takes an array as argument. It returns sum of parsed array elements, suffixed with „px”.
  • Loading branch information
Worie committed Dec 9, 2016
1 parent 7396140 commit 1714336
Showing 1 changed file with 37 additions and 38 deletions.
75 changes: 37 additions & 38 deletions src/LiveDevelopment/Agents/RemoteFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ function RemoteFunctions(config) {
return;
}

var setVisibility = function (el){
var setVisibility = function (el) {
if (
!config.remoteHighlight.showPaddingMargin ||
parseInt(el.height, 10) <= 0 ||
Expand All @@ -259,13 +259,12 @@ function RemoteFunctions(config) {

var elementStyling = window.getComputedStyle(element, null);

var calculateSize = function () {
var sum = 0;
var i;
for (i = 0; i < arguments.length; i++) {
sum += parseInt(arguments[i], 10);
}
return sum;
var sum = function (offsets) {
var value = offsets.reduce(function (previous, current) {
return parseInt(previous, 10) + parseInt(current, 10);
});

return value + "px";
};

var mainBoxStyles = config.remoteHighlight.stylesToSet;
Expand All @@ -276,31 +275,31 @@ function RemoteFunctions(config) {
"height": elementStyling.getPropertyValue('padding-top'),
"width": elementBounds.width + "px",
"position": "absolute",
"top": -calculateSize(
"top": "-" + sum([
mainBoxStyles['border-width']
) + "px",
"left": -calculateSize(
]),
"left": sum([
mainBoxStyles['border-width']
) + "px"
])
},
// padding-right
{
"width": elementStyling.getPropertyValue('padding-right'),
"height": elementBounds.height + "px",
"position": "absolute",
"top": 0,
"right": -calculateSize(
"right": "-" + sum([
mainBoxStyles['border-width']
) + "px"
])
},
// padding-bottom
{
"height": elementStyling.getPropertyValue('padding-bottom'),
"width": elementBounds.width + "px",
"position": "absolute",
"bottom": -calculateSize(
"bottom": "-" + sum([
mainBoxStyles['border-width']
) + "px",
]),
"left": 0
},
// padding-left
Expand All @@ -309,9 +308,9 @@ function RemoteFunctions(config) {
"width": elementStyling.getPropertyValue('padding-left'),
"position": "absolute",
"top": 0,
"left": -calculateSize(
"left": "-" + sum([
mainBoxStyles['border-width']
) + "px"
])
}
];

Expand All @@ -321,62 +320,62 @@ function RemoteFunctions(config) {
"height": elementStyling.getPropertyValue('margin-top'),
"width": elementBounds.width + "px",
"position": "absolute",
"top": -calculateSize(
"top": "-" + sum([
elementStyling.getPropertyValue('margin-top'),
mainBoxStyles['border-width']
) + "px",
"left": -calculateSize(
]),
"left": "-" + sum([
mainBoxStyles['border-width']
) + "px"
])
},
// margin-right
{
"width": elementStyling.getPropertyValue('margin-right'),
"height":
calculateSize(
sum([
elementBounds.height,
elementStyling.getPropertyValue('margin-top'),
elementStyling.getPropertyValue('margin-bottom')
) + "px",
]),
"position": "absolute",
"top": -calculateSize(
"top": "-" + sum([
elementStyling.getPropertyValue('margin-top'),
mainBoxStyles['border-width']
) + "px",
"right": -calculateSize(
]),
"right": "-" + sum([
elementStyling.getPropertyValue('margin-right'),
mainBoxStyles['border-width']
) + "px"
])
},
// margin-bottom
{
"height": elementStyling.getPropertyValue('margin-bottom'),
"width": elementBounds.width + "px",
"position": "absolute",
"bottom": -calculateSize(
"bottom": "-" + sum([
mainBoxStyles['border-width'],
elementStyling.getPropertyValue('margin-bottom')
) + "px",
"left": -calculateSize(
]),
"left": "-" + sum([
mainBoxStyles['border-width']
) + "px"
])
},
{
"height": calculateSize(
"height": sum([
elementBounds.height,
elementStyling.getPropertyValue('margin-top'),
elementStyling.getPropertyValue('margin-bottom')
) + "px",
]),
"width": elementStyling.getPropertyValue('margin-left'),
"position": "absolute",
"top": -calculateSize(
"top": "-" + sum([
elementStyling.getPropertyValue('margin-top'),
mainBoxStyles['border-width']
) + "px",
"left": -calculateSize(
]),
"left": "-" + sum([
elementStyling.getPropertyValue('margin-left'),
mainBoxStyles['border-width']
) + "px"
])
}
];

Expand Down

0 comments on commit 1714336

Please sign in to comment.