-
Notifications
You must be signed in to change notification settings - Fork 0
/
foot_scripts.html
109 lines (97 loc) · 4.09 KB
/
foot_scripts.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<!-- Import jQuery -->
<script type="text/javascript" src="https://code.jquery.com/jquery-latest.js"></script>
<!-- Import Tether -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<!-- Import Bootstrap Javascript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
<!-- MathJax -->
<script type="text/javascript" asyn src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?..."></script>
{% if page.is_post %}
<script>
$(document).ready(function() {
// CREATE CUSTOM POST NAVIGATION
// use kramdown auto generated TOC - https://kramdown.gettalong.org/converter/html.html#toc
// transform into bootstrap nav, and apply scrollspy
// wrap markdown-toc in navbar div
$('#markdown-toc').wrap('<nav id="post-nav" class="navbar post-nav"></div>');
// add scrollspy to post navigation
$('body').scrollspy({target: "#post-nav", offset: 50});
// format toc objects with classes for custom scrollspy
$('#markdown-toc').addClass('nav justify-content-center');
$('#markdown-toc li').addClass('nav-item');
$('#markdown-toc a').addClass('nav-link');
// capitalize headings - because I do not in markdown
$('#markdown-toc a').css({"text-transform": "capitalize"});
// loop thru toc list, get headings
// pad each heading to clear post-nav when linked
$('#markdown-toc li a').each(function(index) {
heading = $(this).attr('id');
// remove auto pre text from toc id
heading = heading.replace("markdown-toc-", "")
$("#"+heading).css({"padding-top": "50px"});
});
// fix post navbar on scroll past
var distanceFromTop = $('#post-nav').offset().top;
$(window).scroll(function() {
var currentScroll = $(window).scrollTop();
if (currentScroll >= distanceFromTop) {
$('#post-nav').addClass('fixed-top');
} else {
$('#post-nav').removeClass('fixed-top');
}
});
// add links to post headers
$(function() {
return $("h1, h2, h3, h4, h5, h6").each(function(i, el) {
var $el, icon, id;
$el = $(el);
id = $el.attr('id');
icon = '<i class="material-icons">link</i>';
if (id) {
return $el.prepend($("<a />").addClass("header-link").attr("href", "#" + id).html(icon));
}
});
});
// convert kramdown tables to bootstrap tables
$(".post-content table").addClass("table table-bordered table-striped table-responsive table-sm");
// $(".post-content table thead").addClass("thead-default");
// center and make fluid all post images
$(".post-content img").addClass('img-fluid mx-auto d-block');
});
// dynamically add navigation button (go to top) if scrolled to bottom
$(window).scroll(function(){
// if distance from top, plus window height greater than document height minus buffer
// i.e. if bottom of screen is within 200 pixels from bottom of document
if ($(window).scrollTop() + $(window).height() > $(document).height() - 400) {
$('#back2top').fadeIn();
} else {
$('#back2top').fadeOut();
}
});
$('#back2top').click(function(){
// scroll back to top
$("html, body").animate({ scrollTop: 0 }, 400);
});
</script>
{% endif %}
{% if page.is_notebook %}
<script>
$('#toggle_code_blocks').click(function(){
$('div.input').toggle();
});
// dynamically add navigation button (go to top) if scrolled to bottom
$(window).scroll(function(){
// if distance from top, plus window height greater than document height minus buffer
// i.e. if bottom of screen is within 200 pixels from bottom of document
if ($(window).scrollTop() + $(window).height() > $(document).height() - 400) {
$('#back2top').fadeIn();
} else {
$('#back2top').fadeOut();
}
});
$('#back2top').click(function(){
// scroll back to top
$("html, body").animate({ scrollTop: 0 }, 400);
});
</script>
{% endif %}