<commit_before>/*global $, app, me, client, XMPP*/
"use strict";

var _ = require('underscore');
var async = require('async');
var Backbone = require('backbone');
var MeModel = require('./models/me');
var MainView = require('./views/main');
var Router = require('./router');
var Storage = require('./storage');
var xmppEventHandlers = require('./helpers/xmppEventHandlers');
var notifier = require('./helpers/notifications');


module.exports = {
    launch: function () {
        var self = window.app = this;
        var config = localStorage.config;
   
        self.notifier = notifier;

        if (!config) {
            console.log('missing config');
            window.location = '/login';
        }

        me.hasFocus = false;
        $(window).blur(function () {
            me.hasFocus = false;
        });
        $(window).focus(function () {
            me.hasFocus = true;
        });
        window.onbeforeunload = function () {
            if (client.sessionStarted) {
                client.disconnect();
                return "End active session?";
            }
        };

        config = JSON.parse(config);

        _.extend(this, Backbone.Events);

        async.series([
            function (cb) {
                app.storage = new Storage();
                app.storage.open(cb);
            },
            function (cb) {
                app.storage.rosterver.get(config.jid, function (err, ver) {
                    if (ver) {
                        config.rosterVer = ver;
                    }
                    cb();
                });
            },
            function (cb) {
                window.me = new MeModel();

                self.api = window.client = XMPP.createClient(config);
                xmppEventHandlers(self.api, self);

                self.api.connect();

                self.api.once('session:started', function () {
                    app.hasConnected = true;
                    cb();
                });
            },
            function (cb) {
                new Router();
                app.history = Backbone.history;

                self.view = new MainView({
                    model: me,
                    el: document.body
                });
                self.view.render();

                // we have what we need, we can now start our router and show the appropriate page
                app.history.start({pushState: true, root: '/'});
                cb();
            }
        ]);
    },
    whenConnected: function (func) {
        if (app.api.sessionStarted) {
            func();
        } else {
            app.api.once('session:started', func);
        }
    },
    navigate: function (page) {
        var url = (page.charAt(0) === '/') ? page.slice(1) : page;
        app.history.navigate(url, true);
    },
    renderPage: function (view, animation) {
        var container = $('#pages');

        if (app.currentPage) {
            app.currentPage.hide(animation);
        }
        // we call render, but if animation is none, we want to tell the view
        // to start with the active class already before appending to DOM.
        container.append(view.render(animation === 'none').el);
        view.show(animation);
    }
};


module.exports.launch();
<commit_msg>Move focus check<commit_after>/*global $, app, me, client, XMPP*/
"use strict";

var _ = require('underscore');
var async = require('async');
var Backbone = require('backbone');
var MeModel = require('./models/me');
var MainView = require('./views/main');
var Router = require('./router');
var Storage = require('./storage');
var xmppEventHandlers = require('./helpers/xmppEventHandlers');
var notifier = require('./helpers/notifications');


module.exports = {
    launch: function () {
        var self = window.app = this;
        var config = localStorage.config;
   
        self.notifier = notifier;

        if (!config) {
            console.log('missing config');
            window.location = '/login';
        }

        config = JSON.parse(config);

        _.extend(this, Backbone.Events);

        async.series([
            function (cb) {
                app.storage = new Storage();
                app.storage.open(cb);
            },
            function (cb) {
                app.storage.rosterver.get(config.jid, function (err, ver) {
                    if (ver) {
                        config.rosterVer = ver;
                    }
                    cb();
                });
            },
            function (cb) {
                window.me = new MeModel();

                me.hasFocus = false;
                $(window).blur(function () {
                    me.hasFocus = false;
                });
                $(window).focus(function () {
                    me.hasFocus = true;
                });
                window.onbeforeunload = function () {
                    if (client.sessionStarted) {
                        client.disconnect();
                        return "End active session?";
                    }
                };

                self.api = window.client = XMPP.createClient(config);
                xmppEventHandlers(self.api, self);

                self.api.connect();

                self.api.once('session:started', function () {
                    app.hasConnected = true;
                    cb();
                });
            },
            function (cb) {
                new Router();
                app.history = Backbone.history;

                self.view = new MainView({
                    model: me,
                    el: document.body
                });
                self.view.render();

                // we have what we need, we can now start our router and show the appropriate page
                app.history.start({pushState: true, root: '/'});
                cb();
            }
        ]);
    },
    whenConnected: function (func) {
        if (app.api.sessionStarted) {
            func();
        } else {
            app.api.once('session:started', func);
        }
    },
    navigate: function (page) {
        var url = (page.charAt(0) === '/') ? page.slice(1) : page;
        app.history.navigate(url, true);
    },
    renderPage: function (view, animation) {
        var container = $('#pages');

        if (app.currentPage) {
            app.currentPage.hide(animation);
        }
        // we call render, but if animation is none, we want to tell the view
        // to start with the active class already before appending to DOM.
        container.append(view.render(animation === 'none').el);
        view.show(animation);
    }
};


module.exports.launch();

{'fraction_non_alphanumeric': 0.13083270817704426, 'fraction_numerical': 0.0006001500375093774, 'mean_word_length': 1.3935368043087972, 'pattern_counts': {'":': 0, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7101586', 'n_tokens_mistral': 1788, 'n_tokens_neox': 1690, 'n_words': 398}