<commit_before>(function() {

  this.Player = function() {

    var defaults = {
        videoId: null,
        playerClass: 'custom-player',
        extraClass: null,
        width: 480,
        height: 270,
        autoPlay: null,
        controls: null,
        relatedVideos: 0,
        showInfo: null,
        wrap: null,
        wrapClass: 'custom-player-wrapper',
        playButton: null,
        playButtonClass: 'play-button',
        playButtonText: 'Play',
        pauseButton: null,
        pauseButtonText: 'Pause',
        mute: null,
        placement: null
    };
  
    // Add our defaults above into a global array of options
    if ( arguments[0] && typeof arguments[0] === 'object' ) {
      this.options = extendDefaults( defaults, arguments[0] );
    }

    if( document.readyState !== 'complete' ) {
      document.addEventListener('DOMContentLoaded', (this.init).bind(this), false);
    } else {
      // Run Player.init()
      this.init();
    }

  };

  Player.prototype.init = function() {

    var this_ = this;

    // If any extraClass names have been added add them
    var extraClass = this_.options.extraClass,
        classCheck = extraClass === null,
        addExtraClass = classCheck ? '' : ' ' + extraClass;

    if ( !document.getElementById( this_.options.videoId ) ) {
      this.generateEl( 'div', this_.options.videoId, this_.options.playerClass + addExtraClass );
    }

    // Generate the wrapper
    if ( this_.options.wrap || this_.options.wrapClass ) {
      this.wrapper = document.createElement( 'div' );
      this.wrapper.className = this_.options.wrapClass;
      this.customPlayer = document.getElementById( this_.options.videoId );
      this.wrapper.appendChild( this.customPlayer.cloneNode( true ) );
      this.customPlayer.parentNode.replaceChild( this.wrapper, this.customPlayer );
    }

    var callback = ( function() {
      this_.player = new YT.Player( this_.options.videoId, {
        videoId: this_.options.videoId,
        height: this_.options.height,
        width: this_.options.width,
        playerVars: {
          autoplay: this_.options.autoPlay,
          controls: this_.options.controls,
          rel: this_.options.relatedVideos,
          showinfo: this_.options.showInfo,
        },
        events: {
          onReady: ( this_._onPlayerReady ).bind( this ),
          onStateChange: ( this_._onStateChange ).bind( this )
        }
      });
      
      // Load custom controls
      if ( this_.options.playButton || this_.options.pauseButton ) {
        this_.customControls();
      }
    }).bind( this );

    // Test if the youtube api is loaded
    if ( 'YT' in window ) {
      if ( window.YT.loaded === 0 ) {
        if ( window.onYouTubePlayerAPIReady ) {
          var oldonYouTubePlayerAPIReady = window.onYouTubePlayerAPIReady;
        }
        window.onYouTubePlayerAPIReady = function() {
          if ( window.onYouTubePlayerAPIReady ) {
            oldonYouTubePlayerAPIReady();
          }
          callback();
        };
      } else {
        callback();
      }
    } else {
      window.YT = {
        loaded: 0
      };

      window.onYouTubePlayerAPIReady = function() {
        callback();
      };

      var tag = document.createElement( 'script' );

      tag.src = 'https://www.youtube.com/iframe_api';
      var firstScriptTag = document.getElementsByTagName( 'script' )[0];
      firstScriptTag.parentNode.insertBefore( tag, firstScriptTag );
    }

  };

  // Controls
  Player.prototype.customControls = function() {
    var this_ = this,
        customControlsClass = 'custom-controls',
        customControlsSelector = '.' + customControlsClass;

    // Cache the created element so we know which is which
    // when multiple videos are present
    this.videoControls = this.generateEl( 'div', null, customControlsClass );

    // If there is a wrapper add the controls inside it
    if ( this_.options.wrap ) {
      var wrapper = document.querySelector( '.' + this_.options.wrapClass ),
          controls = document.querySelector( customControlsSelector );

      wrapper.appendChild( controls );
    }

    // Play button
    if ( this_.options.playButton ) {
      var playButtonEl;

      playButtonEl = document.createElement( 'button' );
      playButtonEl.innerHTML = this_.options.playButtonText;
      playButtonEl.className = this_.options.videoID + '-' + this_.options.playButtonClass;
      this.videoControls.appendChild( playButtonEl );

      document.querySelector( '.' + this_.options.playButton ).addEventListener( 'click', function() {
        this_.player.playVideo();
      });
    }

    // Pause video
    if ( this_.options.pauseButton ) {
      var pauseButtonEl;

      pauseButtonEl = document.createElement( 'button' );
      pauseButtonEl.innerHTML = this_.options.pauseButtonText;
      pauseButtonEl.className = this_.options.pauseButtonClass;
      this.videoControls.appendChild( pauseButtonEl );

      document.querySelector( '.' + this_.options.pauseButton ).addEventListener( 'click', function() {
        this_.player.pauseVideo();
      });
    }

  };

  // Events
  // Player ready
  Player.prototype._onPlayerReady = function( event ) {
    if ( this.options.mute === 1) {
      event.target.mute();
    }
  };
  // Player state change
  Player.prototype._onStateChange = function( event ) {};


  // Private Methods

  // Build the necessary markup
  // and inject it into the document if needed<commit_msg>Set up class variable for play/ pause buttons<commit_after>(function() {

  this.Player = function() {

    var defaults = {
        videoId: null,
        playerClass: 'custom-player',
        extraClass: null,
        width: 480,
        height: 270,
        autoPlay: null,
        controls: null,
        relatedVideos: 0,
        showInfo: null,
        wrap: null,
        wrapClass: 'custom-player-wrapper',
        playButton: null,
        playButtonClass: 'play-button',
        playButtonText: 'Play',
        pauseButton: null,
        pauseButtonText: 'Pause',
        mute: null,
        placement: null
    };
  
    // Add our defaults above into a global array of options
    if ( arguments[0] && typeof arguments[0] === 'object' ) {
      this.options = extendDefaults( defaults, arguments[0] );
    }

    if( document.readyState !== 'complete' ) {
      document.addEventListener('DOMContentLoaded', (this.init).bind(this), false);
    } else {
      // Run Player.init()
      this.init();
    }

  };

  Player.prototype.init = function() {

    var this_ = this;

    // If any extraClass names have been added add them
    var extraClass = this_.options.extraClass,
        classCheck = extraClass === null,
        addExtraClass = classCheck ? '' : ' ' + extraClass;

    if ( !document.getElementById( this_.options.videoId ) ) {
      this.generateEl( 'div', this_.options.videoId, this_.options.playerClass + addExtraClass );
    }

    // Generate the wrapper
    if ( this_.options.wrap || this_.options.wrapClass ) {
      this.wrapper = document.createElement( 'div' );
      this.wrapper.className = this_.options.wrapClass;
      this.customPlayer = document.getElementById( this_.options.videoId );
      this.wrapper.appendChild( this.customPlayer.cloneNode( true ) );
      this.customPlayer.parentNode.replaceChild( this.wrapper, this.customPlayer );
    }

    var callback = ( function() {
      this_.player = new YT.Player( this_.options.videoId, {
        videoId: this_.options.videoId,
        height: this_.options.height,
        width: this_.options.width,
        playerVars: {
          autoplay: this_.options.autoPlay,
          controls: this_.options.controls,
          rel: this_.options.relatedVideos,
          showinfo: this_.options.showInfo,
        },
        events: {
          onReady: ( this_._onPlayerReady ).bind( this ),
          onStateChange: ( this_._onStateChange ).bind( this )
        }
      });
      
      // Load custom controls
      if ( this_.options.playButton || this_.options.pauseButton ) {
        this_.customControls();
      }
    }).bind( this );

    // Test if the youtube api is loaded
    if ( 'YT' in window ) {
      if ( window.YT.loaded === 0 ) {
        if ( window.onYouTubePlayerAPIReady ) {
          var oldonYouTubePlayerAPIReady = window.onYouTubePlayerAPIReady;
        }
        window.onYouTubePlayerAPIReady = function() {
          if ( window.onYouTubePlayerAPIReady ) {
            oldonYouTubePlayerAPIReady();
          }
          callback();
        };
      } else {
        callback();
      }
    } else {
      window.YT = {
        loaded: 0
      };

      window.onYouTubePlayerAPIReady = function() {
        callback();
      };

      var tag = document.createElement( 'script' );

      tag.src = 'https://www.youtube.com/iframe_api';
      var firstScriptTag = document.getElementsByTagName( 'script' )[0];
      firstScriptTag.parentNode.insertBefore( tag, firstScriptTag );
    }

  };

  // Controls
  Player.prototype.customControls = function() {
    var this_ = this,
        customControlsClass = 'custom-controls',
        customControlsSelector = '.' + customControlsClass;

    // Cache the created element so we know which is which
    // when multiple videos are present
    this.videoControls = this.generateEl( 'div', null, customControlsClass );

    // If there is a wrapper add the controls inside it
    if ( this_.options.wrap ) {
      var wrapper = document.querySelector( '.' + this_.options.wrapClass ),
          controls = document.querySelector( customControlsSelector );

      wrapper.appendChild( controls );
    }

    // Play button
    if ( this_.options.playButton ) {
      var playButtonEl;

      playButtonEl = document.createElement( 'button' );
      playButtonEl.innerHTML = this_.options.playButtonText;
      // Store class name of button
      playButtonClass = playButtonEl.className = this_.options.videoID + '-' + this_.options.playButtonClass;
      this.videoControls.appendChild( playButtonEl );

      document.querySelector( '.' + playButtonClass ).addEventListener( 'click', function() {
        this_.player.playVideo();
      });
    }

    // Pause video
    if ( this_.options.pauseButton ) {
      var pauseButtonEl;

      pauseButtonEl = document.createElement( 'button' );
      pauseButtonEl.innerHTML = this_.options.pauseButtonText;
      // Store class name of button
      pauseButtonClass = pauseButtonEl.className = this_.options.videoID + '-' + this_.options.pauseButtonClass;
      this.videoControls.appendChild( pauseButtonEl );

      document.querySelector( '.' + pauseButtonClass ).addEventListener( 'click', function() {
        this_.player.pauseVideo();
      });
    }

  };

  // Events
  // Player ready
  Player.prototype._onPlayerReady = function( event ) {
    if ( this.options.mute === 1) {
      event.target.mute();
    }
  };
  // Player state change
  Player.prototype._onStateChange = function( event ) {};


  // Private Methods

  // Build the necessary markup
  // and inject it into the document if needed
{'fraction_non_alphanumeric': 0.1170433060232286, 'fraction_numerical': 0.0025209327451156927, 'mean_word_length': 2.3742405832320777, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '565561', 'n_tokens_mistral': 3107, 'n_tokens_neox': 3050, 'n_words': 685}