Clean up custom.js, rename to daux.js

This commit is contained in:
Stéphane Goetz 2015-07-21 22:36:46 +02:00
parent 848e68ea55
commit 0298b7bf91
2 changed files with 72 additions and 30 deletions

View File

@ -1,26 +1,48 @@
$(function () {
$('.aj-nav').click(function (e) {
e.preventDefault();
$(this).parent().siblings().find('ul').slideUp();
$(this).next().slideToggle();
});
$('table').addClass('table');
$('#menu-spinner-button').click(function () {
$('#sub-nav-collapse').slideToggle();
});
_ = {};
$(window).resize(function () {
// Remove transition inline style on large screens
if ($(window).width() >= 768)
$('#sub-nav-collapse').removeAttr('style');
});
});
_.now = Date.now || function() {
return new Date().getTime();
};
//Fix GitHub Ribbon overlapping Scrollbar
var t = $('#github-ribbon');
var a = $('article');
if (t[0] && a[0] && a[0].scrollHeight > $('.right-column').height()) t[0].style.right = '16px';
_.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;
}
return result;
};
};
var codeBlocks, codeBlockView, toggleCodeBlockBtn, codeBlockState;
function toggleCodeBlocks() {
codeBlockState = (codeBlockState + 1) % 3;
localStorage.setItem("codeBlockState", codeBlockState);
setCodeBlockStyle(codeBlockState);
}
function setCodeBlockStyle(x) {
switch (x) {
@ -38,19 +60,39 @@ function setCodeBlockStyle(x) {
case 2:
toggleCodeBlockBtn.innerHTML = "Show Code Blocks";
codeBlockView.removeClass('float-view');
codeBlocks.addClass('hidden');
codeBlocks.addClass('hidden');
break;
}
}
function toggleCodeBlocks() {
codeBlockState = (codeBlockState + 1) % 3;
localStorage.setItem("codeBlockState", codeBlockState);
setCodeBlockStyle(codeBlockState);
}
//Initialize CodeBlock Visibility Settings
$(function () {
// Tree navigation
$('.aj-nav').click(function (e) {
e.preventDefault();
$(this).parent().siblings().find('ul').slideUp();
$(this).next().slideToggle();
});
// Responsive navigation
$('#menu-spinner-button').click(function () {
$('#sub-nav-collapse').slideToggle();
});
//Github ribbon placement
var ribbon = $('#github-ribbon');
function onResize() {
//Fix GitHub Ribbon overlapping Scrollbar
var a = $('article');
if (ribbon[0] && a[0] && a[0].scrollHeight > $('.right-column').height()) {
ribbon[0].style.right = '16px';
} else {
ribbon[0].style.right = '';
}
}
$(window).resize(_.debounce(onResize, 100));
onResize();
//Initialize CodeBlock Visibility Settings
toggleCodeBlockBtn = $('#toggleCodeBlockBtn')[0];
codeBlockView = $('.right-column');
codeBlocks = $('.content-page article > pre');
@ -65,4 +107,4 @@ $(function () {
toggleCodeBlockBtn.classList.add('hidden');
}
setCodeBlockStyle(codeBlockState);
});
});

View File

@ -56,6 +56,6 @@
echo '<script src="' . $js . '"></script>';
} ?>
<script src="<?= $base_url; ?>resources/js/custom.js"></script>
<script src="<?= $base_url; ?>resources/js/daux.js"></script>
</body>
</html>