From 64459af4aec30337bac038a71ef06222de06153b Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Fri, 10 Jan 2014 01:13:25 +0100 Subject: [PATCH] Show checkbox and radiobox state in hint label. --- src/hints.js | 16 ++++++++++++---- src/js2h.sh | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/hints.js b/src/hints.js index 48b98e2..4d6faee 100644 --- a/src/hints.js +++ b/src/hints.js @@ -56,12 +56,20 @@ var VbHint = (function(){ this.e.classList.add(hClass); /* create the label with the hint number */ - this.label.innerText = this.num; + var text = []; + if (this.e instanceof HTMLInputElement) { + var type = this.e.type; + if (type === "checkbox") { + text.push(this.e.checked ? "☑" : "☐"); + } else if (type === "radio") { + text.push(this.e.checked ? "⊙" : "○"); + } + } if (this.showText && this.text) { - /* use \x20 instead of ' ' to keep this space during */ - /* js2h.sh processing */ - this.label.innerText += ":\x20" + this.text.substr(0, 20); + text.push(this.text.substr(0, 20)); } + /* use \x20 instead of ' ' to keep this space during js2h.sh processing */ + this.label.innerText = this.num + (text.length ? ":\x20" + text.join("\x20") : ""); }; } diff --git a/src/js2h.sh b/src/js2h.sh index 90ed16a..be92ac4 100755 --- a/src/js2h.sh +++ b/src/js2h.sh @@ -7,6 +7,7 @@ cat $1 | \ -e 's|[ ]\{2,\}| |g' \ -e "s|[ ]\{0,\}\([-!?<>:=(){};+\&\"',\|]\)[ ]\{0,\}|\1|g" \ -e 's|"+"||g' \ + -e 's|\\x20| |g' \ -e 's|\\|\\\\|g' \ -e 's|"|\\"|g' echo '"' -- 2.20.1