Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions _includes/layouts/page.njk
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

{% include "partials/langpicker.njk" %}

{% include "partials/master-main.njk" %}

<div class="max-width">
<header class="spaced">
<h1 class="centered">{{title}}</h1>
Expand Down
36 changes: 36 additions & 0 deletions _includes/partials/master-main.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<div class="master-main-switch">
<label>
<input type="radio" name="master-main" value="master" checked="checked"/>
<code>master</code>
</label>
<label>
<input type="radio" name="master-main" value="main"/>
<code>main</code>
</label>
</div>
<script async="async">
function changeMainBranch(branch) {
const branchWas = branch === 'main'
? /\bmaster\b/g
: /\bmain\b/g;
const nodes = [];
const treeWalker = document.createTreeWalker(document.querySelector('main'), NodeFilter.SHOW_TEXT);
while (treeWalker.nextNode()) {
const node = treeWalker.currentNode;
if (node.nodeType === Node.TEXT_NODE && node.textContent.match(branchWas)) {
nodes.push(node);
}
};
nodes.forEach(function (node) {
node.textContent = node.textContent.replace(branchWas, branch);
});
}
addEventListener('DOMContentLoaded', function () {
console.log('DOMContentLoaded');
document.querySelectorAll('.master-main-switch [type="radio"]').forEach(function (radio) {
radio.addEventListener('change', function () {
changeMainBranch(radio.value);
});
});
});
</script>
32 changes: 29 additions & 3 deletions _includes/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,18 @@ footer {
footer a {
color: white;
}
.langpicker {
.langpicker,
.master-main-switch {
float: right;
margin-top: 0.5em;
margin-bottom: 2em;
margin-bottom: 0.5em;
overflow: hidden;
}
.langpicker * {
box-sizing: border-box;
}
.langpicker-button {
.langpicker-button,
.master-main-switch {
border: 2px solid #222;
background: none;
font-size: 1em;
Expand Down Expand Up @@ -113,6 +115,30 @@ footer a {
display: inline-block;
color: #fff;
}
.master-main-switch {
clear: right;
margin-top: 0;
margin-bottom: 2em;
height: auto;
padding: 0;
align-items: center;
}
.master-main-switch code {
display: block;
font: inherit;
font-weight: bold;
padding: 0.25em 0.5em;
cursor: pointer;
color: black;
background: white;
}
.master-main-switch input {
display: none;
}
.master-main-switch input:checked + code {
background: black;
color: white;
}
.max-width {
margin: 1em;
clear: both;
Expand Down