aboutsummaryrefslogtreecommitdiff
path: root/html/jspage.pl
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2017-04-26 14:39:45 +0100
committerSimon Tatham <anakin@pobox.com>2017-04-26 21:48:11 +0100
commitbc2c1f69fddac3a51d086fb379f0ec8954f4b894 (patch)
tree9e7d20313a58b4101271b91f8f0d7e6c493e32e8 /html/jspage.pl
parentce6e3df99bc7825d1c1638d378320375eb05fd0b (diff)
downloadpuzzles-bc2c1f69fddac3a51d086fb379f0ec8954f4b894.zip
puzzles-bc2c1f69fddac3a51d086fb379f0ec8954f4b894.tar.gz
puzzles-bc2c1f69fddac3a51d086fb379f0ec8954f4b894.tar.bz2
puzzles-bc2c1f69fddac3a51d086fb379f0ec8954f4b894.tar.xz
Javascript puzzles: switch to a CSS-based drop-down system.
The previous control buttons and dropdowns based on form elements were always a bit ugly: partly in a purely visual sense, and partly because of the nasty bodge I had to do with splitting the usual 'Custom' game type menu item into two (to get round the fact that if an element of a <select> is already selected, browsers won't send an event when it's re-selected). Also, I'm about to want to introduce hierarchical submenus in the Type menu, and <select> doesn't support that at all. So here's a replacement system which does everything by CSS properties, including the popping-up of menus when the mouse moves over their parent menu item. (Thanks to the Internet in general for showing me how that trick is done.)
Diffstat (limited to 'html/jspage.pl')
-rwxr-xr-xhtml/jspage.pl142
1 files changed, 132 insertions, 10 deletions
diff --git a/html/jspage.pl b/html/jspage.pl
index 19868bd..a21f977 100755
--- a/html/jspage.pl
+++ b/html/jspage.pl
@@ -63,6 +63,129 @@ EOF
<meta http-equiv="Content-Type" content="text/html; charset=ASCII" />
<title>${puzzlename}, ${unfinishedtitlefragment}from Simon Tatham's Portable Puzzle Collection</title>
<script type="text/javascript" src="${filename}.js"></script>
+<style class="text/css">
+/* Margins and centring on the top-level div for the game menu */
+#gamemenu { margin-top: 0; margin-bottom: 0.5em; text-align: center }
+
+/* Inside that div, the main menu bar and every submenu inside it is a <ul> */
+#gamemenu ul {
+ list-style: none; /* get rid of the normal unordered-list bullets */
+ display: inline; /* make top-level menu bar items appear side by side */
+ position: relative; /* allow submenus to position themselves near parent */
+ margin: 0;
+ margin-bottom: 0.5em;
+ padding: 0;
+}
+
+/* Individual menu items are <li> elements within such a <ul> */
+#gamemenu ul li {
+ /* Add a little mild text formatting */
+ font-weight: bold; font-size: 0.8em;
+ /* Line height and padding appropriate to top-level menu items */
+ padding-left: 0.75em; padding-right: 0.75em;
+ padding-top: 0.2em; padding-bottom: 0.2em;
+ margin: 0;
+ /* Make top-level menu items appear side by side, not vertically stacked */
+ display: inline;
+ /* Suppress the text-selection I-beam pointer */
+ cursor: default;
+ /* Surround each menu item with a border. The left border is removed
+ * because it will abut the right border of the previous item. (A rule
+ * below will reinstate the left border for the leftmost menu item.) */
+ border-left: 0;
+ border-right: 1px solid rgba(0,0,0,0.3);
+ border-top: 1px solid rgba(0,0,0,0.3);
+ border-bottom: 1px solid rgba(0,0,0,0.3);
+}
+
+#gamemenu ul li.disabled {
+ /* Grey out menu items with the "disabled" class */
+ color: rgba(0,0,0,0.5);
+}
+
+#gamemenu ul li:first-of-type {
+ /* Reinstate the left border for the leftmost top-level menu item */
+ border-left: 1px solid rgba(0,0,0,0.3);
+}
+
+#gamemenu ul li:hover {
+ /* When the mouse is over a menu item, highlight it */
+ background: rgba(0,0,0,0.3);
+ /* Set position:relative, so that if this item has a submenu it can
+ * position itself relative to the parent item. */
+ position: relative;
+}
+
+#gamemenu ul li.disabled:hover {
+ /* Disabled menu items don't get a highlight on mouse hover */
+ background: inherit;
+}
+
+#gamemenu ul ul {
+ /* Second-level menus and below are not displayed by default */
+ display: none;
+ /* When they are displayed, they are positioned immediately below
+ * their parent <li>, and with the left edge aligning */
+ position: absolute;
+ top: 100%;
+ left: 0;
+ /* We must specify an explicit background colour for submenus, because
+ * they must be opaque (don't want other page contents showing through
+ * them). */
+ background: white;
+ /* And make sure they appear in front. */
+ z-index: 1;
+}
+
+#gamemenu ul ul.left {
+ /* A second-level menu with class "left" aligns its right edge with
+ * its parent, rather than its left edge */
+ left: inherit; right: 0;
+}
+
+/* Menu items in second-level menus and below */
+#gamemenu ul ul li {
+ /* Go back to vertical stacking, for drop-down submenus */
+ display: block;
+ /* Inhibit wrapping, so the submenu will expand its width as needed. */
+ white-space: nowrap;
+ /* Override the text-align:center from above */
+ text-align: left;
+ /* Don't make the text any smaller than the previous level of menu */
+ font-size: 100%;
+ /* This time it's the top border that we omit on all but the first
+ * element in the submenu, since now they're vertically stacked */
+ border-left: 1px solid rgba(0,0,0,0.3);
+ border-right: 1px solid rgba(0,0,0,0.3);
+ border-top: 0;
+ border-bottom: 1px solid rgba(0,0,0,0.3);
+}
+
+#gamemenu ul ul li:first-of-type {
+ /* Reinstate top border for first item in a submenu */
+ border-top: 1px solid rgba(0,0,0,0.3);
+}
+
+#gamemenu ul ul ul {
+ /* Third-level submenus are drawn to the side of their parent menu
+ * item, not below it */
+ top: 0; left: 100%;
+}
+
+#gamemenu ul ul ul.left {
+ /* A submenu with class "left" goes to the left of its parent,
+ * not the right */
+ left: inherit; right: 100%;
+}
+
+#gamemenu ul li:hover > ul {
+ /* Last but by no means least, the all-important line that makes
+ * submenus be displayed! Any <ul> whose parent <li> is being
+ * hovered over gets display:block overriding the display:none
+ * from above. */
+ display: block;
+}
+</style>
</head>
<body onLoad="initPuzzle();">
<h1 align=center>${puzzlename}</h1>
@@ -73,16 +196,15 @@ ${unfinishedpara}
<hr>
<div id="puzzle" style="display: none">
-<p align=center>
- <input type="button" id="new" value="New game">
- <input type="button" id="restart" value="Restart game">
- <input type="button" id="undo" value="Undo move">
- <input type="button" id="redo" value="Redo move">
- <input type="button" id="solve" value="Solve game">
- <input type="button" id="specific" value="Enter game ID">
- <input type="button" id="random" value="Enter random seed">
- <select id="gametype"></select>
-</p>
+<div id="gamemenu"><ul><li id="new">New game</li
+><li id="restart">Restart game</li
+><li id="undo">Undo move</li
+><li id="redo">Redo move</li
+><li id="solve">Solve game</li
+><li id="specific">Enter game ID</li
+><li id="random">Enter random seed</li
+><li>Select game type<ul id="gametype" class="left"></ul></li
+></ul></div>
<div align=center>
<div id="resizable" style="position:relative; left:0; top:0">
<canvas style="display: block" id="puzzlecanvas" width="1px" height="1px" tabindex="1">