daux.io/themes/daux/js/daux.js

99 lignes
3.4 KiB
JavaScript
Brut Vue normale Historique

2018-02-27 22:47:07 +01:00
/** global localStorage, hljs */
if (hljs) {
hljs.initHighlightingOnLoad();
}
2015-08-13 23:03:19 +02:00
//Initialize CodeBlock Visibility Settings
$(function () {
2016-05-23 20:09:15 +02:00
var codeBlockView = $('.Columns__right'),
codeBlocks = $('.s-content pre'),
toggleCodeSection = $('.CodeToggler'),
toggleCodeBlockBtns = toggleCodeSection.find('.CodeToggler__button'),
toggleCodeBlockBtn = toggleCodeSection.find('.CodeToggler__button--main'),
toggleCodeBlockBtnHide = toggleCodeSection.find('.CodeToggler__button--hide'),
toggleCodeBlockBtnBelow = toggleCodeSection.find('.CodeToggler__button--below'),
toggleCodeBlockBtnFloat = toggleCodeSection.find('.CodeToggler__button--float');
2015-08-13 23:03:19 +02:00
// If there is no code block we hide the link
if (!codeBlocks.size()) {
2018-02-26 22:46:36 +01:00
toggleCodeSection.addClass('Hidden');
2015-08-13 23:03:19 +02:00
return;
}
2016-05-23 20:09:15 +02:00
function setCodeBlockStyle(codeBlockState) {
localStorage.setItem("codeBlockState", codeBlockState);
toggleCodeBlockBtns.removeClass("Button--active");
switch (codeBlockState) {
2016-07-29 22:38:03 +02:00
case 2: // Show code blocks inline
toggleCodeBlockBtnFloat.addClass("Button--active");
codeBlockView.addClass('Columns__right--float');
2017-12-11 21:14:18 +01:00
codeBlockView.removeClass('Columns__right--full');
2018-02-26 22:46:36 +01:00
codeBlocks.removeClass('Hidden');
2016-05-23 20:09:15 +02:00
break;
case 1: // Show code blocks below
toggleCodeBlockBtnBelow.addClass("Button--active");
2017-10-19 21:20:58 +02:00
toggleCodeBlockBtn.prop('checked', true);
2016-05-23 20:09:15 +02:00
codeBlockView.removeClass('Columns__right--float');
2017-12-11 21:14:18 +01:00
codeBlockView.addClass('Columns__right--full');
2018-02-26 22:46:36 +01:00
codeBlocks.removeClass('Hidden');
2016-05-23 20:09:15 +02:00
break;
2016-07-29 22:38:03 +02:00
case 0: // Hidden code blocks
default:
toggleCodeBlockBtnHide.addClass("Button--active");
2017-10-19 21:20:58 +02:00
toggleCodeBlockBtn.prop('checked', false);
2016-07-29 22:38:03 +02:00
codeBlockView.removeClass('Columns__right--float');
2017-12-11 21:14:18 +01:00
codeBlockView.addClass('Columns__right--full');
2018-02-26 22:46:36 +01:00
codeBlocks.addClass('Hidden');
2016-05-23 20:09:15 +02:00
break;
}
}
2016-04-08 00:13:06 +02:00
2016-05-23 20:09:15 +02:00
toggleCodeBlockBtn.click(function() {
2018-02-26 22:46:36 +01:00
setCodeBlockStyle(codeBlocks.hasClass('Hidden') ? 1 : 0);
2016-05-23 20:09:15 +02:00
});
2015-08-13 23:03:19 +02:00
2016-05-23 20:09:15 +02:00
toggleCodeBlockBtnHide.click(function() { setCodeBlockStyle(0); });
toggleCodeBlockBtnBelow.click(function() { setCodeBlockStyle(1); });
toggleCodeBlockBtnFloat.click(function() { setCodeBlockStyle(2); });
2016-04-08 00:23:12 +02:00
2016-05-23 20:09:15 +02:00
var floating = $(document.body).hasClass("with-float");
var codeBlockState = localStorage.getItem("codeBlockState");
2016-04-08 00:23:12 +02:00
2015-08-13 23:03:19 +02:00
if (!codeBlockState) {
2016-04-08 00:23:12 +02:00
codeBlockState = floating? 2 : 1;
} else {
codeBlockState = parseInt(codeBlockState);
}
if (!floating && codeBlockState == 2) {
codeBlockState = 1;
}
2015-08-13 23:03:19 +02:00
setCodeBlockStyle(codeBlockState);
});
$(function () {
2015-07-21 22:36:46 +02:00
// Tree navigation
$('.aj-nav').click(function (e) {
e.preventDefault();
$(this).parent().siblings().find('ul').slideUp();
$(this).next().slideToggle();
});
// New Tree navigation
2016-05-23 20:09:15 +02:00
$('ul.Nav > li.has-children > a > .Nav__arrow').click(function() {
$(this).parent().parent().toggleClass('Nav__item--open');
return false;
});
2015-07-21 22:36:46 +02:00
// Responsive navigation
2016-05-23 20:09:15 +02:00
$('.Collapsible__trigger').click(function () {
$('.Collapsible__content').slideToggle();
2015-07-21 22:36:46 +02:00
});
});
2015-08-13 23:03:19 +02:00