<commit_before>/*
Copyright 2015, 2016 OpenMarket Ltd

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

'use strict';

var React = require('react');
var ReactDOM = require('react-dom');

var dis = require('matrix-react-sdk/lib/dispatcher');

module.exports = React.createClass({
    displayName: 'RoomTooltip',

    propTypes: {
        component: React.PropTypes.object.isRequired,
        room: React.PropTypes.object,
        label: React.PropTypes.string,
    },

    // Create a wrapper for the tooltip outside the main matrix element
    componentDidMount: function() {
        this.tooltipContainer = document.createElement("div");
        this.tooltipContainer.className = "mx_RoomTileTooltip_wrapper";
        document.body.appendChild(this.tooltipContainer);

        this._renderTooltip();

        // tell the roomlist about us so it can position us
        dis.dispatch({
            action: 'view_tooltip',
            tooltip: this.tooltip,
            parent: this.props.component ? ReactDOM.findDOMNode(this.props.component) : null,
        });
    },

    // Remove the wrapper element, as the tooltip has finished using it
    componentWillUnmount: function() {
        dis.dispatch({
            action: 'view_tooltip',
            tooltip: null,
            parent: null,
        });

        ReactDOM.unmountComponentAtNode(this.tooltipContainer);
        document.body.removeChild(this.tooltipContainer);
    },

    _renderTooltip: function() {
        var label = this.props.room ? this.props.room.name : this.props.label;
        var tooltip = (
            <div className="mx_RoomTooltip">
                 <img className="mx_RoomTooltip_chevron" src="img/chevron-left.png" width="9" height="16"/>
                 { label }
            </div>
        );

        this.tooltip = ReactDOM.render(tooltip, this.tooltipContainer);
    },

    render: function() {<commit_msg>Tweak of the RoomTooltip to use DOM element for the parent rather than a React component<commit_after>/*
Copyright 2015, 2016 OpenMarket Ltd

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

'use strict';

var React = require('react');
var ReactDOM = require('react-dom');

var dis = require('matrix-react-sdk/lib/dispatcher');

module.exports = React.createClass({
    displayName: 'RoomTooltip',

    propTypes: {
        parent: React.PropTypes.object.isRequired,
        room: React.PropTypes.object,
        label: React.PropTypes.string,
    },

    // Create a wrapper for the tooltip outside the main matrix element
    componentDidMount: function() {
        this.tooltipContainer = document.createElement("div");
        this.tooltipContainer.className = "mx_RoomTileTooltip_wrapper";
        document.body.appendChild(this.tooltipContainer);

        // don't render tooltip if parent is undefined
        if (this.props.parent) {
            this._renderTooltip();

            // tell the roomlist about us so it can position us
            dis.dispatch({
                action: 'view_tooltip',
                tooltip: this.tooltip,
                parent: this.props.parent,
            });
        }
    },

    // Remove the wrapper element, as the tooltip has finished using it
    componentWillUnmount: function() {
        dis.dispatch({
            action: 'view_tooltip',
            tooltip: null,
            parent: null,
        });

        ReactDOM.unmountComponentAtNode(this.tooltipContainer);
        document.body.removeChild(this.tooltipContainer);
    },

    _renderTooltip: function() {
        var label = this.props.room ? this.props.room.name : this.props.label;
        var tooltip = (
            <div className="mx_RoomTooltip">
                 <img className="mx_RoomTooltip_chevron" src="img/chevron-left.png" width="9" height="16"/>
                 { label }
            </div>
        );

        this.tooltip = ReactDOM.render(tooltip, this.tooltipContainer);
    },

    render: function() {
{'fraction_non_alphanumeric': 0.09716268626250255, 'fraction_numerical': 0.00612369871402327, 'mean_word_length': 2.6539895600298284, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6707721', 'n_tokens_mistral': 1306, 'n_tokens_neox': 1258, 'n_words': 400}