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

Commit e48ddbc

Browse files
committed
use getBoundingClientRect instead of custom fn
1 parent 6e8ea61 commit e48ddbc

File tree

4 files changed

+23
-59
lines changed

4 files changed

+23
-59
lines changed

frontend/Highlighter/MultiOverlay.js

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

13-
var nodePos = require('./nodePos');
1413
var setStyle = require('./setStyle');
1514

1615
import type {DOMNode} from '../types';
@@ -30,12 +29,12 @@ class MultiOverlay {
3029
this.container.innerHTML = '';
3130
nodes.forEach(node => {
3231
var div = this.win.document.createElement('div');
33-
var pos = nodePos(node);
32+
var box = node.getBoundingClientRect();
3433
setStyle(div, {
35-
top: pos.top + 'px',
36-
left: pos.left + 'px',
37-
width: node.offsetWidth + 'px',
38-
height: node.offsetHeight + 'px',
34+
top: box.top + 'px',
35+
left: box.left + 'px',
36+
width: box.width + 'px',
37+
height: box.height + 'px',
3938
border: '2px dotted rgba(200, 100, 100, .8)',
4039
boxSizing: 'border-box',
4140
backgroundColor: 'rgba(200, 100, 100, .2)',

frontend/Highlighter/Overlay.js

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

13-
var nodePos = require('./nodePos');
1413
var setStyle = require('./setStyle');
1514

1615
import type {DOMNode} from '../types';
@@ -86,31 +85,31 @@ class Overlay {
8685
}
8786

8887
inspect(node: DOMNode, name?: ?string) {
89-
var pos = nodePos(node);
88+
var box = node.getBoundingClientRect();
9089
var dims = getElementDimensions(node);
9190

9291
boxWrap(dims, 'margin', this.node);
9392
boxWrap(dims, 'border', this.border);
9493
boxWrap(dims, 'padding', this.padding);
9594

9695
setStyle(this.content, {
97-
height: node.offsetHeight - dims.borderTop - dims.borderBottom - dims.paddingTop - dims.paddingBottom + 'px',
98-
width: node.offsetWidth - dims.borderLeft - dims.borderRight - dims.paddingLeft - dims.paddingRight + 'px',
96+
height: box.height - dims.borderTop - dims.borderBottom - dims.paddingTop - dims.paddingBottom + 'px',
97+
width: box.width - dims.borderLeft - dims.borderRight - dims.paddingLeft - dims.paddingRight + 'px',
9998
});
10099

101100
setStyle(this.node, {
102-
top: pos.top - dims.marginTop + 'px',
103-
left: pos.left - dims.marginLeft + 'px',
101+
top: box.top - dims.marginTop + 'px',
102+
left: box.left - dims.marginLeft + 'px',
104103
});
105104

106105
this.nameSpan.textContent = (name || node.nodeName.toLowerCase());
107-
this.dimSpan.textContent = node.offsetWidth + 'px × ' + node.offsetHeight + 'px';
106+
this.dimSpan.textContent = box.width + 'px × ' + box.height + 'px';
108107

109108
var tipPos = findTipPos({
110-
top: pos.top - dims.marginTop,
111-
left: pos.left - dims.marginLeft,
112-
height: node.offsetHeight + dims.marginTop + dims.marginBottom,
113-
width: node.offsetWidth + dims.marginLeft + dims.marginRight,
109+
top: box.top - dims.marginTop,
110+
left: box.left - dims.marginLeft,
111+
height: box.height + dims.marginTop + dims.marginBottom,
112+
width: box.width + dims.marginLeft + dims.marginRight,
114113
}, this.win);
115114
setStyle(this.tip, tipPos);
116115
}

frontend/Highlighter/nodePos.js

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

frontend/types.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ export type DOMNode = {
2323
offsetHeight: number,
2424
offsetWidth: number,
2525
offsetParent: ?DOMNode,
26+
getBoundingClientRect: () => {
27+
top: number,
28+
left: number,
29+
width: number,
30+
height: number,
31+
bottom: number,
32+
right: number,
33+
},
2634
onclick?: (evt: DOMEvent) => void,
2735
scrollLeft: number,
2836
scrollTop: number,

0 commit comments

Comments
 (0)