Documented and cleaned up parser a bit so I have an easier time circling back to this, refactored splash.js to be properly namespaced and handle window/stage resizing

This commit is contained in:
Ryan McGrath 2010-08-19 03:03:05 -07:00
parent 7ba03595eb
commit 91bf367d80
2 changed files with 56 additions and 22 deletions

View file

@ -8,28 +8,51 @@
* @Requires: jQuery 1.3.2 or greater (preferably 1.4.2, I make no guarantee for anything else, but it should work)
*/
if(typeof splash === "undefined")
var splash = {};
var splash = {
/* Stored reference to a jQuery'd window object, so we don't do repeated useless lookups. */
win: null,
var game_on = function(json) {
if(/App Code/.test(json)) return;
/* Stage for programs to run. Gets set at document ready, below. */
stage: null,
debug(json);
/* Handles resizing of the overall window and stage.
*
* @param win - jQuery'd window object.
*/
resizeStage: function(callbackfn) {
if(typeof callbackfn !== "undefined")
splash.stage.animate({"height": splash.win.height() - 50}, 800, callbackfn);
else
splash.stage.animate({"height": splash.win.height() - 50}, 800);
},
/* Self explanatory - masked call to console.log, "handles" browsers that don't support it. */
debug: function(msg) { if(typeof console !== "undefined" && typeof console.log === "function") console.log(msg); },
/* splash.game_on gets called by the compiled/written out .splash file. Every
* app gets a "main" function injected (see: parser.js - exports.writeApp), which
* is merely reference to calling splash.game_on.
*
* This, of course, has to walk the JSON chain and actually construct the events for
* the stage.
*/
game_on: function(json) {
if(/App Code/.test(json)) return;
// Parse JSON object here - need a lookup table for name/noun/verb/etc?
splash.debug(json);
}
};
if(typeof debug === "undefined")
var debug = function(msg) {
/* TODO: Support debugging in other annoying consoles (Opera, I'm looking at you) */
if(typeof console !== "undefined" && typeof console.log === "function") console.log(msg);
};
$(document).ready(function() {
splash.wrapper = $("#splash_app_wrapper");
splash.stage = $("#splash_app_wrapper");
splash.win = $(window);
splash.win.resize(splash.resizeStage);
/* Rough guesstimation for now on desired height, finagle later. Wait until the frame is our desired height before
* "running" our program.
* "running" our program (in this case, "main" is our program to run, injected by the compiler).
*/
splash.wrapper.animate({"height": $(window).height() - 50}, 800, function() {
main();
});
splash.resizeStage(main);
});