Skip to content

Commit 034b889

Browse files
committed
Allow to select an example on the front page
1 parent 842aad8 commit 034b889

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed

css/style.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,6 +1737,22 @@ input.resetButton{display: none}
17371737
.runnable-examples-args {
17381738
display: none;
17391739
}
1740+
.your-code-here-title {
1741+
display: none;
1742+
}
1743+
#your-code-here-select-example {
1744+
padding-bottom: 0.3em;
1745+
}
1746+
#your-code-here-select-example select {
1747+
background: white;
1748+
border: 1px solid #CCC;
1749+
border-radius: 4px;
1750+
padding: 0.3em 20px 0.3em 0.3em;
1751+
font-size: 0.95em;
1752+
-webkit-appearance: none;
1753+
-moz-appearance: none;
1754+
appearance: none;
1755+
}
17401756
/* Runnable-examples css -end */
17411757

17421758
.page-contents

index.dd

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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
3334
The D programming language
3435
Modern convenience.
3536
Modeling power.
3637
Native efficiency.)
3738
----
38-
// Compute average line length for stdin
3939
void 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
5655
import 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
7675
Mercury
7776
Venus
@@ -82,7 +81,6 @@ Saturn
8281
Uranus
8382
Neptune)
8483
----
85-
// Sort lines
8684
import std.stdio, std.array, std.algorithm;
8785

8886
void 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

Comments
 (0)