1
0
mirror of https://github.com/moparisthebest/mail synced 2024-10-31 15:25:01 -04:00
mail/src/js/sandbox-loader.js

47 lines
916 B
JavaScript
Raw Normal View History

(function() {
'use strict';
var router,
mainWindow,
mainWindowOrigin;
/**
* Load templates and start the application
*/
$(document).ready(function() {
console.log('sandbox loaded');
2013-06-04 17:19:02 -04:00
// set listener for event from main window
window.onmessage = function(e) {
2013-06-04 17:19:02 -04:00
if (e.data.cmd === 'init') {
app.util.tpl.templates = e.data.args;
2013-06-04 17:19:02 -04:00
// remember references to main window
mainWindow = e.source;
mainWindowOrigin = e.origin;
router = new app.Router();
2013-06-04 17:19:02 -04:00
Backbone.history.start();
}
};
});
/**
* Helper method to ease message posting between sandbox and main window
*/
app.util.postMessage = function(cmd, args, callback) {
// set listender
window.onmessage = function(e) {
if (e.data.cmd === cmd) {
callback(e.data.args);
}
};
// send message to main window
mainWindow.postMessage({
cmd: cmd,
args: args
}, mainWindowOrigin);
};
}());