<commit_before>// (C) Copyright 2014-2015 Hewlett Packard Enterprise Development LP

var React = require('react');
var ReactDOM = require('react-dom');
var merge = require('lodash/object/merge');
var pick = require('lodash/object/pick');
var keys = require('lodash/object/keys');
var Box = require('./Box');
var KeyboardAccelerators = require('../utils/KeyboardAccelerators');
var DOM = require('../utils/DOM');
var Scroll = require('../utils/Scroll');
var SkipLinkAnchor = require('./SkipLinkAnchor');

var CLASS_ROOT = "article";

var Article = React.createClass({

  propTypes: merge({
    scrollStep: React.PropTypes.bool,
    primary: React.PropTypes.bool
  }, Box.propTypes),

  getDefaultProps: function () {
    return {
      pad: 'none',
      direction: 'column'
    };
  },

  componentDidMount: function () {
    if (this.props.scrollStep) {
      this._markInactive();
      var articleElement = ReactDOM.findDOMNode(this.refs.component);
      this._scrollParent = DOM.findScrollParents(articleElement)[0];
      document.addEventListener('wheel', this._onWheel);
      this._scrollParent.addEventListener('scroll', this._onScroll);
      KeyboardAccelerators.startListeningToKeyboard(this, {
        up: this._onUp,
        down: this._onDown
      });
    }
  },

  componentWillUnmount: function () {
    if (this.props.scrollStep) {
      document.removeEventListener('wheel', this._onWheel);
      clearInterval(this._scrollToTimer);
      this._scrollParent.removeEventListener('scroll', this._onScroll);
      clearTimeout(this._scrollTimer);
      KeyboardAccelerators.stopListeningToKeyboard(this, {
        up: this._onUp,
        down: this._onDown
      });
    }
  },

  _markInactive: function () {
    var articleElement = ReactDOM.findDOMNode(this.refs.component);
    var sections = articleElement.querySelectorAll('.section.box--full');
    for (var i = 0; i < sections.length; i += 1) {
      var section = sections[i];
      var rect = section.getBoundingClientRect();
      if (rect.top > (window.innerHeight - 10)) {
        section.classList.add('section--inactive');
      } else {
        section.classList.remove('section--inactive');
      }
    }
  },

  _onScroll: function (event) {
    clearTimeout(this._scrollTimer);
    this._scrollTimer = setTimeout(this._markInactive, 50);
  },

  _onWheel: function (event) {
    if (Math.abs(event.deltaY) > 100) {
      clearInterval(this._scrollTimer);
    } else if (event.deltaY > 5) {
      this._onDown();
    } else if (event.deltaY < -5) {
      this._onUp();
    }
  },

  _onDown: function (event) {<commit_msg>Fix jumpy wheel interactions for scrollStep Article.<commit_after>// (C) Copyright 2014-2015 Hewlett Packard Enterprise Development LP

var React = require('react');
var ReactDOM = require('react-dom');
var merge = require('lodash/object/merge');
var pick = require('lodash/object/pick');
var keys = require('lodash/object/keys');
var Box = require('./Box');
var KeyboardAccelerators = require('../utils/KeyboardAccelerators');
var DOM = require('../utils/DOM');
var Scroll = require('../utils/Scroll');
var SkipLinkAnchor = require('./SkipLinkAnchor');

var CLASS_ROOT = "article";

var Article = React.createClass({

  propTypes: merge({
    scrollStep: React.PropTypes.bool,
    primary: React.PropTypes.bool
  }, Box.propTypes),

  getDefaultProps: function () {
    return {
      pad: 'none',
      direction: 'column'
    };
  },

  componentDidMount: function () {
    if (this.props.scrollStep) {
      var articleElement = ReactDOM.findDOMNode(this.refs.component);
      this._scrollParent = DOM.findScrollParents(articleElement)[0];
      document.addEventListener('wheel', this._onWheel);
      KeyboardAccelerators.startListeningToKeyboard(this, {
        up: this._onUp,
        down: this._onDown
      });
    }
  },

  componentWillUnmount: function () {
    if (this.props.scrollStep) {
      document.removeEventListener('wheel', this._onWheel);
      KeyboardAccelerators.stopListeningToKeyboard(this, {
        up: this._onUp,
        down: this._onDown
      });
    }
  },

  _onWheel: function (event) {
    if (Math.abs(event.deltaY) > 100) {
      // The user is expressing a resolute interest in controlling the
      // scrolling behavior. Stop doing any of our scroll step aligning
      // until he stops expressing such interest.
      clearInterval(this._wheelTimer);
      clearInterval(this._wheelLongTimer);
      this._wheelLongTimer = setTimeout(function () {
        this._wheelLongTimer = null;
      }.bind(this), 2000);
    } else if (! this._wheelLongTimer) {
      if (event.deltaY > 5) {
        clearInterval(this._wheelTimer);
        this._wheelTimer = setTimeout(this._onDown, 50);
      } else if (event.deltaY < -5) {
        clearInterval(this._wheelTimer);
        this._wheelTimer = setTimeout(this._onUp, 50);
      }
    }
  },

  _onDown: function (event) {
{'fraction_non_alphanumeric': 0.1373425436814303, 'fraction_numerical': 0.008533116619260463, 'mean_word_length': 3.24031007751938, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1657033', 'n_tokens_mistral': 1514, 'n_tokens_neox': 1457, 'n_words': 302}