<commit_before>'use strict';
/* Services */
var KMCServices = angular.module('KMC.services', []);

KMCServices.config(['$httpProvider', function($httpProvider) {
    $httpProvider.defaults.useXDomain = true;
    delete $httpProvider.defaults.headers.common['X-Requested-With'];
}]);

KMCServices.factory('apiCache', function($cacheFactory) {
    return $cacheFactory('apiCache', {
        capacity: 10
    });
});

KMCServices.factory('sortSvc', [function() {
    var containers = {};
    var sorter = {};

    var Container = function Container(name) {
        this.name = name;
        this.elements = [];
        containers[name] = this;
    };
    Container.prototype.addElement = function(model) {
        this.elements.push(model);
    };
    Container.prototype.callObjectsUpdate = function() {
        angular.forEach(this.elements, function(model) {
            cl(model.sortVal + ' ' + model.model);
        });
    };
    Container.prototype.removeElement = function(model) {
        var index = this.elements.indexOf(model);
        if (index != -1)
            this.elements.splice(index, 1);
    };
    sorter.sortScope = '';
    sorter.register = function(containerName, model) {
        var container = (typeof  containers[containerName] == 'undefined') ? new Container(containerName) : containers[containerName];
        container.addElement(model);
    };
    sorter.update = function(newVal, oldVal, model) {
        var oldContainer = containers[oldVal];
        var newContainer = (!containers[newVal]) ? new Container(newVal) : containers[newVal];
        if (oldContainer) {
            oldContainer.removeElement(model);
        }
        newContainer.addElement(model);
        if (typeof  sorter.sortScope == 'object') {
            sorter.sortScope.$broadcast('sortContainersChanged');
        }
    };
    sorter.getObjects = function() {
        return containers;
    };
    sorter.saveOrder = function(containersObj) {
        containers = containersObj;
        angular.forEach(containers, function(container) {
            container.callObjectsUpdate();
        });
    };
    return sorter;
}]
);

