blob: a5e97a40f64de1e9b7ff20be4791e4038bdd7e01 (
plain)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
var NAV_INLINE_BREAKPOINT = 1100;
var landingHeaderBar = document.getElementById('landing-header-bar');
var headerLinks = document.getElementsByClassName('header-link');
if (landingHeaderBar) {
window.addEventListener('scroll', function() {
if (window.scrollY >= 100) {
landingHeaderBar.classList.add('scrolling-header');
for (var i = 0; i < headerLinks.length; i++) {
headerLinks[i].classList.add('scrolling-header-links');
}
} else {
landingHeaderBar.classList.remove('scrolling-header');
for (var i = 0; i < headerLinks.length; i++) {
headerLinks[i].classList.remove('scrolling-header-links');
}
}
});
}
var navtoggle = document.getElementById('docs-nav-toggle');
if (navtoggle) {
navtoggle.addEventListener('click', toggleNavigation);
}
function toggleNavigation() {
nav = document.getElementsByClassName('header')[0];
nav.classList.toggle('active');
}
// move document nav to sidebar
(function() {
var timeofday = document.getElementById('timeofday');
var tocList = document.querySelector('.js-article-content > ul#markdown-toc');
var main = document.querySelector('.js-main-wrapper');
// Set timeofday var depending on the time //
if (timeofday) {
var date = new Date();
var hour = date.getHours();
if (hour < 11) {
timeofday.innerHTML = 'morning';
}
if (hour >= 11 && hour < 16) {
timeofday.innerHTML = 'afternoon';
}
if (hour >= 16) {
timeofday.innerHTML = 'evening';
}
}
// if the document has a top level nav
if (tocList) {
// append to the sidebar
var sidebar = document.getElementById('doc-nav');
if (sidebar) {
// if there are items
if (tocList.children.length >= 1) {
var menu = tocList;
// grab the h1's li anchor text
var title = document.createElement('h4');
title.innerHTML = 'On this page:';
// add the text as a title
menu.insertBefore(title, menu.children[0]);
sidebar.appendChild(menu);
var sidebarContent = sidebar.querySelector('ul');
var sidebarContentHeight = 0;
// remove whitespace between elements to prevent list spacing issues
sidebarContent.innerHTML = sidebarContent.innerHTML.replace(
new RegExp('>[s\r\n]+<', 'g'),
'><'
);
// When we scroll down to the bottom, we don't want the footer covering
// the TOC list (sticky behavior)
document.addEventListener(
'scroll',
function() {
// Wait a cycle for the dimensions to kick in
if (!sidebarContentHeight) {
sidebarContentHeight =
sidebarContent.getBoundingClientRect().height + 55;
}
var isTouchingBottom = false;
if (window.innerWidth >= NAV_INLINE_BREAKPOINT) {
isTouchingBottom =
window.scrollY + sidebarContentHeight >= main.offsetHeight;
}
if (isTouchingBottom) {
sidebarContent.style.top =
main.offsetHeight -
(window.scrollY + sidebarContentHeight) +
'px';
} else {
sidebarContent.style.top = '';
}
},
{ passive: true }
);
}
}
// main content has-toc
if (main && main.classList) {
main.classList.add('has-toc');
} else {
main.className += ' has-toc';
}
}
document.addEventListener('DOMContentLoaded', function() {
var globalNav = document.getElementById('global-nav');
var media = window.matchMedia('(max-width: 1099px)');
window.addEventListener('scroll', function(e) {
var isTouchingBottom = false;
if (!media.matches) {
isTouchingBottom =
window.scrollY + window.innerHeight >=
document.querySelector('.footer').offsetTop;
}
if (isTouchingBottom) {
globalNav.style.top =
main.offsetHeight -
(window.scrollY + globalNav.offsetHeight) +
80 +
'px';
} else {
globalNav.style.top = '';
}
});
if (media.matches) {
var el = document.getElementById('markdown-toc');
el.classList.add('collapse');
el.classList.add('out');
el.style.height = '34px';
el.previousElementSibling.classList.add('collapsed');
}
});
})();
|