<commit_before>'use strict';

var CARD = {
    audio: {},
    // clipLength: 30,
    paused: true,
    player: {},
    playerElement: '',
    // timecode: 0,
    // timer: 0,

    init: function() {
        // this.timecode = 0;

        // If we can't autoplay, we're probably on a mobile
        // device. Initialize the fallback video and exit.
        if ( ! Modernizr.videoautoplay ) {
            this.player = new MediaElementPlayer('[data-fallback-video]');

            return;
        }

        this.audioElement = '[data-audio-player]';
        this.playerElement = '[data-video-player]';
        this.initPlayers();

        $('body').fitVids();

        // Listen for clip clicks
        $('[data-video]').on('click', function(e) {
            e.preventDefault();

            var video = $(e.currentTarget).data('video');

            this.swapVideo(video);
        }.bind(this));

        $(this.playerElement).on('pause', function() {
            // this.pauseTimer();
            this.pauseAudio();
        }.bind(this));

        $(this.playerElement).on('playing', function() {
            // console.log('playing');
            // this.startTimer();
            this.startAudio();
        }.bind(this));
    },

    initPlayers: function() {
        this.player = new MediaElementPlayer(this.playerElement, {
            features: [],
            pauseOtherPlayers: false
        });
        this.audio = new MediaElementPlayer(this.audioElement, {
            features: [],
            pauseOtherPlayers: false
        });
    },

    pauseAudio: function() {
        this.audio.pause();
    },

    pauseTimer: function() {
        window.clearInterval(this.timer);

        this.paused = true;

        console.log('Timer paused');

        return this.timer;
    },

    restartPlayer: function() {
        this.player.setCurrentTime(0);
        this.player.play();
    },

    startAudio: function() {
        this.audio.play();
    },

    startTimer: function() {
        // Bail if there's already a timer running
        if ( ! this.paused ) {
            return;
        }

        this.timer = window.setInterval( this.updateTimecode.bind(this), 1000 );

        this.paused = false;

        console.log('Timer started');

        return this.timer;
    },

    swapVideo: function( video ) {
        // Set the new video source
        // console.log(video);
        this.player.setSrc(video);

        // Pick up where we are in the current timecode
        // this.player.setCurrentTime( this.timecode );
        this.player.play();
    },

    updateTimecode: function() {

        if ( ++this.timecode > this.clipLength ) {
            this.timecode = 0;

            // Set video to beginning, too.
            this.restartPlayer();
        }

        console.log(this.timecode);

        return this.timecode;
    }
};

$(document).ready(function() {
    CARD.init();
});<commit_msg>Add comments and remove extra stuff<commit_after>'use strict';

var CARD = {
    audio: {},
    paused: true,
    player: {},
    playerElement: '',

    /**
     * Initialize function
     * @return {object} This
     */
    init: function() {
        // If we can't autoplay, we're probably on a mobile
        // device. Initialize the fallback video and exit.
        if ( ! Modernizr.videoautoplay ) {
            this.player = new MediaElementPlayer('[data-fallback-video]');

            return;
        }

        this.audioElement = '[data-audio-player]';
        this.playerElement = '[data-video-player]';
        this.initPlayers();

        $('body').fitVids();

        // Listen for clip clicks
        $('[data-video]').on('click', function(e) {
            e.preventDefault();

            var video = $(e.currentTarget).data('video');

            this.swapVideo(video);
        }.bind(this));

        $(this.playerElement).on('pause', function() {
            this.pauseAudio();
        }.bind(this));

        $(this.playerElement).on('playing', function() {
            this.startAudio();
        }.bind(this));

        return this;
    },

    /**
     * Initialize the audio and video players
     * @return {object} this
     */
    initPlayers: function() {
        this.player = new MediaElementPlayer(this.playerElement, {
            features: [],
            pauseOtherPlayers: false
        });
        this.audio = new MediaElementPlayer(this.audioElement, {
            features: [],
            pauseOtherPlayers: false
        });

        return this;
    },

    /**
     * Pause the audio player
     * @return {object} this
     */
    pauseAudio: function() {
        this.audio.pause();

        return this;
    },

    /**
     * Restart a player
     * @return {object} this
     */
    restartPlayer: function() {
        this.player.setCurrentTime(0);
        this.player.play();

        return this;
    },

    /**
     * Start the audio
     * @return {object} this
     */
    startAudio: function() {
        this.audio.play();

        return this;
    },

    /**
     * Switch out the video with the selected one
     * @param  {string} video Video URL
     * @return {object}       this
     */
    swapVideo: function( video ) {
        // Set the new video source
        this.player.setSrc(video);
        this.player.play();

        return this;
    },
};

// Kick it off when we're loaded
$(document).ready(function() {
    CARD.init();
});
{'fraction_non_alphanumeric': 0.14335728763589461, 'fraction_numerical': 0.002211166390270868, 'mean_word_length': 1.748354430379747, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '5721221', 'n_tokens_mistral': 1582, 'n_tokens_neox': 1498, 'n_words': 332}