2022-03-15 14:16:44 +01:00
|
|
|
$('#mysidebar').height($('.nav').height());
|
2016-09-07 16:10:48 -04:00
|
|
|
|
2022-02-23 19:21:02 +01:00
|
|
|
// Detect small devices and move the TOC in line
|
2022-03-15 14:16:44 +01:00
|
|
|
function moveToc() {
|
|
|
|
if (window.innerWidth < 1350) {
|
|
|
|
$('#toc').detach().appendTo('#inline-toc').removeClass('affix');
|
2022-02-23 19:21:02 +01:00
|
|
|
} else {
|
2022-03-15 14:16:44 +01:00
|
|
|
$('#toc').detach().appendTo('.toc-col').addClass('affix');
|
2022-02-23 19:21:02 +01:00
|
|
|
}
|
|
|
|
}
|
2016-09-07 16:10:48 -04:00
|
|
|
|
2022-03-15 14:16:44 +01:00
|
|
|
$(document).ready(function () {
|
|
|
|
$('#toc').toc({
|
|
|
|
minimumHeaders: 0,
|
|
|
|
listType: 'ul',
|
|
|
|
showSpeed: 0,
|
|
|
|
headers: 'h2,h3,h4',
|
|
|
|
});
|
2016-09-07 16:10:48 -04:00
|
|
|
|
|
|
|
//this script says, if the height of the viewport is greater than 800px, then insert affix class, which makes the nav bar float in a fixed
|
|
|
|
// position as your scroll. if you have a lot of nav items, this height may not work for you.
|
|
|
|
var h = $(window).height();
|
|
|
|
//console.log (h);
|
2022-02-23 19:21:02 +01:00
|
|
|
if (h > 600) {
|
2022-03-15 14:16:44 +01:00
|
|
|
$('#mysidebar').attr('class', 'nav affix');
|
2016-09-07 16:10:48 -04:00
|
|
|
}
|
|
|
|
// activate tooltips. although this is a bootstrap js function, it must be activated this way in your theme.
|
|
|
|
$('[data-toggle="tooltip"]').tooltip({
|
2022-03-15 14:16:44 +01:00
|
|
|
placement: 'top',
|
2016-09-07 16:10:48 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* AnchorJS
|
|
|
|
*/
|
|
|
|
anchors.add('h2,h3,h4,h5');
|
2022-03-15 14:16:44 +01:00
|
|
|
|
|
|
|
// Add an "Edit on GitHub" button to each header (except h1)
|
|
|
|
let url = $('div.post-content').attr('data-github-edit-url');
|
|
|
|
|
|
|
|
$('div.post-content')
|
|
|
|
.find(':header:not(h1)')
|
|
|
|
.append(
|
|
|
|
' <a class="edit-header" target="_blank" href=' +
|
|
|
|
url +
|
|
|
|
' role="button">✏️️</a>'
|
|
|
|
);
|
|
|
|
|
2022-02-23 19:21:02 +01:00
|
|
|
// Check if TOC needs to be moved on page load
|
|
|
|
moveToc();
|
2016-09-07 16:10:48 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
// needed for nav tabs on pages. See Formatting > Nav tabs for more details.
|
|
|
|
// script from http://stackoverflow.com/questions/10523433/how-do-i-keep-the-current-tab-active-with-twitter-bootstrap-after-a-page-reload
|
2022-03-15 14:16:44 +01:00
|
|
|
$(function () {
|
2016-09-07 16:10:48 -04:00
|
|
|
var json, tabsState;
|
2022-03-15 14:16:44 +01:00
|
|
|
$('a[data-toggle="pill"], a[data-toggle="tab"]').on(
|
|
|
|
'shown.bs.tab',
|
|
|
|
function (e) {
|
|
|
|
var href, json, parentId, tabsState;
|
2016-09-07 16:10:48 -04:00
|
|
|
|
2022-03-15 14:16:44 +01:00
|
|
|
tabsState = localStorage.getItem('tabs-state');
|
|
|
|
json = JSON.parse(tabsState || '{}');
|
|
|
|
parentId = $(e.target)
|
|
|
|
.parents('ul.nav.nav-pills, ul.nav.nav-tabs')
|
|
|
|
.attr('id');
|
|
|
|
href = $(e.target).attr('href');
|
|
|
|
json[parentId] = href;
|
2016-09-07 16:10:48 -04:00
|
|
|
|
2022-03-15 14:16:44 +01:00
|
|
|
return localStorage.setItem('tabs-state', JSON.stringify(json));
|
|
|
|
}
|
|
|
|
);
|
2016-09-07 16:10:48 -04:00
|
|
|
|
2022-03-15 14:16:44 +01:00
|
|
|
tabsState = localStorage.getItem('tabs-state');
|
|
|
|
json = JSON.parse(tabsState || '{}');
|
2016-09-07 16:10:48 -04:00
|
|
|
|
2022-03-15 14:16:44 +01:00
|
|
|
$.each(json, function (containerId, href) {
|
|
|
|
return $('#' + containerId + ' a[href=' + href + ']').tab('show');
|
2016-09-07 16:10:48 -04:00
|
|
|
});
|
|
|
|
|
2022-03-15 14:16:44 +01:00
|
|
|
$('ul.nav.nav-pills, ul.nav.nav-tabs').each(function () {
|
2016-09-07 16:10:48 -04:00
|
|
|
var $this = $(this);
|
2022-03-15 14:16:44 +01:00
|
|
|
if (!json[$this.attr('id')]) {
|
|
|
|
return $this
|
|
|
|
.find('a[data-toggle=tab]:first, a[data-toggle=pill]:first')
|
|
|
|
.tab('show');
|
2016-09-07 16:10:48 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2022-02-23 19:21:02 +01:00
|
|
|
|
|
|
|
// Check if TOC needs to be moved on window resizing
|
2022-03-15 14:16:44 +01:00
|
|
|
$(window).resize(function () {
|
|
|
|
moveToc();
|
|
|
|
});
|