<commit_before>import React, { PureComponent, PropTypes } from 'react';
import { findDOMNode } from 'react-dom';
import TransitionGroup from 'react-addons-transition-group';
import cn from 'classnames';

import { TAB } from '../constants/keyCodes';
import Tooltip from './Tooltip';

export default class TooltipContainer extends PureComponent {
  static propTypes = {
    style: PropTypes.object,
    className: PropTypes.string,
    tooltipStyle: PropTypes.object,
    tooltipClassName: PropTypes.string,
    label: PropTypes.node.isRequired,
    position: Tooltip.propTypes.position,
    delay: PropTypes.number.isRequired,
    enterTimeout: PropTypes.number.isRequired,
    leaveTimeout: PropTypes.number.isRequired,
  };

  constructor(props) {
    super(props);

    this.state = { visible: false };
    this._delayedTimeout = null;

    this._setContainers = this._setContainers.bind(this);
    this._showTooltip = this._showTooltip.bind(this);
    this._hideTooltip = this._hideTooltip.bind(this);
    this._stopContextMenu = this._stopContextMenu.bind(this);
    this._handleKeyUp = this._handleKeyUp.bind(this);
  }

  componentWillUnmount() {
    if (this._container) {
      this._container.removeEventListener('mouseover', this._showTooltip);
      this._container.removeEventListener('mouseleave', this._hideTooltip);
      this._container.removeEventListener('touchstart', this._showTooltip);
      this._container.removeEventListener('touchend', this._hideTooltip);
      this._container.removeEventListener('keyup', this._handleKeyUp);
      this._container.removeEventListener('blur', this._hideTooltip);
    }
  }

  _setContainers(container) {
    if (container) {
      this._container = findDOMNode(container).parentNode;

      this._container.addEventListener('mouseover', this._showTooltip);
      this._container.addEventListener('mouseleave', this._hideTooltip);
      this._container.addEventListener('touchstart', this._showTooltip);
      this._container.addEventListener('touchend', this._hideTooltip);
      this._container.addEventListener('keyup', this._handleKeyUp);
      this._container.addEventListener('blur', this._hideTooltip);
    }
  }

  _stopContextMenu(e) {
    e.preventDefault();
    window.removeEventListener('contextmenu', this._stopContextMenu, true);
  }

  _showTooltip(e) {
    if (e.type === 'mouseover' && this._touched) {
      return;
    }

    if (e.type === 'touchstart') {
      this._touched = true;

      window.addEventListener('contextmenu', this._stopContextMenu, true);
    }


    const { delay } = this.props;
    if (this._delayedTimeout) {
      clearTimeout(this._delayedTimeout);
    }

    if (delay) {
      this._delayedTimeout = setTimeout(() => {
        this._delayedTimeout = null;

        this.setState({ visible: true });
      }, delay);
    } else {
      this.setState({ visible: true });
    }
  }

  _hideTooltip(e) {
    if (this._delayedTimeout) {
      clearTimeout(this._delayedTimeout);
    }

    if (e.type === 'mouseover' && this._touched) {<commit_msg>Updated Tooltip Behavior on Touch Devices<commit_after>import React, { PureComponent, PropTypes } from 'react';
import { findDOMNode } from 'react-dom';
import TransitionGroup from 'react-addons-transition-group';
import cn from 'classnames';

import { TAB } from '../constants/keyCodes';
import captureNextEvent from '../utils/EventUtils/captureNextEvent';
import Tooltip from './Tooltip';

export default class TooltipContainer extends PureComponent {
  static propTypes = {
    style: PropTypes.object,
    className: PropTypes.string,
    tooltipStyle: PropTypes.object,
    tooltipClassName: PropTypes.string,
    label: PropTypes.node.isRequired,
    position: Tooltip.propTypes.position,
    delay: PropTypes.number.isRequired,
    enterTimeout: PropTypes.number.isRequired,
    leaveTimeout: PropTypes.number.isRequired,
  };

  constructor(props) {
    super(props);

    this.state = { visible: false };
    this._delayedTimeout = null;

    this._setContainers = this._setContainers.bind(this);
    this._showTooltip = this._showTooltip.bind(this);
    this._hideTooltip = this._hideTooltip.bind(this);
    this._stopContextMenu = this._stopContextMenu.bind(this);
    this._handleKeyUp = this._handleKeyUp.bind(this);
  }

  componentWillUnmount() {
    if (this._container) {
      this._container.removeEventListener('mouseover', this._showTooltip);
      this._container.removeEventListener('mouseleave', this._hideTooltip);
      this._container.removeEventListener('touchstart', this._showTooltip);
      this._container.removeEventListener('touchend', this._hideTooltip);
      this._container.removeEventListener('keyup', this._handleKeyUp);
      this._container.removeEventListener('blur', this._hideTooltip);
    }
  }

  _setContainers(container) {
    if (container) {
      this._container = findDOMNode(container).parentNode;

      this._container.addEventListener('mouseover', this._showTooltip);
      this._container.addEventListener('mouseleave', this._hideTooltip);
      this._container.addEventListener('touchstart', this._showTooltip);
      this._container.addEventListener('touchend', this._hideTooltip);
      this._container.addEventListener('keyup', this._handleKeyUp);
      this._container.addEventListener('blur', this._hideTooltip);
    }
  }

  _stopContextMenu(e) {
    e.preventDefault();
    window.removeEventListener('contextmenu', this._stopContextMenu, true);
    captureNextEvent('click');
    this.setState({ visible: true });
  }

  _showTooltip(e) {
    if (e.type === 'mouseover' && this._touched) {
      return;
    }

    if (e.type === 'touchstart') {
      this._touched = true;

      window.addEventListener('contextmenu', this._stopContextMenu, true);
      return;
    }


    const { delay } = this.props;
    if (this._delayedTimeout) {
      clearTimeout(this._delayedTimeout);
    }

    if (delay) {
      this._delayedTimeout = setTimeout(() => {
        this._delayedTimeout = null;

        this.setState({ visible: true });
      }, delay);
    } else {
      this.setState({ visible: true });
    }
  }

  _hideTooltip(e) {
    if (this._delayedTimeout) {
      clearTimeout(this._delayedTimeout);
    }

    if (e.type === 'mouseover' && this._touched) {
{'fraction_non_alphanumeric': 0.126870423432028, 'fraction_numerical': 0.0, 'mean_word_length': 3.7670713201820942, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5611182', 'n_tokens_mistral': 1793, 'n_tokens_neox': 1803, 'n_words': 310}