2018-02-27 22:47:07 +01:00
|
|
|
/** global localStorage, hljs */
|
|
|
|
|
|
|
|
if (hljs) {
|
|
|
|
hljs.initHighlightingOnLoad();
|
|
|
|
}
|
2014-02-13 13:21:27 +01:00
|
|
|
|
2019-08-10 04:55:18 +02:00
|
|
|
(function() {
|
|
|
|
var codeBlocks = document.querySelectorAll(".s-content pre");
|
|
|
|
var toggleCodeSection = document.querySelector(".CodeToggler");
|
|
|
|
if (!toggleCodeSection) {
|
|
|
|
return;
|
|
|
|
} else if (!codeBlocks.length) {
|
|
|
|
toggleCodeSection.classList.add("Hidden");
|
2015-08-13 23:03:19 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-10 04:55:18 +02:00
|
|
|
var toggleCodeBlockBtnList = toggleCodeSection.querySelectorAll(".CodeToggler__button");
|
|
|
|
var toggleCodeBlockBtnSet = toggleCodeSection.querySelector(".CodeToggler__button--main"); // available when floating is disabled
|
|
|
|
var toggleCodeBlockBtnHide = toggleCodeSection.querySelector(".CodeToggler__button--hide");
|
|
|
|
var toggleCodeBlockBtnBelow = toggleCodeSection.querySelector(".CodeToggler__button--below");
|
|
|
|
var toggleCodeBlockBtnFloat = toggleCodeSection.querySelector(".CodeToggler__button--float");
|
|
|
|
var codeBlockView = document.querySelector(".Columns__right");
|
|
|
|
var floating = document.body.classList.contains("with-float");
|
|
|
|
|
2016-05-23 20:09:15 +02:00
|
|
|
function setCodeBlockStyle(codeBlockState) {
|
2019-08-10 04:55:18 +02:00
|
|
|
for (var a = 0; a < toggleCodeBlockBtnList.length; a++) {
|
|
|
|
toggleCodeBlockBtnList[a].classList.remove("Button--active");
|
2019-08-09 00:19:37 +02:00
|
|
|
}
|
2016-05-23 20:09:15 +02:00
|
|
|
switch (codeBlockState) {
|
2019-08-10 04:55:18 +02:00
|
|
|
case true: // Show code blocks below (flowed); checkbox
|
|
|
|
var hidden = false;
|
|
|
|
break;
|
|
|
|
case false: // Hidden code blocks; checkbox
|
|
|
|
var hidden = true;
|
2016-05-23 20:09:15 +02:00
|
|
|
break;
|
2019-08-10 04:55:18 +02:00
|
|
|
case 2: // Show code blocks inline (floated)
|
|
|
|
toggleCodeBlockBtnFloat.classList.add("Button--active");
|
|
|
|
codeBlockView.classList.add("Columns__right--float");
|
|
|
|
codeBlockView.classList.remove("Columns__right--full");
|
|
|
|
var hidden = false;
|
|
|
|
break;
|
|
|
|
case 1: // Show code blocks below (flowed)
|
|
|
|
case "checked":
|
|
|
|
toggleCodeBlockBtnBelow.classList.add("Button--active");
|
|
|
|
codeBlockView.classList.remove("Columns__right--float");
|
|
|
|
codeBlockView.classList.add("Columns__right--full");
|
|
|
|
var hidden = false;
|
2016-05-23 20:09:15 +02:00
|
|
|
break;
|
2016-07-29 22:38:03 +02:00
|
|
|
case 0: // Hidden code blocks
|
|
|
|
default:
|
2019-08-10 04:55:18 +02:00
|
|
|
toggleCodeBlockBtnHide.classList.add("Button--active");
|
|
|
|
codeBlockView.classList.remove("Columns__right--float");
|
|
|
|
codeBlockView.classList.add("Columns__right--full");
|
|
|
|
var hidden = true;
|
2016-05-23 20:09:15 +02:00
|
|
|
break;
|
|
|
|
}
|
2019-08-10 04:55:18 +02:00
|
|
|
for (var a = 0; a < codeBlocks.length; a++) {
|
|
|
|
if (hidden) {
|
|
|
|
codeBlocks[a].classList.add("Hidden");
|
|
|
|
} else {
|
|
|
|
codeBlocks[a].classList.remove("Hidden");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
localStorage.setItem("codeBlockState", +codeBlockState);
|
|
|
|
} catch (e) {
|
|
|
|
// local storage operations can fail with the file:// protocol
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!floating) {
|
|
|
|
toggleCodeBlockBtnSet.addEventListener("change", function(ev) {setCodeBlockStyle(ev.target.checked);}, false);
|
|
|
|
} else {
|
|
|
|
toggleCodeBlockBtnHide.addEventListener("click", function() {setCodeBlockStyle(0);}, false);
|
|
|
|
toggleCodeBlockBtnBelow.addEventListener("click", function() {setCodeBlockStyle(1);}, false);
|
|
|
|
toggleCodeBlockBtnFloat.addEventListener("click", function() {setCodeBlockStyle(2);}, false);
|
2016-05-23 20:09:15 +02:00
|
|
|
}
|
2016-04-08 00:13:06 +02:00
|
|
|
|
2019-08-09 00:19:37 +02:00
|
|
|
try {
|
|
|
|
var codeBlockState = localStorage.getItem("codeBlockState");
|
|
|
|
} catch (e) {
|
|
|
|
// local storage operations can fail with the file:// protocol
|
2019-08-10 04:55:18 +02:00
|
|
|
var codeBlockState = null;
|
2019-08-09 00:19:37 +02:00
|
|
|
}
|
2015-08-13 23:03:19 +02:00
|
|
|
if (!codeBlockState) {
|
2019-08-10 04:55:18 +02:00
|
|
|
codeBlockState = floating ? 2 : 1;
|
2016-04-08 00:23:12 +02:00
|
|
|
} else {
|
|
|
|
codeBlockState = parseInt(codeBlockState);
|
|
|
|
}
|
2019-08-10 04:55:18 +02:00
|
|
|
if (!floating) {
|
|
|
|
codeBlockState = !!codeBlockState;
|
2016-04-08 00:23:12 +02:00
|
|
|
}
|
2015-08-13 23:03:19 +02:00
|
|
|
|
|
|
|
setCodeBlockStyle(codeBlockState);
|
2019-08-10 04:55:18 +02:00
|
|
|
})();
|
2015-08-13 23:03:19 +02:00
|
|
|
|
2019-08-10 22:48:18 +02:00
|
|
|
(function() {
|
|
|
|
function debounce(func, wait) {
|
|
|
|
var timeout;
|
|
|
|
return function() {
|
|
|
|
var context = this, args = arguments;
|
|
|
|
var later = function() {
|
|
|
|
timeout = null;
|
|
|
|
};
|
2015-07-21 22:36:46 +02:00
|
|
|
|
2019-08-10 22:48:18 +02:00
|
|
|
clearTimeout(timeout);
|
|
|
|
timeout = setTimeout(later, wait);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-08-11 15:15:11 +02:00
|
|
|
var navItems = document.querySelectorAll('.Nav__item.has-children > a');
|
2019-08-10 22:48:18 +02:00
|
|
|
|
|
|
|
function _toggleSubMenu(ev) {
|
2019-08-11 15:15:11 +02:00
|
|
|
if (ev.preventDefault !== undefined) {
|
|
|
|
ev.preventDefault();
|
|
|
|
}
|
2019-08-10 22:48:18 +02:00
|
|
|
|
|
|
|
var parent = ev.target.parentNode;
|
|
|
|
var subNav = parent.querySelector('ul.Nav');
|
|
|
|
|
2019-08-11 15:15:11 +02:00
|
|
|
if (ev.preventDefault !== undefined && parent.classList.contains('Nav__item--open')) {
|
2019-08-10 22:48:18 +02:00
|
|
|
subNav.style.height = 0;
|
|
|
|
parent.classList.remove('Nav__item--open');
|
|
|
|
} else {
|
2019-08-11 15:15:11 +02:00
|
|
|
if (ev.preventDefault !== undefined) {
|
|
|
|
subNav.style.transitionDuration = Math.max(subNav.scrollHeight, 150) + 'ms';
|
|
|
|
subNav.style.height = subNav.scrollHeight + 'px';
|
|
|
|
parent.classList.add('Nav__item--open');
|
|
|
|
} else {
|
|
|
|
// When running at page load the transitions don't need to fire and
|
|
|
|
// the classList doesn't need to be altered.
|
|
|
|
subNav.style.transitionDuration = '0ms';
|
|
|
|
subNav.style.height = subNav.scrollHeight + 'px';
|
|
|
|
subNav.style.transitionDuration = Math.max(subNav.scrollHeight, 150) + 'ms';
|
|
|
|
}
|
2019-08-10 22:48:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Because font sizes change the height of the menus can change so they must
|
|
|
|
// be recalculated if necessary when the viewport size changes.
|
|
|
|
function _resize() {
|
|
|
|
var subNav = document.querySelector('.Nav .Nav'),
|
|
|
|
height, cur;
|
|
|
|
for (var i = 0; i < subNav.length; i++) {
|
|
|
|
cur = subNav[i];
|
|
|
|
height = parseFloat(cur.style.height, 10);
|
|
|
|
if (height > 0 && cur.scrollHeight !== height) {
|
2019-08-11 15:15:11 +02:00
|
|
|
// Transitions don't need to fire when resizing the window.
|
|
|
|
cur.style.transitionDuration = '0ms';
|
2019-08-10 22:48:18 +02:00
|
|
|
cur.style.height = cur.scrollHeight + 'px';
|
|
|
|
cur.style.transitionDuration = Math.max(cur.scrollHeight, 150) + 'ms';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-02 13:39:04 +02:00
|
|
|
|
2019-08-11 15:15:11 +02:00
|
|
|
for (var i = 0, cur; i < navItems.length; i++) {
|
|
|
|
cur = navItems[i];
|
|
|
|
cur.addEventListener('click', _toggleSubMenu);
|
|
|
|
|
|
|
|
if (cur.parentNode.classList.contains('Nav__item--open')) {
|
|
|
|
_toggleSubMenu({ target: cur });
|
|
|
|
}
|
2019-08-10 22:48:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener('resize', debounce(_resize, 150));
|
|
|
|
window.addEventListener('orientationchange', _resize);
|
2019-08-11 15:15:11 +02:00
|
|
|
|
|
|
|
|
2019-08-10 22:48:18 +02:00
|
|
|
})();
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
var trigger = document.querySelector('.Collapsible__trigger');
|
|
|
|
|
|
|
|
if (!trigger) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
content = document.querySelector('.Collapsible__content');
|
|
|
|
|
|
|
|
trigger.addEventListener('click', function(ev) {
|
|
|
|
if (content.classList.contains('Collapsible__content--open')) {
|
|
|
|
content.style.height = 0;
|
|
|
|
content.classList.remove('Collapsible__content--open');
|
|
|
|
} else {
|
|
|
|
content.style.transitionDuration = Math.max(content.scrollHeight, 150) + 'ms';
|
|
|
|
content.style.height = content.scrollHeight + 'px';
|
|
|
|
content.classList.add('Collapsible__content--open');
|
|
|
|
}
|
2015-07-21 22:36:46 +02:00
|
|
|
});
|
2019-08-10 22:48:18 +02:00
|
|
|
})();
|