<commit_before>'use strict';

function WatchEvents(options) {
  this.mainView = document.querySelector('#appMountPoint');
  this.onPlay = options.onPlay;
  this.onPause = options.onPause;
  this.onStop = options.onStop;
}

WatchEvents.prototype = {
  startListeners: function() {
    this.addPlayPauseListener();
    this.addStopListener();
  },

  stopListeners: function() {
    this.removePlayPauseListener();
    this.removeStopListener();
  },

  addPlayPauseListener: function() {
    this.mainView.addEventListener('click', this.onPlayPause.bind(this), false);
  },

  addStopListener: function() {
    window.onpopstate = this.onStop;
    window.onbeforeunload = function() {
      this.onStop();
      this.stopListeners();
    }.bind(this)
  },

  onPlayPause: function(e) {
    if (e.target.classList.contains('play')) {
      this.onPlay(e);
    } else if (e.target.classList.contains('pause')) {
      this.onPause(e);
    } else if (e.target.classList.contains('player-next-episode')) {
      this.onStop(e);
      this.onPlay(e);
    } else if (e.target.className === 'player-scrubber-target' ||
        e.target.className === 'player-scrubber-progress-completed' ||
        e.target.className === 'player-scrubber-progress-buffered' ||
        e.target.className === 'player-scrubber-progress') {
      this.onPlay(e);
    } else if (e.target.className === 'play-icon') {
      this.onStop(e);
      this.onPlay(e);
    }
  },

  removePlayPauseListener: function() {
    this.mainView.removeEventListener('click', this.onPlayPause.bind(this), false);
  },

  removeStopListener: function() {
    window.onpopstate = null;
    window.onbeforeunload = null;
  }
};

module.exports = WatchEvents;<commit_msg>Added Keyboard events to WatchEvents<commit_after>'use strict';

var KEY_SPACE = 32;
var KEY_ENTER = 13;
var KEY_PAGE_UP = 33;
var KEY_PAGE_DOWN = 34;
var KEY_LEFT_ARROW = 37;
var KEY_RIGHT_ARROW = 39;

function WatchEvents(options) {
  this.document = document;
  this.onPlay = options.onPlay;
  this.onPause = options.onPause;
  this.onStop = options.onStop;
}

WatchEvents.prototype = {
  startListeners: function() {
    this.addClickListener();
    this.addStopListener();
    this.addKeyUpListener();
  },

  stopListeners: function() {
    this.removeClickListener();
    this.removeStopListener();
    this.removeKeyUpListener();
  },

  addClickListener: function() {
    this.document.addEventListener('click', this.onClick.bind(this), false);
  },

  addStopListener: function() {
    window.onpopstate = this.onStop;
    window.onbeforeunload = function() {
      this.onStop();
      this.stopListeners();
    }.bind(this)
  },

  addKeyUpListener: function() {
    this.document.addEventListener('keyup', this.onKeyUp.bind(this), false);
  },

  onClick: function(e) {
    if (e.target.classList.contains('play')) {
      this.onPlay(e);
    } else if (e.target.classList.contains('pause')) {
      this.onPause(e);
    } else if (e.target.classList.contains('player-next-episode')) {
      this.onStop(e);
      this.onPlay(e);
    } else if (e.target.className === 'player-scrubber-target' ||
        e.target.className === 'player-scrubber-progress-completed' ||
        e.target.className === 'player-scrubber-progress-buffered' ||
        e.target.className === 'player-scrubber-progress') {
      this.isPlaying() ? this.onPause(e) : this.onPlay(e);
    } else if (e.target.className === 'play-icon') {
      this.onStop(e);
      this.onPlay(e);
    }
  },

  onKeyUp: function(e) {
    switch (e.which) {
      case KEY_SPACE:
        this.isPlaying() ? this.onPause(e) : this.onPlay(e);
        break;
      case KEY_ENTER:
        this.isPlaying() ? this.onPause(e) : this.onPlay(e);
        break;
      case KEY_PAGE_UP:
        this.onPlay(e);
        break;
      case KEY_PAGE_DOWN:
        this.onPause(e);
        break;
      case KEY_LEFT_ARROW:
        this.onPause(e);
        break;
      case KEY_RIGHT_ARROW:
        this.onPause(e);
        break;
    }
  },

  removeClickListener: function() {
    this.document.removeEventListener('click', this.onClick.bind(this), false);
  },

  removeStopListener: function() {
    window.onpopstate = null;
    window.onbeforeunload = null;
  },

  removeKeyUpListener: function() {
    this.document.removeEventListener('keyup', this.onKeyUp.bind(this), false);
  },

  isPlaying: function() {
    var playPause = this.document.querySelector('.player-play-pause');
    return playPause && playPause.classList.contains('play');
  }
};

module.exports = WatchEvents;
{'fraction_non_alphanumeric': 0.15177398160315375, 'fraction_numerical': 0.002628120893561104, 'mean_word_length': 3.209216589861751, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2951902', 'n_tokens_mistral': 1528, 'n_tokens_neox': 1504, 'n_words': 233}