forked from pydata/pydata-sphinx-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.js
56 lines (49 loc) · 1.6 KB
/
bootstrap.js
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
// Import and setup functions to control Bootstrap's behavior.
import "@popperjs/core";
import { Tooltip } from "bootstrap";
import { documentReady } from "./mixin";
import "../styles/bootstrap.scss";
/*******************************************************************************
* Trigger tooltips
*/
/**
* Add tooltip to each element with the "tooltip" data-bs-toogle class
*/
function TriggerTooltip() {
var tooltipTriggerList = [].slice.call(
document.querySelectorAll('[data-bs-toggle="tooltip"]')
);
tooltipTriggerList.map(function (tooltipTriggerEl) {
return new Tooltip(tooltipTriggerEl, { delay: { show: 500, hide: 100 } });
});
}
/*******************************************************************************
* back to top button
*/
function backToTop() {
var btn = document.getElementById("pst-back-to-top");
btn.addEventListener("click", function () {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
});
}
function showBackToTop() {
var btn = document.getElementById("pst-back-to-top");
var header = document
.getElementsByClassName("bd-header")[0]
.getBoundingClientRect();
window.addEventListener("scroll", function () {
if (this.oldScroll > this.scrollY && this.scrollY > header.bottom) {
btn.style.display = "block";
} else {
btn.style.display = "none";
}
this.oldScroll = this.scrollY;
});
}
/*******************************************************************************
* Call functions after document loading.
*/
documentReady(TriggerTooltip);
documentReady(backToTop);
documentReady(showBackToTop);