@@ -20,6 +20,7 @@ $(DIVC intro, $(DIV, $(DIV,
2020 )
2121 )
2222 $(DIVID your-code-here,
23+ $(DIVID your-code-here-select-example)
2324 $(DIVC tip,
2425 $(LINK2 https://forum.dlang.org/newpost/general?subject=%5Byour+code+here%5D, your code here)
2526 $(DIV,
@@ -29,14 +30,13 @@ $(DIVC intro, $(DIV, $(DIV,
2930 $(P Upon approval it will be showcased here on a random schedule.)
3031 )
3132 )
32- $(EXTRA_EXAMPLE
33+ $(EXTRA_EXAMPLE Compute average line length for stdin,
3334$(RUNNABLE_EXAMPLE_STDIN
3435The D programming language
3536Modern convenience.
3637Modeling power.
3738Native efficiency.)
3839----
39- // Compute average line length for stdin
4040void main()
4141{
4242 import std.range, std.stdio;
@@ -50,10 +50,9 @@ void main()
5050}
5151----
5252)
53- $(EXTRA_EXAMPLE
53+ $(EXTRA_EXAMPLE Round floating point numbers,
5454$(RUNNABLE_EXAMPLE_STDIN 2.4 plus 2.4 equals 5 for sufficiently large values of 2.)
5555----
56- // Round floating point numbers
5756import std.algorithm, std.conv, std.functional,
5857 std.math, std.regex, std.stdio;
5958
@@ -72,7 +71,7 @@ void main()
7271}
7372----
7473)
75- $(EXTRA_EXAMPLE
74+ $(EXTRA_EXAMPLE Sort lines,
7675$(RUNNABLE_EXAMPLE_STDIN
7776Mercury
7877Venus
8382Uranus
8483Neptune)
8584----
86- // Sort lines
8785import std.stdio, std.array, std.algorithm;
8886
8987void main()
@@ -111,6 +109,31 @@ $(SCRIPT
111109 var rouletteIndex = Math.floor(Math.random() * examples.length);
112110 var rouletteChild = examples[rouletteIndex];
113111 rouletteChild.style.display = "block";
112+
113+ // build a list of the titles of all examples and add an option chooser to
114+ // allow switching between them
115+ var titles = Array.prototype.map.call(examples, function(e) {
116+ return e.getElementsByClassName("your-code-here-title")[0].innerText;
117+ });
118+ var sel = document.createElement("select");
119+ Array.prototype.forEach.call(titles, function(title, i) {
120+ var el = document.createElement("option");
121+ el.value = i;
122+ el.innerText = title;
123+ sel.appendChild(el);
124+ });
125+ sel.selectedIndex = rouletteIndex;
126+ sel.addEventListener("change", function(e) {
127+ examples[rouletteIndex].style.display = "none";
128+ rouletteIndex = sel.selectedIndex;
129+ examples[rouletteIndex].style.display = "block";
130+ });
131+ var selEl = document.getElementById("your-code-here-select-example");
132+ selEl.appendChild(sel);
133+ var caret = document.createElement("i");
134+ caret.className = "fa fa-caret-down";
135+ caret.style.marginLeft = "-15px";
136+ selEl.appendChild(caret);
114137 })();
115138)
116139
@@ -482,7 +505,11 @@ Macros:
482505 TAG2=<$1 $2>$3</$1>
483506 D=<span class="d_inlinecode">$0</span>
484507 EXAMPLE=$(TAG2 a, id="a$1-control" class="example-control", )$(TAG2 div, id="a$1" class="example-box", $(RUNNABLE_EXAMPLE $2))
485- EXTRA_EXAMPLE=<div class="your-code-here-extra" style="display:none">$(RUNNABLE_EXAMPLE $0)</div>
508+ EXTRA_EXAMPLE=<div class="your-code-here-extra" style="display:none">
509+ $(DIVC your-code-here-title, $1)
510+ $(RUNNABLE_EXAMPLE $+)
511+ </div>
512+ _=
486513 LAYOUT_PREFIX=
487514 LAYOUT_SUFFIX=
488515 $(SCRIPTLOAD $(ROOT_DIR)js/platform-downloads.js, data-latest="$(LATEST)")
0 commit comments