<commit_before>﻿$.UI = $.UI || {};
$.UI.Player = {
    _player: null,
    _currentItem: null,
    _initialItem: null,
    _$title: null,

    Init: function (onSuccess) {
        var pl = $.UI.Player;

        pl._$title = $(".player_header");

        $('<script>')
            .attr({
                "type": "text/javascript",
                "src": "https://www.youtube.com/player_api"
            })
            .appendTo('head');

        window.onYouTubePlayerAPIReady = function() {
            pl._player = new YT.Player('ytplayer', {
                videoId: pl._initialItem ? pl._initialItem.yId : "guXMb7zLblM",
                playerVars: {
                    rel: 0,
                    showinfo: 0
                },
                events: {
                    onReady: pl.OnPlayerReady,
                    onStateChange: pl.OnPlayerStateChange,
                    onError: pl.OnPlayerError
                }
            });

            pl._$title.html(pl._initialItem ? pl._initialItem.name : "");
        };

        $.isFunction(onSuccess) && onSuccess();
    },
    Play: function(item) {
        var pl = $.UI.Player;

        if (!pl._player || !pl._player.loadVideoById) {
            pl._initialItem = item;
            return;
        }

        pl._player.loadVideoById(item.yId);
        pl._$title.html(item.name);
        pl._currentItem = item;
    },
    GetCurrentItem: function() {
        return $.UI.Player._currentItem;
    },

    OnPlayerReady: function () {
        $.UI.Player._player.playVideo();
    },
    OnPlayerStateChange: function (a) {
        if (a.data === 0) {
            $.UI.Player._player.playVideo();
        }
    },
    OnPlayerError: function () {
        if (!ga) {
            return;
        }

        ga('send', 'exception', { 'exDescription': "Player doesn't feel well" });
    }
};<commit_msg>Fix player initialization<commit_after>﻿$.UI = $.UI || {};
$.UI.Player = {
    _player: null,
    _currentItem: null,
    _initialItem: null,
    _$title: null,

    Init: function (onSuccess) {
        var pl = $.UI.Player;

        pl._$title = $(".player_header");

        $('<script>')
            .attr({
                "type": "text/javascript",
                "src": "https://www.youtube.com/player_api"
            })
            .appendTo('head');

        window.onYouTubePlayerAPIReady = function() {
            pl._player = new YT.Player('ytplayer', {
                videoId: "guXMb7zLblM",
                playerVars: {
                    rel: 0,
                    showinfo: 0
                },
                events: {
                    onReady: pl.OnPlayerReady,
                    onStateChange: pl.OnPlayerStateChange,
                    onError: pl.OnPlayerError
                }
            });
        };

        $.isFunction(onSuccess) && onSuccess();
    },
    Play: function(item) {
        var pl = $.UI.Player;

        if (!pl._player || !pl._player.loadVideoById) {
            pl._initialItem = item;
            return;
        }

        pl._player.loadVideoById(item.yId);
        pl._$title.html(item.name);
        pl._currentItem = item;
    },
    GetCurrentItem: function() {
        return $.UI.Player._currentItem;
    },

    OnPlayerReady: function () {
        var pl = $.UI.Player;

        if (pl._initialItem) {
            pl.Play(pl._initialItem);
        }

        $.UI.Player._player.playVideo();
    },
    OnPlayerStateChange: function (a) {
        if (a.data === 0) {
            $.UI.Player._player.playVideo();
        }
    },
    OnPlayerError: function () {
        if (!ga) {
            return;
        }

        ga('send', 'exception', { 'exDescription': "Player doesn't feel well" });
    }
};
{'fraction_non_alphanumeric': 0.1441947565543071, 'fraction_numerical': 0.002140181915462814, 'mean_word_length': 1.4294996751137101, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, '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': '6557916', 'n_tokens_mistral': 1125, 'n_tokens_neox': 1076, 'n_words': 188}