Optimize Code Block View toggling. Also auto-hide Code section for pages without code
This commit is contained in:
parent
8c02c01831
commit
37226d4b66
77
js/custom.js
77
js/custom.js
@ -5,15 +5,11 @@ $(function () {
|
|||||||
$(this).next().slideToggle();
|
$(this).next().slideToggle();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Bootstrap Table Class
|
|
||||||
$('table').addClass('table');
|
$('table').addClass('table');
|
||||||
|
|
||||||
// Responsive menu spinner
|
|
||||||
$('#menu-spinner-button').click(function () {
|
$('#menu-spinner-button').click(function () {
|
||||||
$('#sub-nav-collapse').slideToggle();
|
$('#sub-nav-collapse').slideToggle();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Catch browser resize
|
|
||||||
$(window).resize(function () {
|
$(window).resize(function () {
|
||||||
// Remove transition inline style on large screens
|
// Remove transition inline style on large screens
|
||||||
if ($(window).width() >= 768)
|
if ($(window).width() >= 768)
|
||||||
@ -26,40 +22,47 @@ var t = $('#github-ribbon');
|
|||||||
var a = $('article');
|
var a = $('article');
|
||||||
if (t[0] && a[0] && a[0].scrollHeight > $('.right-column').height()) t[0].style.right = '16px';
|
if (t[0] && a[0] && a[0].scrollHeight > $('.right-column').height()) t[0].style.right = '16px';
|
||||||
|
|
||||||
//Toggle Code Block Visibility
|
function setCodeBlockStyle(x) {
|
||||||
function toggleCodeBlocks() {
|
switch (x) {
|
||||||
var t = localStorage.getItem("toggleCodeStats")
|
default:
|
||||||
t = (t + 1) % 3;
|
case 0:
|
||||||
localStorage.setItem("toggleCodeStats", t);
|
toggleCodeBlockBtn.innerHTML = "Show Code Blocks Inline";
|
||||||
var a = $('.content-page article');
|
codeBlockView.addClass('float-view');
|
||||||
var c = a.children().filter('pre');
|
codeBlocks.removeClass('hidden');
|
||||||
var d = $('.right-column');
|
break;
|
||||||
if (d.hasClass('float-view')) {
|
case 1:
|
||||||
d.removeClass('float-view');
|
toggleCodeBlockBtn.innerHTML = "Hide Code Blocks";
|
||||||
$('#toggleCodeBlockBtn')[0].innerHTML = "Hide Code Blocks";
|
codeBlockView.removeClass('float-view');
|
||||||
} else {
|
codeBlocks.removeClass('hidden');
|
||||||
if (c.hasClass('hidden')) {
|
break;
|
||||||
d.addClass('float-view');
|
case 2:
|
||||||
c.removeClass('hidden');
|
toggleCodeBlockBtn.innerHTML = "Show Code Blocks";
|
||||||
$('#toggleCodeBlockBtn')[0].innerHTML = "Show Code Blocks Inline";
|
codeBlockView.removeClass('float-view');
|
||||||
} else {
|
codeBlocks.addClass('hidden');
|
||||||
c.addClass('hidden');
|
break;
|
||||||
$('#toggleCodeBlockBtn')[0].innerHTML = "Show Code Blocks";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (localStorage.getItem("toggleCodeStats") >= 0) {
|
function toggleCodeBlocks() {
|
||||||
var t = localStorage.getItem("toggleCodeStats");
|
codeBlockState = (codeBlockState + 1) % 3;
|
||||||
if (t == 1) {
|
localStorage.setItem("codeBlockState", codeBlockState);
|
||||||
toggleCodeBlocks();
|
setCodeBlockStyle(codeBlockState);
|
||||||
localStorage.setItem("toggleCodeStats", 1);
|
|
||||||
}
|
|
||||||
if (t == 2) {
|
|
||||||
toggleCodeBlocks();
|
|
||||||
toggleCodeBlocks();
|
|
||||||
localStorage.setItem("toggleCodeStats", 2);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
localStorage.setItem("toggleCodeStats", 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Initialize CodeBlock Visibility Settings
|
||||||
|
$(function () {
|
||||||
|
toggleCodeBlockBtn = $('#toggleCodeBlockBtn')[0];
|
||||||
|
codeBlockView = $('.right-column');
|
||||||
|
codeBlocks = $('.content-page article > pre');
|
||||||
|
codeBlockState = localStorage.getItem("codeBlockState");
|
||||||
|
if (!codeBlockState) {
|
||||||
|
codeBlockState = 0;
|
||||||
|
localStorage.setItem("codeBlockState", codeBlockState);
|
||||||
|
} else codeBlockState = parseInt(codeBlockState);
|
||||||
|
if (!codeBlockView.size()) return;
|
||||||
|
if (!codeBlocks.size()) {
|
||||||
|
codeBlockState = 2;
|
||||||
|
toggleCodeBlockBtn.classList.add('hidden');
|
||||||
|
}
|
||||||
|
setCodeBlockStyle(codeBlockState);
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user