-
Notifications
You must be signed in to change notification settings - Fork 0
/
footer.html
171 lines (152 loc) · 5.75 KB
/
footer.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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
{{ $include_toc := .Params.include_toc}}
<footer>
{{ partial "github-edit-link.html" . }}
{{ if .Site.GoogleAnalytics }}
<!-- Google Analytics -->
{{ template "_internal/google_analytics_async.html" . }}
{{ end }}
{{ partial "footer/font-awesome-js.html" . }}
{{ partial "footer/mathjax-js.html" . }}
{{ partial "highlight-js.html" . }}
<script src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.2.0/zepto.min.js" integrity="sha256-vrn14y7WH7zgEElyQqm2uCGSQrX/xjYDjniRUQx3NyU=" crossorigin="anonymous"></script>
<script type="text/javascript">
function addBlockSwitches() {
$('.primary').each(function() {
primary = $(this);
createSwitchItem(primary, createBlockSwitch(primary)).item.addClass("selected");
primary.children('.title').remove();
});
$('.secondary').each(function(idx, node) {
secondary = $(node);
primary = findPrimary(secondary);
switchItem = createSwitchItem(secondary, primary.children('.switch'));
switchItem.content.addClass('hidden');
findPrimary(secondary).append(switchItem.content);
secondary.remove();
});
}
function createBlockSwitch(primary) {
blockSwitch = $('<div class="switch"></div>');
primary.prepend(blockSwitch);
return blockSwitch;
}
function findPrimary(secondary) {
candidate = secondary.prev();
while (!candidate.is('.primary')) {
candidate = candidate.prev();
}
return candidate;
}
function createSwitchItem(block, blockSwitch) {
blockName = block.children('.title').text();
content = block.children('.content').first().append(block.next('.colist'));
item = $('<div class="switch--item">' + blockName + '</div>');
blockSwitch.append(item);
return {'item': item, 'content': content};
}
function globalSwitch() {
$('.switch--item').each(function() {
var blockId = blockIdForSwitchItem($(this));
$(this).off('click');
$(this).on('click', function() {
selectedText = $(this).text()
window.localStorage.setItem(blockId, selectedText);
$(".switch--item").filter(function() {
return blockIdForSwitchItem($(this)) === blockId;
}).filter(function() {
return $(this).text() === selectedText;
}).each(function() {
select($(this))
});
});
if ($(this).text() === window.localStorage.getItem(blockId)) {
select($(this))
}
});
}
function blockIdForSwitchItem(item) {
idComponents = []
idComponents.push(item.text().toLowerCase());
item.siblings(".switch--item").each(function(index, sibling) {
idComponents.push($(sibling).text().toLowerCase());
});
return idComponents.sort().join("-")
}
function select(selected) {
selected.addClass('selected');
selected.siblings().removeClass('selected');
selectedContent = selected.parent().siblings(".content").eq(selected.index())
selectedContent.removeClass('hidden');
selectedContent.siblings().addClass('hidden');
}
$(addBlockSwitches);
$(globalSwitch);
</script>
<script type="text/javascript">
// based on https://codepen.io/saas/pen/LYENgqq
// Adapted for the non-semantic HTML output of asciidoctor
window.addEventListener("load", () => {
if (!'IntersectionObserver' in window) {
return;
}
// Retrieve all sections
const sections = Array.from(document.querySelectorAll("section[id], h2[id], h3[id], h4[id], h5[id]"));
const visibleSectionClass = "visible-section";
// Once a scrolling event is detected, iterate all elements
// whose visibility changed and highlight their navigation entry
const scrollHandler = entries =>
entries.forEach(entry => {
const section = entry.target;
const sectionId = section.id;
const sectionLink = document.querySelector(`a[href="#${sectionId}"]`);
console.log(sectionId, sectionLink);
console.log(entry)
console.log(entry.intersectionRect.height / entry.rootBounds.height)
if (entry.intersectionRatio > 0) {
section.classList.add(visibleSectionClass);
sectionLink.classList.add(visibleSectionClass);
} else {
section.classList.remove(visibleSectionClass);
sectionLink.classList.remove(visibleSectionClass);
}
});
// Creates a new scroll observer
const observer = new IntersectionObserver(scrollHandler);
sections.map(section => {
if (section.tagName === "SECTION") {
return section;
} else {
// in the case of asciidoctor, the section is a title that is contained
// in a div with classes like "sect1", "sect2", to represent nested
// sections. Using the enclosing element is necessary otherwise the menu
// will only highlight the title when it is visible. While we want to
// keep the menu highlight for the whole section.
//
// Also, the scrollHandler need to work with the section id so it's added
// to the enclosing element.
let actualSectionContainer = section.parentElement;
actualSectionContainer.id = section.id;
return actualSectionContainer;
}
}).forEach(section => observer.observe(section));
});
</script>
{{ with .Site.Params.toc }}
{{ if and (eq . "tocbot") (ne $include_toc false) }}
<script src="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.18.2/tocbot.min.js" integrity="sha512-g3ESN5HI4E4N2ZsgXw6mcLgD6U8qs1vneuEhN8xq3fQcgiBz7MD1jIMBjf404FPu8NrEaJNUwwxholBy4NiIZg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script type="text/javascript">
if (tocbot) {
tocbot.init({
// Where to render the table of contents.
tocSelector: '.toc',
// Where to grab the headings to build the table of contents.
contentSelector: '.post',
// Which headings to grab inside of the contentSelector element.
headingSelector: 'h2, h3, h4',
collapseDepth: 4
});
}
</script>
{{ end }}
{{ end }}
</footer>