Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit b3dcb3f

Browse files
committed
setStyle replaced with Object.assign
1 parent e48ddbc commit b3dcb3f

File tree

5 files changed

+25
-39
lines changed

5 files changed

+25
-39
lines changed

frontend/Draggable.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ import type {DOMEvent} from './types';
1616
class Draggable {
1717
_onMove: (evt: DOMEvent) => void;
1818
_onUp: (evt: DOMEvent) => void;
19-
props: Object;
19+
props: {
20+
onMove: (x: number, y: number) => void,
21+
onStart: () => void,
22+
onStop: () => void,
23+
style: Object,
24+
};
2025

2126
componentDidMount() {
2227
this._onMove = this.onMove.bind(this);
@@ -33,7 +38,7 @@ class Draggable {
3338

3439
onMove(evt: DOMEvent) {
3540
evt.preventDefault();
36-
this.props.onMove(evt.pageX);
41+
this.props.onMove(evt.pageX, evt.pageY);
3742
}
3843

3944
onUp(evt: DOMEvent) {

frontend/Highlighter/Highlighter.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import type {DOMNode, DOMEvent} from '../types';
1515
var Overlay = require('./Overlay');
1616
var MultiOverlay = require('./MultiOverlay');
1717

18+
/**
19+
* Manages the highlighting of items on an html page, as well as
20+
* hover-to-inspect.
21+
*/
1822
class Highlighter {
1923
_overlay: ?Overlay;
2024
_multiOverlay: ?MultiOverlay;

frontend/Highlighter/MultiOverlay.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
*/
1111
'use strict';
1212

13-
var setStyle = require('./setStyle');
14-
13+
var assign = require('object-assign');
1514
import type {DOMNode} from '../types';
1615

1716
class MultiOverlay {
@@ -30,7 +29,7 @@ class MultiOverlay {
3029
nodes.forEach(node => {
3130
var div = this.win.document.createElement('div');
3231
var box = node.getBoundingClientRect();
33-
setStyle(div, {
32+
assign(div.style, {
3433
top: box.top + 'px',
3534
left: box.left + 'px',
3635
width: box.width + 'px',
@@ -39,7 +38,7 @@ class MultiOverlay {
3938
boxSizing: 'border-box',
4039
backgroundColor: 'rgba(200, 100, 100, .2)',
4140
position: 'fixed',
42-
zIndex: 100000,
41+
zIndex: 10000000,
4342
pointerEvents: 'none',
4443
});
4544
this.container.appendChild(div);

frontend/Highlighter/Overlay.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
*/
1111
'use strict';
1212

13-
var setStyle = require('./setStyle');
14-
13+
var assign = require('object-assign');
1514
import type {DOMNode} from '../types';
1615

1716
class Overlay {
@@ -38,14 +37,14 @@ class Overlay {
3837
this.padding.style.borderColor = overlayStyles.padding;
3938
this.content.style.backgroundColor = overlayStyles.background;
4039

41-
setStyle(this.node, {
40+
assign(this.node.style, {
4241
borderColor: overlayStyles.margin,
4342
pointerEvents: 'none',
4443
position: 'fixed',
4544
});
4645

4746
this.tip = doc.createElement('div');
48-
setStyle(this.tip, {
47+
assign(this.tip.style, {
4948
border: '1px solid #aaa',
5049
backgroundColor: 'rgb(255, 255, 178)',
5150
fontFamily: 'sans-serif',
@@ -57,13 +56,13 @@ class Overlay {
5756

5857
this.nameSpan = doc.createElement('span');
5958
this.tip.appendChild(this.nameSpan);
60-
setStyle(this.nameSpan, {
59+
assign(this.nameSpan.style, {
6160
color: 'rgb(136, 18, 128)',
6261
marginRight: '5px',
6362
});
6463
this.dimSpan = doc.createElement('span');
6564
this.tip.appendChild(this.dimSpan);
66-
setStyle(this.dimSpan, {
65+
assign(this.dimSpan.style, {
6766
color: '#888',
6867
});
6968

@@ -92,12 +91,12 @@ class Overlay {
9291
boxWrap(dims, 'border', this.border);
9392
boxWrap(dims, 'padding', this.padding);
9493

95-
setStyle(this.content, {
94+
assign(this.content.style, {
9695
height: box.height - dims.borderTop - dims.borderBottom - dims.paddingTop - dims.paddingBottom + 'px',
9796
width: box.width - dims.borderLeft - dims.borderRight - dims.paddingLeft - dims.paddingRight + 'px',
9897
});
9998

100-
setStyle(this.node, {
99+
assign(this.node.style, {
101100
top: box.top - dims.marginTop + 'px',
102101
left: box.left - dims.marginLeft + 'px',
103102
});
@@ -111,7 +110,7 @@ class Overlay {
111110
height: box.height + dims.marginTop + dims.marginBottom,
112111
width: box.width + dims.marginLeft + dims.marginRight,
113112
}, this.win);
114-
setStyle(this.tip, tipPos);
113+
assign(this.tip.style, tipPos);
115114
}
116115
}
117116

@@ -138,10 +137,10 @@ function findTipPos(dims, win) {
138137
top += 'px';
139138

140139
if (dims.left < 0) {
141-
return {top, left: 0};
140+
return {top, left: margin};
142141
}
143142
if (dims.left + 200 > win.innerWidth) {
144-
return {top, right: 0};
143+
return {top, right: margin};
145144
}
146145
return {top, left: dims.left + margin + 'px'};
147146
}
@@ -166,7 +165,7 @@ function getElementDimensions(element) {
166165
}
167166

168167
function boxWrap(dims, what, node) {
169-
setStyle(node, {
168+
assign(node.style, {
170169
borderTopWidth: dims[what + 'Top'] + 'px',
171170
borderLeftWidth: dims[what + 'Left'] + 'px',
172171
borderRightWidth: dims[what + 'Right'] + 'px',

frontend/Highlighter/setStyle.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)