-
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathschema_doc.js
More file actions
74 lines (67 loc) · 2.41 KB
/
Copy pathschema_doc.js
File metadata and controls
74 lines (67 loc) · 2.41 KB
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
document.addEventListener('click', function(event) {
var anchor = event.target.closest('a[href^="#"]');
if (anchor) {
event.preventDefault();
history.pushState({}, '', anchor.href);
}
});
function flashElement(elementId) {
var myElement = document.getElementById(elementId);
if (myElement) {
myElement.classList.add("jsfh-animated-property");
setTimeout(function() {
myElement.classList.remove("jsfh-animated-property");
}, 1000);
}
}
function setAnchor(anchorLinkDestination) {
// Set anchor link without reloading
history.pushState({}, '', anchorLinkDestination);
}
function anchorOnLoad() {
// Added to onload on body, checks if there is an anchor link and if so, expand
var linkTarget = decodeURIComponent(window.location.hash.split("?")[0].split("&")[0]);
if (linkTarget[0] === "#") {
linkTarget = linkTarget.substr(1);
}
if (linkTarget.length > 0) {
anchorLink(linkTarget);
}
}
function anchorLink(linkTarget) {
var target = document.getElementById(linkTarget);
if (!target) return;
// Find the targeted element and all its parents that can be expanded
var element = target;
while (element) {
// Expand collapsed sections
if (element.classList.contains("collapse") && !element.classList.contains("show")) {
var bsCollapse = new bootstrap.Collapse(element, { toggle: true });
}
// Activate tab panes
if (element.classList.contains("tab-pane")) {
var tabTrigger = document.querySelector('a[href="#' + element.id + '"]');
if (tabTrigger) {
var bsTab = new bootstrap.Tab(tabTrigger);
bsTab.show();
}
}
// Handle direct tab links
if (element.getAttribute("role") === "tab") {
var bsTab = new bootstrap.Tab(element);
bsTab.show();
}
element = element.parentElement;
}
// Wait a little so the user has time to see the page scroll
setTimeout(function() {
var targetElement = document.getElementById(linkTarget);
if (targetElement) {
targetElement.scrollIntoView({ block: "center", behavior:"smooth" });
// Flash the element so that the user notices where the link points to
setTimeout(function() {
flashElement(linkTarget);
}, 500);
}
}, 1000);
}