2013-08-20 13:45:06 -04:00
|
|
|
/* global app, XMPP */
|
|
|
|
var Backbone = require('backbone');
|
|
|
|
var MeModel = require('models/me');
|
|
|
|
var MainView = require('views/main');
|
|
|
|
var Router = require('router');
|
|
|
|
var xmppEventHandlers = require('helpers/xmppEventHandlers');
|
2013-06-03 18:51:30 -04:00
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
launch: function () {
|
2013-08-20 13:45:06 -04:00
|
|
|
var app = window.app = this;
|
|
|
|
var me = window.me = new MeModel();
|
2013-06-03 18:51:30 -04:00
|
|
|
|
2013-08-20 13:45:06 -04:00
|
|
|
new Router();
|
|
|
|
app.history = Backbone.history;
|
2013-06-03 18:51:30 -04:00
|
|
|
|
2013-08-20 13:45:06 -04:00
|
|
|
if (!localStorage.config) {
|
|
|
|
return app.navigate('signin');
|
|
|
|
}
|
2013-06-03 18:51:30 -04:00
|
|
|
|
2013-08-20 13:45:06 -04:00
|
|
|
app.view = new MainView({
|
|
|
|
el: document.body,
|
|
|
|
model: me
|
|
|
|
}).render();
|
2013-06-03 18:51:30 -04:00
|
|
|
|
2013-08-20 13:45:06 -04:00
|
|
|
var config = JSON.parse(localStorage.config);
|
|
|
|
var client = window.client = app.client = XMPP.createClient(config);
|
|
|
|
xmppEventHandlers(client, app);
|
|
|
|
client.connect();
|
2013-06-03 18:51:30 -04:00
|
|
|
|
|
|
|
// we have what we need, we can now start our router and show the appropriate page
|
|
|
|
app.history.start({pushState: true, root: '/'});
|
|
|
|
},
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|