Skip to content

Commit 1ca1706

Browse files
authored
Merge pull request #1777 from wilzbach/example-selecting
Allow to select an example on the front page merged-on-behalf-of: Vladimir Panteleev <github@thecybershadow.net>
2 parents ccf58b5 + e295c23 commit 1ca1706

File tree

2 files changed

+55
-7
lines changed

2 files changed

+55
-7
lines changed

css/style.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,6 +1760,23 @@ div.openInEditorButton {
17601760
.runnable-examples-args {
17611761
display: none;
17621762
}
1763+
.your-code-here-title {
1764+
display: none;
1765+
}
1766+
#your-code-here-select-example {
1767+
padding-bottom: 0.3em;
1768+
}
1769+
#your-code-here-select-example select {
1770+
background: white;
1771+
border: 1px solid #CCC;
1772+
border-radius: 4px;
1773+
padding: 0.3em 20px 0.3em 0.3em;
1774+
font-size: 0.95em;
1775+
-webkit-appearance: none;
1776+
-moz-appearance: none;
1777+
appearance: none;
1778+
max-width: 100%;
1779+
}
17631780
/* Runnable-examples css -end */
17641781

17651782
.page-contents
@@ -2152,6 +2169,10 @@ the home page, intro pitch and your-code-here layed out vertically */
21522169
width: auto;
21532170
max-width: 32em;
21542171
}
2172+
2173+
body#Home #content > .intro #your-code-here .tip {
2174+
display: none;
2175+
}
21552176
}
21562177

21572178
.decl_anchor {

index.dd

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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
3435
The D programming language
3536
Modern convenience.
3637
Modeling power.
3738
Native efficiency.)
3839
----
39-
// Compute average line length for stdin
4040
void 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
5756
import 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
7776
Mercury
7877
Venus
@@ -83,7 +82,6 @@ Saturn
8382
Uranus
8483
Neptune)
8584
----
86-
// Sort lines
8785
import std.stdio, std.array, std.algorithm;
8886

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

Comments
 (0)