1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-15 13:45:08 -05:00
mail/src/sandbox.js

48 lines
947 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;
// start backone.js router
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);
};
}());