2013-06-10 21:36:48 -04:00
|
|
|
require(['require-config'], function() {
|
2013-06-04 15:36:13 -04:00
|
|
|
'use strict';
|
|
|
|
|
2013-06-10 21:36:48 -04:00
|
|
|
// Start the main app logic.
|
|
|
|
require(['jquery', 'backbone', 'js/app-router',
|
|
|
|
'js/app-config'
|
|
|
|
], function($, Backbone, Router, app) {
|
|
|
|
|
|
|
|
var router,
|
|
|
|
mainWindow,
|
|
|
|
mainWindowOrigin;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load templates and start the application
|
|
|
|
*/
|
|
|
|
$(document).ready(function() {
|
|
|
|
console.log('sandbox loaded');
|
|
|
|
|
|
|
|
// set listener for event from main window
|
|
|
|
window.onmessage = function(e) {
|
|
|
|
if (e.data.cmd === 'init') {
|
|
|
|
app.util.tpl.templates = e.data.args;
|
|
|
|
|
|
|
|
// remember references to main window
|
|
|
|
mainWindow = e.source;
|
|
|
|
mainWindowOrigin = e.origin;
|
|
|
|
|
|
|
|
// start backone.js router
|
|
|
|
router = new Router();
|
|
|
|
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);
|
2013-06-04 19:10:09 -04:00
|
|
|
};
|
|
|
|
|
2013-06-10 21:36:48 -04:00
|
|
|
});
|
|
|
|
});
|