mirror of
https://github.com/moparisthebest/mail
synced 2025-01-08 12:08:07 -05:00
refactored sandbox with requirejs
This commit is contained in:
parent
2007fbcc0f
commit
1c234b7def
@ -8,23 +8,7 @@
|
||||
<link rel="stylesheet" href="css/styles.css"/>
|
||||
|
||||
<!-- The Scripts -->
|
||||
<script src="lib/jquery-1.8.2.min.js"></script>
|
||||
<script src="lib/underscore-1.4.4.min.js"></script>
|
||||
<script src="lib/backbone-1.0.0.min.js"></script>
|
||||
<script src="js/jqm-config.js"></script>
|
||||
<script src="lib/jquery.mobile-1.2.0.min.js"></script>
|
||||
|
||||
<script src="js/app-config.js"></script>
|
||||
|
||||
<script src="js/view/login-view.js"></script>
|
||||
<script src="js/view/compose-view.js"></script>
|
||||
<script src="js/view/messagelist-view.js"></script>
|
||||
<script src="js/view/messagelistitem-view.js"></script>
|
||||
<script src="js/view/folderlist-view.js"></script>
|
||||
<script src="js/view/read-view.js"></script>
|
||||
|
||||
<script src="js/app-router.js"></script>
|
||||
<script src="sandbox.js"></script>
|
||||
<script data-main="sandbox.js" src="lib/require.js"></script>
|
||||
</head>
|
||||
|
||||
<body></body>
|
||||
|
@ -1,48 +1,54 @@
|
||||
(function() {
|
||||
require(['require-config'], function() {
|
||||
'use strict';
|
||||
|
||||
var router,
|
||||
mainWindow,
|
||||
mainWindowOrigin;
|
||||
// Start the main app logic.
|
||||
require(['jquery', 'backbone', 'js/app-router',
|
||||
'js/app-config'
|
||||
], function($, Backbone, Router, app) {
|
||||
|
||||
/**
|
||||
* Load templates and start the application
|
||||
*/
|
||||
$(document).ready(function() {
|
||||
console.log('sandbox loaded');
|
||||
var router,
|
||||
mainWindow,
|
||||
mainWindowOrigin;
|
||||
|
||||
// set listener for event from main window
|
||||
window.onmessage = function(e) {
|
||||
if (e.data.cmd === 'init') {
|
||||
app.util.tpl.templates = e.data.args;
|
||||
/**
|
||||
* Load templates and start the application
|
||||
*/
|
||||
$(document).ready(function() {
|
||||
console.log('sandbox loaded');
|
||||
|
||||
// remember references to main window
|
||||
mainWindow = e.source;
|
||||
mainWindowOrigin = e.origin;
|
||||
// set listener for event from main window
|
||||
window.onmessage = function(e) {
|
||||
if (e.data.cmd === 'init') {
|
||||
app.util.tpl.templates = e.data.args;
|
||||
|
||||
// start backone.js router
|
||||
router = new app.Router();
|
||||
Backbone.history.start();
|
||||
}
|
||||
// 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);
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* 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);
|
||||
};
|
||||
|
||||
}());
|
||||
});
|
Loading…
Reference in New Issue
Block a user