aboutsummaryrefslogtreecommitdiff
path: root/emccpre.js
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2022-10-18 09:38:37 +0100
committerBen Harris <bjh21@bjh21.me.uk>2022-11-12 09:48:31 +0000
commit60d2bf5930d9fbac8860fa440fdf4f5e12c134b8 (patch)
treefc57f55f42bb2204b7cde7832155d3255742baef /emccpre.js
parent22c4cad50e5583d668b87ad19adce377a67452a6 (diff)
downloadpuzzles-60d2bf5930d9fbac8860fa440fdf4f5e12c134b8.zip
puzzles-60d2bf5930d9fbac8860fa440fdf4f5e12c134b8.tar.gz
puzzles-60d2bf5930d9fbac8860fa440fdf4f5e12c134b8.tar.bz2
puzzles-60d2bf5930d9fbac8860fa440fdf4f5e12c134b8.tar.xz
js: Convert menus to use semantically appropriate HTML elements
Presets are now radio buttons with labels, and menu items that take actions are now buttons. The <li> representing each menu item is now a thin wrapper around another element: a <label> for radio buttons, a <button> for other buttons, and a <div> for submenu headings. All of the things that previously applied to the <li> now apply to that inner element instead. This means that presets can now use the standard "checked" attribute to indicate which one is selected, and buttons can be disabled using the standard "disabled" attribute. It also means that we can query and set the state of all the presets at once through their RadioNodeList. I think this should also make the menus more accessible, and make it easier to make them keyboard-controllable.
Diffstat (limited to 'emccpre.js')
-rw-r--r--emccpre.js16
1 files changed, 8 insertions, 8 deletions
diff --git a/emccpre.js b/emccpre.js
index 77bdbb1..93d2e45 100644
--- a/emccpre.js
+++ b/emccpre.js
@@ -126,15 +126,17 @@ var dlg_return_funcs = null;
var dlg_return_sval, dlg_return_ival;
// The <ul> object implementing the game-type drop-down, and a list of
-// the <li> objects inside it. Used by js_add_preset(),
-// js_get_selected_preset() and js_select_preset().
-var gametypelist = null, gametypeitems = [];
-var gametypeselectedindex = null;
+// the sub-lists inside it. Used by js_add_preset().
+var gametypelist = null;
var gametypesubmenus = [];
// C entry point for miscellaneous events.
var command;
+// The <form> encapsulating the menus. Used by
+// js_get_selected_preset() and js_select_preset().
+var menuform = null;
+
// The two anchors used to give permalinks to the current puzzle. Used
// by js_update_permalinks().
var permalink_seed, permalink_desc;
@@ -187,10 +189,7 @@ function canvas_mouse_coords(event, element) {
// Enable and disable items in the CSS menus.
function disable_menu_item(item, disabledFlag) {
- if (disabledFlag)
- item.className = "disabled";
- else
- item.className = "";
+ item.disabled = disabledFlag;
}
// Dialog-box functions called from both C and JS.
@@ -420,6 +419,7 @@ function initPuzzle() {
gametypelist = document.getElementById("gametype");
gametypesubmenus.push(gametypelist);
+ menuform = document.getElementById("gamemenu");
// In IE, the canvas doesn't automatically gain focus on a mouse
// click, so make sure it does