KMCServices.factory('PlayerService', ['$http', '$modal', '$log', '$q', 'apiService' , '$filter', 'localStorageService',
    function($http, $modal, $log, $q, apiService, $filter, localStorageService) {
        var playersCache = {};
        var currentPlayer = {};
        var previewEntry;
        var previewEntryObj;
        var playerId = 'kVideoTarget';
        var currentRefresh = null;
        var defaultCallback = function() {
            currentRefresh.resolve(true);
            playersService.refreshNeeded = false;
            currentRefresh = null;
            logTime('renderPlayerDone');
        };
        var playerRefresh = function(option) {
            if (!currentRefresh) {
                currentRefresh = $q.defer();
                try {
                    playersService.renderPlayer(defaultCallback);
                }
                catch (e) {
                    currentRefresh.reject(e);
                }
            }
            return currentRefresh.promise;
        };
        var playersService = {
            clearCurrentRefresh: function() {
                currentRefresh = null;
            },
            'refreshNeeded': false,
            getCurrentRefresh: function() {
                return currentRefresh;
            },
            'clearCurrentPlayer': function() {
                currentPlayer = {};
            },
            'setPreviewEntry': function(previewObj) {
                localStorageService.set('previewEntry', previewObj);
                previewEntry = previewObj.id;
                previewEntryObj = previewObj;
            },
            'getPreviewEntry': function() {
                if (!previewEntry) {
                    return localStorageService.get('previewEntry');
                }
                else {
                    return previewEntryObj;
                }
            },
            'renderPlayer': function(callback) {
                logTime('renderPlayer');
                if (currentPlayer && typeof kWidget != "undefined") {
                    var data2Save = angular.copy(currentPlayer.config);
                    data2Save.plugins = playersService.preparePluginsDataForRender(data2Save.plugins);
                    var flashvars = {'jsonConfig': angular.toJson(data2Save)}; // update the player with the new configuration
                    if ($('html').hasClass('IE8')) {                      // for IE8 add transparent mode
                        angular.extend(flashvars, {'wmode': 'transparent'});
                    }
                    // clear companion divs
                    $("#Companion_300x250").empty();
                    $("#Companion_728x90").empty();
                    window.mw.setConfig('Kaltura.LeadWithHTML5', true);
                    window.mw.setConfig('Kaltura.EnableEmbedUiConfJs', true);
                    window.jsCallbackReady = function (playerId) {
                        document.getElementById(playerId).kBind("layoutBuildDone", function () {
                            if (typeof callback == 'function') {
                                callback();
                            }
                        });
                    };
                    kWidget.embed({
                        "targetId": playerId, // hard coded for now?
                        "wid": "_" + currentPlayer.partnerId, //$scope.data.partnerId,
                        "uiconf_id": currentPlayer.id,// $scope.data.id,
                        "flashvars": flashvars,
                        "entry_id": previewEntry //$scope.previewEntry
                    });

                }
                else {
                    throw function() {
                        return "player could not be rendered";
                    };
                }
            },
            'setKDPAttribute': function(attrStr, value) {
                var kdp = document.getElementById('kVideoTarget');
                if ($.isFunction(kdp.setKDPAttribute) && typeof attrStr != "undefined" && attrStr.indexOf(".") != -1) {
                    var obj = attrStr.split(".")[0];
                    var property = attrStr.split(".")[1];
                    kdp.setKDPAttribute(obj, property, value);
                }
            },
            playerRefresh: playerRefresh,
            newPlayer: function() {
                var deferred = $q.defer();
                playersService.getDefaultConfig().
                    success(function(data, status, headers, config) {
                        var request = {
                            'service': 'uiConf',
                            'action': 'add',
                            'uiConf:objectType': 'KalturaUiConf',
                            'uiConf:objType': 1,<commit_msg>use local readyCallback instead of window.jsCallbackReady<commit_after>'use strict';
/* Services */
var KMCServices = angular.module('KMC.services', []);

KMCServices.config(['$httpProvider', function($httpProvider) {
    $httpProvider.defaults.useXDomain = true;
    delete $httpProvider.defaults.headers.common['X-Requested-With'];
}]);

KMCServices.factory('apiCache', function($cacheFactory) {
    return $cacheFactory('apiCache', {
        capacity: 10
    });
});

KMCServices.factory('sortSvc', [function() {
    var containers = {};
    var sorter = {};

    var Container = function Container(name) {
        this.name = name;
        this.elements = [];
        containers[name] = this;
    };
    Container.prototype.addElement = function(model) {
        this.elements.push(model);
    };
    Container.prototype.callObjectsUpdate = function() {
        angular.forEach(this.elements, function(model) {
            cl(model.sortVal + ' ' + model.model);
        });
    };
    Container.prototype.removeElement = function(model) {
        var index = this.elements.indexOf(model);
        if (index != -1)
            this.elements.splice(index, 1);
    };
    sorter.sortScope = '';
    sorter.register = function(containerName, model) {
        var container = (typeof  containers[containerName] == 'undefined') ? new Container(containerName) : containers[containerName];
        container.addElement(model);
    };
    sorter.update = function(newVal, oldVal, model) {
        var oldContainer = containers[oldVal];
        var newContainer = (!containers[newVal]) ? new Container(newVal) : containers[newVal];
        if (oldContainer) {
            oldContainer.removeElement(model);
        }
        newContainer.addElement(model);
        if (typeof  sorter.sortScope == 'object') {
            sorter.sortScope.$broadcast('sortContainersChanged');
        }
    };
    sorter.getObjects = function() {
        return containers;
    };
    sorter.saveOrder = function(containersObj) {
        containers = containersObj;
        angular.forEach(containers, function(container) {
            container.callObjectsUpdate();
        });
    };
    return sorter;
}]
);

KMCServices.factory('PlayerService', ['$http', '$modal', '$log', '$q', 'apiService' , '$filter', 'localStorageService',
    function($http, $modal, $log, $q, apiService, $filter, localStorageService) {
        var playersCache = {};
        var currentPlayer = {};
        var previewEntry;
        var previewEntryObj;
        var playerId = 'kVideoTarget';
        var currentRefresh = null;
        var defaultCallback = function() {
            currentRefresh.resolve(true);
            playersService.refreshNeeded = false;
            currentRefresh = null;
            logTime('renderPlayerDone');
        };
        var playerRefresh = function(option) {
            if (!currentRefresh) {
                currentRefresh = $q.defer();
                try {
                    playersService.renderPlayer(defaultCallback);
                }
                catch (e) {
                    currentRefresh.reject(e);
                }
            }
            return currentRefresh.promise;
        };
        var playersService = {
            clearCurrentRefresh: function() {
                currentRefresh = null;
            },
            'refreshNeeded': false,
            getCurrentRefresh: function() {
                return currentRefresh;
            },
            'clearCurrentPlayer': function() {
                currentPlayer = {};
            },
            'setPreviewEntry': function(previewObj) {
                localStorageService.set('previewEntry', previewObj);
                previewEntry = previewObj.id;
                previewEntryObj = previewObj;
            },
            'getPreviewEntry': function() {
                if (!previewEntry) {
                    return localStorageService.get('previewEntry');
                }
                else {
                    return previewEntryObj;
                }
            },
            'renderPlayer': function(callback) {
                logTime('renderPlayer');
                if (currentPlayer && typeof kWidget != "undefined") {
                    var data2Save = angular.copy(currentPlayer.config);
                    data2Save.plugins = playersService.preparePluginsDataForRender(data2Save.plugins);
                    var flashvars = {'jsonConfig': angular.toJson(data2Save)}; // update the player with the new configuration
                    if ($('html').hasClass('IE8')) {                      // for IE8 add transparent mode
                        angular.extend(flashvars, {'wmode': 'transparent'});
                    }
                    // clear companion divs
                    $("#Companion_300x250").empty();
                    $("#Companion_728x90").empty();
                    window.mw.setConfig('Kaltura.LeadWithHTML5', true);
                    window.mw.setConfig('Kaltura.EnableEmbedUiConfJs', true);
                    kWidget.embed({
                        "targetId": playerId, // hard coded for now?
                        "wid": "_" + currentPlayer.partnerId, //$scope.data.partnerId,
                        "uiconf_id": currentPlayer.id,// $scope.data.id,
                        "flashvars": flashvars,
                        "entry_id": previewEntry, //$scope.previewEntry
                        "readyCallback": function ( playerId ) {
                            document.getElementById(playerId).kBind("layoutBuildDone", function () {
	                            if (typeof callback == 'function') {
	                                callback();
	                            }
	                        });
                        }
                    });

                }
                else {
                    throw function() {
                        return "player could not be rendered";
                    };
                }
            },
            'setKDPAttribute': function(attrStr, value) {
                var kdp = document.getElementById('kVideoTarget');
                if ($.isFunction(kdp.setKDPAttribute) && typeof attrStr != "undefined" && attrStr.indexOf(".") != -1) {
                    var obj = attrStr.split(".")[0];
                    var property = attrStr.split(".")[1];
                    kdp.setKDPAttribute(obj, property, value);
                }
            },
            playerRefresh: playerRefresh,
            newPlayer: function() {
                var deferred = $q.defer();
                playersService.getDefaultConfig().
                    success(function(data, status, headers, config) {
                        var request = {
                            'service': 'uiConf',
                            'action': 'add',
                            'uiConf:objectType': 'KalturaUiConf',
                            'uiConf:objType': 1,
{'fraction_non_alphanumeric': 0.1175108538350217, 'fraction_numerical': 0.0037626628075253256, 'mean_word_length': 1.6042962125494629, 'pattern_counts': {'":': 11, '<': 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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5600469', 'n_tokens_mistral': 3432, 'n_tokens_neox': 3294, 'n_words': 620}