mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
js: Tolerate the non-existence of some HTML elements
Specifically, the permalinks, the apology, and the resizable div.
This commit is contained in:
@ -166,8 +166,10 @@ mergeInto(LibraryManager.library, {
|
||||
*/
|
||||
js_update_permalinks: function(desc, seed) {
|
||||
desc = encodeURI(UTF8ToString(desc)).replace(/#/g, "%23");
|
||||
if (permalink_desc !== null)
|
||||
permalink_desc.href = "#" + desc;
|
||||
|
||||
if (permalink_seed !== null) {
|
||||
if (seed == 0) {
|
||||
permalink_seed.style.display = "none";
|
||||
} else {
|
||||
@ -175,6 +177,7 @@ mergeInto(LibraryManager.library, {
|
||||
permalink_seed.href = "#" + seed;
|
||||
permalink_seed.style.display = "";
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/*
|
||||
@ -547,7 +550,9 @@ mergeInto(LibraryManager.library, {
|
||||
js_canvas_set_size: function(w, h) {
|
||||
onscreen_canvas.width = w;
|
||||
offscreen_canvas.width = w;
|
||||
resizable_div.style.width = w / (window.devicePixelRatio || 1) + "px";
|
||||
if (resizable_div !== null)
|
||||
resizable_div.style.width =
|
||||
w / (window.devicePixelRatio || 1) + "px";
|
||||
|
||||
onscreen_canvas.height = h;
|
||||
offscreen_canvas.height = h;
|
||||
|
14
emccpre.js
14
emccpre.js
@ -472,6 +472,7 @@ function initPuzzle() {
|
||||
ctx.stroke();
|
||||
}
|
||||
resizable_div = document.getElementById("resizable");
|
||||
if (resizable_div !== null) {
|
||||
resizable_div.appendChild(resize_handle);
|
||||
resize_handle.id = "resizehandle";
|
||||
resize_handle.title = "Drag to resize the puzzle. Right-click to restore the default size.";
|
||||
@ -479,15 +480,18 @@ function initPuzzle() {
|
||||
var resize_xoffset = null, resize_yoffset = null;
|
||||
var resize_puzzle = Module.cwrap('resize_puzzle',
|
||||
'void', ['number', 'number']);
|
||||
var restore_puzzle_size = Module.cwrap('restore_puzzle_size', 'void', []);
|
||||
var restore_puzzle_size = Module.cwrap('restore_puzzle_size',
|
||||
'void', []);
|
||||
resize_handle.oncontextmenu = function(event) { return false; }
|
||||
resize_handle.onmousedown = function(event) {
|
||||
if (event.button == 0) {
|
||||
var xy = element_coords(onscreen_canvas);
|
||||
resize_xbase = xy.x + onscreen_canvas.offsetWidth / 2;
|
||||
resize_ybase = xy.y;
|
||||
resize_xoffset = xy.x + onscreen_canvas.offsetWidth - event.pageX;
|
||||
resize_yoffset = xy.y + onscreen_canvas.offsetHeight - event.pageY;
|
||||
resize_xoffset =
|
||||
xy.x + onscreen_canvas.offsetWidth - event.pageX;
|
||||
resize_yoffset =
|
||||
xy.y + onscreen_canvas.offsetHeight - event.pageY;
|
||||
} else {
|
||||
restore_pending = true;
|
||||
}
|
||||
@ -529,6 +533,7 @@ function initPuzzle() {
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Arrange to detect changes of device pixel ratio. Adapted from
|
||||
@ -558,7 +563,8 @@ function initPuzzle() {
|
||||
// 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";
|
||||
var apology = document.getElementById("apology");
|
||||
if (apology !== null) apology.style.display = "none";
|
||||
document.getElementById("puzzle").style.display = "";
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user