2013-04-01 17:23:25 -04:00
|
|
|
(function() {
|
|
|
|
'use strict';
|
2013-03-13 11:58:46 -04:00
|
|
|
|
2013-04-01 17:23:25 -04:00
|
|
|
/**
|
|
|
|
* The Template Loader. Used to asynchronously load templates located in separate .html files
|
|
|
|
*/
|
|
|
|
app.util.tpl = {
|
2013-03-13 11:58:46 -04:00
|
|
|
|
2013-04-01 17:23:25 -04:00
|
|
|
// Hash of preloaded templates for the app
|
|
|
|
templates: {},
|
2013-03-13 11:58:46 -04:00
|
|
|
|
2013-04-01 17:23:25 -04:00
|
|
|
// Recursively pre-load all the templates for the app.
|
|
|
|
loadTemplates: function(names, callback) {
|
|
|
|
var that = this;
|
2013-03-13 11:58:46 -04:00
|
|
|
|
2013-04-01 17:23:25 -04:00
|
|
|
var loadTemplate = function(index) {
|
|
|
|
var name = names[index];
|
|
|
|
console.log('Loading template: ' + name);
|
|
|
|
$.get('tpl/' + name + '.html', function(data) {
|
|
|
|
that.templates[name] = data;
|
|
|
|
index++;
|
|
|
|
if (index < names.length) {
|
|
|
|
loadTemplate(index);
|
|
|
|
} else {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2013-03-13 11:58:46 -04:00
|
|
|
|
2013-04-01 17:23:25 -04:00
|
|
|
loadTemplate(0);
|
|
|
|
},
|
2013-03-13 11:58:46 -04:00
|
|
|
|
2013-04-01 17:23:25 -04:00
|
|
|
// Get template by name from hash of preloaded templates
|
|
|
|
get: function(name) {
|
|
|
|
return this.templates[name];
|
|
|
|
}
|
2013-03-13 11:58:46 -04:00
|
|
|
|
2013-04-01 17:23:25 -04:00
|
|
|
};
|
2013-03-13 11:58:46 -04:00
|
|
|
|
2013-04-01 17:23:25 -04:00
|
|
|
/**
|
|
|
|
* Load templates and start the application
|
|
|
|
*/
|
|
|
|
$(document).ready(function() {
|
|
|
|
// are we running in native app or in browser?
|
|
|
|
var isBrowser = false;
|
2013-04-29 05:59:34 -04:00
|
|
|
if (document.URL.indexOf("http") === 0) {
|
2013-04-01 17:23:25 -04:00
|
|
|
isBrowser = true;
|
|
|
|
}
|
2013-03-13 11:58:46 -04:00
|
|
|
|
2013-04-01 17:23:25 -04:00
|
|
|
if (!isBrowser) {
|
|
|
|
document.addEventListener("deviceready", onDeviceReady, false);
|
|
|
|
} else {
|
|
|
|
onDeviceReady();
|
|
|
|
}
|
|
|
|
|
|
|
|
function onDeviceReady() {
|
|
|
|
console.log('Starting in Browser: ' + isBrowser);
|
|
|
|
app.util.tpl.loadTemplates([
|
|
|
|
'login',
|
|
|
|
'compose',
|
|
|
|
'folderlist',
|
|
|
|
'messagelist',
|
|
|
|
'messagelistitem',
|
|
|
|
'read'], function() {
|
|
|
|
var router = new app.Router();
|
|
|
|
Backbone.history.start();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}());
|