2013-06-04 15:36:13 -04:00
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
2013-06-04 19:10:09 -04:00
|
|
|
var router,
|
|
|
|
mainWindow,
|
|
|
|
mainWindowOrigin;
|
2013-06-04 15:36:13 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2013-06-04 15:36:13 -04:00
|
|
|
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 15:36:13 -04:00
|
|
|
|
2013-06-04 17:19:02 -04:00
|
|
|
// remember references to main window
|
2013-06-04 19:10:09 -04:00
|
|
|
mainWindow = e.source;
|
|
|
|
mainWindowOrigin = e.origin;
|
2013-06-04 15:36:13 -04:00
|
|
|
|
2013-06-06 09:00:51 -04:00
|
|
|
// start backone.js router
|
2013-06-04 19:10:09 -04:00
|
|
|
router = new app.Router();
|
2013-06-04 17:19:02 -04:00
|
|
|
Backbone.history.start();
|
|
|
|
}
|
2013-06-04 15:36:13 -04:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2013-06-04 19:10:09 -04:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
};
|
|
|
|
|
2013-06-04 15:36:13 -04:00
|
|
|
}());
|