* emccpre.js: one of the Javascript components of an Emscripten-based
* web/Javascript front end for Puzzles.
*
- * The other parts of this system live in emcc.c and emcclib.js.
+ * The other parts of this system live in emcc.c and emcclib.js. It
+ * also depends on being run in the context of a web page containing
+ * an appropriate collection of bits and pieces (a canvas, some
+ * buttons and links etc), which is generated for each puzzle by the
+ * script html/jspage.pl.
*
* This file contains the Javascript code which is prefixed unmodified
* to Emscripten's output via the --pre-js option. It declares all our
// callbacks.
var Module = {
'noInitialRun': true,
- 'noExitRuntime': true,
+ 'noExitRuntime': true
};
// Variables used by js_canvas_find_font_midpoint().
command(2);
};
+ // In IE, the canvas doesn't automatically gain focus on a mouse
+ // click, so make sure it does
+ onscreen_canvas.addEventListener("mousedown", function(event) {
+ onscreen_canvas.focus();
+ });
+
// In our dialog boxes, Return and Escape should be like pressing
// OK and Cancel respectively
document.addEventListener("keydown", function(event) {
// Default to giving keyboard focus to the puzzle.
onscreen_canvas.focus();
- // And run the C setup function, passing argv[1] as the fragment
+ // Run the C setup function, passing argv[1] as the fragment
// identifier (so that permalinks of the form puzzle.html#game-id
// can launch the specified id).
Module.arguments = [location.hash];
Module.run();
+
+ // And if we get here with everything having gone smoothly, i.e.
+ // we haven't crashed for one reason or another during setup, then
+ // it's probably safe to hide the 'sorry, no puzzle here' div and
+ // show the div containing the actual puzzle.
+ document.getElementById("apology").style.display = "none";
+ document.getElementById("puzzle").style.display = "inline";
}