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