{"size": 2800, "ext": "js", "max_stars_repo_path": "js/app/preloader.js", "max_stars_repo_name": "ZalophusDokdo/ball-and-wall", "max_stars_repo_stars_event_min_datetime": "2015-06-18T18:06:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T14:33:11.000Z", "max_issues_repo_path": "js/app/preloader.js", "max_issues_repo_name": "ZalophusDokdo/ball-and-wall", "max_issues_repo_issues_event_min_datetime": "2019-08-15T00:15:19.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-03T03:58:57.000Z", "max_forks_repo_path": "js/app/preloader.js", "max_forks_repo_name": "ZalophusDokdo/ball-and-wall", "max_forks_repo_forks_event_min_datetime": "2016-04-26T04:10:49.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-23T07:44:53.000Z"}
{"max_stars_count": 39, "max_issues_count": 16, "max_forks_count": 35, "avg_line_length": 27.1844660194, "max_line_length": 86, "alphanum_fraction": 0.5553571429}

define('app/preloader', 
[
    'app/core/_', 'app/window/_', 'app/episodes/_'
], 
function(core, _window, episode) {
    
    function Preloader() {
        core.EventEmitter.call(this);
        this.preloaderTimer = null;
        this.preloaderIndicator = new _window.PreloaderIndicator();
    }
    
    Preloader.prototype = Object.create(core.EventEmitter.prototype, {
        constructor: {
            value: Preloader,
            enumerable: false
        }
    });
    
    /**
     * @method get
     * @param {String} resourceId
     * @return {Image}
     */
    Preloader.prototype.get = function(resourceId) {
        return this.queue.getResult(resourceId);
    };
    
    /**
     * @method load
     */
    Preloader.prototype.load = function() {
        episode.load($.proxy(function() {
            var link = document.createElement('link');
            
            createjs.Sound.alternateExtensions = ['mp3'];
            this.queue = new createjs.LoadQueue(false);
            this.queue.installPlugin(createjs.Sound);
            this.queue.addEventListener('complete', $.proxy(this.onComplete, this));
            this.queue.addEventListener("progress", $.proxy(this.onProgress, this));
            this.queue.addEventListener("loadstart", $.proxy(this.onLoadStart, this));
            this.queue.loadManifest(episode.getResources());
            $('#css-episode').remove();

            link.rel = 'stylesheet';
            link.href = SS + 'css/episodes/' + episode.getName() + '.css' + REVISION;
            link.type = 'text/css';
            link.id = 'css-episode';
            link.media = 'screen';
            $(document.head).append(link);
        }, this));
    };
    
    /**
     * @method showIndicator
     */
    Preloader.prototype.showIndicator = function() {
        this.preloaderIndicator.open();
    };
    
    /**
     * @method hideIndicator
     */
    Preloader.prototype.hideIndicator = function() {
        this.preloaderIndicator.close();
    };
    
    /**
     * @method onLoadStart
     * @param {Object} event
     */
    Preloader.prototype.onLoadStart = function(event) {
        this.showIndicator();
        this.emit('loadstart');
    };
    
    /**
     * @method onProgress
     * @param {Object} event
     */
    Preloader.prototype.onProgress = function(event) {
        this.preloaderIndicator.updateProgress((event.loaded * 100) >> 0);
        this.emit('progress', event.loaded);
    };
    
    /**
     * @method onComplete
     * @param {Object} event
     */
    Preloader.prototype.onComplete = function(event) {
        this.hideIndicator();
        this.emit('complete');
    };
    
    var instance = null;
    
    if ( instance === null ) {
        instance = new Preloader();
    }
    
    return instance;
});