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

149 regels
4.5 KiB
JavaScript

2013-06-12 00:28:29 +02:00
2015-07-21 22:36:46 +02:00
_ = {};
2015-07-21 22:36:46 +02:00
_.now = Date.now || function() {
return new Date().getTime();
};
_.debounce = function(func, wait, immediate) {
var timeout, args, context, timestamp, result;
var later = function() {
var last = _.now() - timestamp;
if (last < wait && last >= 0) {
timeout = setTimeout(later, wait - last);
} else {
timeout = null;
if (!immediate) {
result = func.apply(context, args);
if (!timeout) context = args = null;
}
}
};
return function() {
context = this;
args = arguments;
timestamp = _.now();
var callNow = immediate && !timeout;
if (!timeout) timeout = setTimeout(later, wait);
if (callNow) {
result = func.apply(context, args);
context = args = null;
}
2015-07-21 22:36:46 +02:00
return result;
};
};
2016-05-23 20:09:15 +02:00
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()) {
2016-04-08 00:13:06 +02: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");
console.log("Toggle", codeBlockState);
switch (codeBlockState) {
default:
case 0: // Hidden code blocks
toggleCodeBlockBtnHide.addClass("Button--active");
toggleCodeBlockBtn.html("Show Code Blocks");
codeBlockView.removeClass('Columns__right--float');
codeBlocks.addClass('hidden');
break;
case 1: // Show code blocks below
toggleCodeBlockBtnBelow.addClass("Button--active");
toggleCodeBlockBtn.html("Hide Code Blocks");
codeBlockView.removeClass('Columns__right--float');
codeBlocks.removeClass('hidden');
break;
case 2: // Show code blocks inline
toggleCodeBlockBtnFloat.addClass("Button--active");
codeBlockView.addClass('Columns__right--float');
codeBlocks.removeClass('hidden');
break;
}
}
2016-04-08 00:13:06 +02:00
2016-05-23 20:09:15 +02:00
toggleCodeBlockBtn.click(function() {
setCodeBlockStyle(codeBlocks.hasClass('hidden') ? 1 : 0);
});
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
});
//Github ribbon placement
var ribbon = $('#github-ribbon');
function onResize() {
//Fix GitHub Ribbon overlapping Scrollbar
var a = $('article');
2016-01-08 11:04:35 +01:00
if (ribbon.length && a.length) {
2016-01-08 11:00:44 +01:00
if (a[0] && a[0].scrollHeight > $('.right-column').height()) {
ribbon[0].style.right = '16px';
} else {
ribbon[0].style.right = '';
}
2015-07-21 22:36:46 +02:00
}
}
$(window).resize(_.debounce(onResize, 100));
onResize();
});
2015-08-13 23:03:19 +02:00