Add copyBox to copy immutable ClientRects

bc we do things like `box.height -= something` to trim box to window
This commit is contained in:
Bryan Housel
2017-03-30 17:48:31 -04:00
parent dabf8556dd
commit 5459f54900
+18 -3
View File
@@ -53,10 +53,9 @@ export function uiCurtain() {
curtain.reveal = function(box, text, options) {
if (typeof box === 'string') box = d3.select(box).node();
if (box.getBoundingClientRect) box = box.getBoundingClientRect();
if (box.getBoundingClientRect) box = copyBox(box.getBoundingClientRect());
options = options || {};
curtain.cut(box, options.duration);
if (text) {
// pseudo markdown bold text hack
@@ -90,7 +89,7 @@ export function uiCurtain() {
}
// var dimensions = utilGetDimensions(selection, true),
var tip = tooltip.node().getBoundingClientRect(),
var tip = copyBox(tooltip.node().getBoundingClientRect()),
w = window.innerWidth,
h = window.innerHeight,
tooltipWidth = 200,
@@ -173,6 +172,8 @@ export function uiCurtain() {
.call(uiToggle(false));
}
curtain.cut(box, options.duration);
return tooltip;
};
@@ -215,5 +216,19 @@ export function uiCurtain() {
};
// ClientRects are immutable, so copy them to an object,
// in case we need to trim the height/width.
function copyBox(src) {
return {
top: src.top,
right: src.right,
bottom: src.bottom,
left: src.left,
width: src.width,
height: src.height
};
}
return curtain;
}