Small refactor, to make it clearer whats happening

This commit is contained in:
wmwragg 2016-09-04 08:54:15 +01:00
parent e52f5b5d08
commit 50bb4edd1c

View file

@ -60,19 +60,21 @@ module.exports = React.createClass({
_renderTooltip: function() { _renderTooltip: function() {
var label = this.props.room ? this.props.room.name : this.props.label; var label = this.props.room ? this.props.room.name : this.props.label;
var style = {};
if (this.props.top) { style.top = this.props.top; }
if (this.props.left) { style.left = this.props.left; }
// Add the parent's position to the tooltips, so it's correctly // Add the parent's position to the tooltips, so it's correctly
// positioned, also taking into account any window zoom // positioned, also taking into account any window zoom
// NOTE: The additional 6 pixels for the left position, is to take account of the // NOTE: The additional 6 pixels for the left position, is to take account of the
// tooltips chevron // tooltips chevron
var parent = ReactDOM.findDOMNode(this).parentElement; var parent = ReactDOM.findDOMNode(this).parentElement;
style.top = (+style.top || 0) + parent.getBoundingClientRect().top + window.pageYOffset; var style = {};
style.left = (+style.left || 0) + 6 + parent.getBoundingClientRect().right + window.pageXOffset; style.top = parent.getBoundingClientRect().top + window.pageYOffset;
style.left = 6 + parent.getBoundingClientRect().right + window.pageXOffset;
style.display = "block"; style.display = "block";
// Add any additional positional tweaks passed in to the tooltip
if (this.props.top) { style.top += this.props.top; }
if (this.props.left) { style.left += this.props.left; }
var tooltip = ( var tooltip = (
<div className="mx_RoomTooltip" style={style} > <div className="mx_RoomTooltip" style={style} >
<div className="mx_RoomTooltip_chevron"></div> <div className="mx_RoomTooltip_chevron"></div>