Skip to content

Commit 278c7cc

Browse files
committed
attempt to hack language picker to pick for server cloud
1 parent 5e28e22 commit 278c7cc

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

jekyll/_data/sidenav.yml

-2
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,6 @@ server:
438438
link: 2.0/first-steps/
439439
- name: Hello World
440440
link: 2.0/hello-world/
441-
- name: Hello World MacOS
442-
link: 2.0/hello-world-macos/
443441
- name: Hello World Windows
444442
link: 2.0/hello-world-windows/
445443
- name: Get Started with the CLI

jekyll/_includes/sidebar.html

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
{% assign lang = page.lang %}
55
{% assign sidenav = site.data.sidenav[lang] %}
66
{% assign current_url = page.url | slice: 1, page.url.size %}
7+
<div class="lang-picker">
8+
<select id="sidebarProdSelect">
9+
<option value="en">English</option>
10+
<option value="server">Server v2.x</option>
11+
</select>
12+
</div>
713

814
<div class="sidebar-item-group">
915
{% for main-item in sidenav %}

src-js/prod.js

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* JS related to our product switcher in the sidebar
3+
*/
4+
5+
// helpers -------------------
6+
7+
function getElById(id) {
8+
return document.getElementById(id)
9+
}
10+
11+
var products = {
12+
"en": {name: "Cloud", url: "docs/2.0/"},
13+
"ja": {name: "Server", url: "docs/server/2.x/"}
14+
}
15+
16+
// List of elements that have dynamic content based on our selected product
17+
var els = {
18+
sidebarProdSelect: getElById("sidebarProdSelect"),
19+
};
20+
21+
function reloadWithNewProduct(prodCode) {
22+
window.location.href = "https://circleci.com/" + products[prodCode].url
23+
}
24+
25+
// Sets the sidebar product picker to the currently selected product
26+
function handleSetProductOnLoad() {
27+
var currentProd = window.currentProd; // current prod is set in _includes/sidebar.html
28+
29+
// Set value for 'sidebar'
30+
for(var i, j = 0; i = els.sidebaProdSelect.options[j]; j++) {
31+
if(i.value == currentProd) {
32+
els.sidebarProdSelect.selectedIndex = j;
33+
break;
34+
}
35+
}
36+
}
37+
38+
/**
39+
* Function to run when the sidebar product <select> is changed.
40+
* It checks the newly selected product code and reloads the page in that product.
41+
*/
42+
function handleChangeProductSidebar() {
43+
els.sidebarProdSelect.addEventListener("change", function(e) {
44+
switch(e.target.value) {
45+
case "server":
46+
reloadWithNewLocale("server")
47+
break;
48+
case "en":
49+
reloadWithNewLocale("en")
50+
break;
51+
default:
52+
return;
53+
}
54+
})
55+
}
56+
57+
58+
export function init() {
59+
handleChangeProductSidebar();
60+
handleSetProductOnLoad();
61+
}

0 commit comments

Comments
 (0)