MarkupLibGobi MarkupLib lives in gobi/code/Global/Markup.js. Experimental callback supportView the live demo. Watch the URLs while you play the game. These are, so to speak, anonymous, temporary actions passed as form.callback. The form stores them in the user's session. They automatically maintain the state of the game in their JavaScript scope. Source code (explanation follows below):
In the main test_callback_action, we basically do 5 simple things:
The real magic happens in the callback function. When a form element with a callback function is rendered, the function is stored in the user's session with a random ID. The form than gets its action attribute set to the callback ID and, when submitted, gets routed to the callback function (some amount of getChildElement() magic is involved). As the callback inherits the surrounding scope, the form, number, and guesses variables remain visible and up to date throughout the game. It even has the this keyword pointing to the same object as the surrounding function (again, some amount of trickery was necessary to achieve that). Since we use the same form with the same callback multiple times (unless you guess right the first time), the same callback is used multiple times, which is perfectly ok except (maybe) for caching issues. You may want to disable client caching using res.cache (or maybe fake request parameters).
The renderPage() function is a pure utility method to wrap the page content into an html tags. Unfortunately, we can't currently use Gobi's page skin in combination with callbacks because they put an additional object in the request path that doesn't extend the Page prototype. Which is why this whole crap is still tagged as experimental :-) |
navigation
search
|