| 1 |
// TODO: @trallard might end up moving this to the main JS file |
| 2 |
// Import and setup functions to control Bootstrap's behavior. |
| 3 |
import "@popperjs/core"; |
| 4 |
// Import all of Bootstrap's JS |
| 5 |
import * as bootstrap from "bootstrap"; |
| 6 |
import { documentReady } from "./mixin"; |
| 7 |
|
| 8 |
/******************************************************************************* |
| 9 |
* Trigger tooltips |
| 10 |
*/ |
| 11 |
|
| 12 |
/** |
| 13 |
* Add tooltip to each element with the "tooltip" data-bs-toogle class |
| 14 |
*/ |
| 15 |
function TriggerTooltip() { |
| 16 |
var tooltipTriggerList = [].slice.call( |
| 17 |
document.querySelectorAll('[data-bs-toggle="tooltip"]'), |
| 18 |
); |
| 19 |
tooltipTriggerList.map(function (tooltipTriggerEl) { |
| 20 |
return new bootstrap.Tooltip(tooltipTriggerEl, { |
| 21 |
delay: { show: 500, hide: 100 }, |
| 22 |
}); |
| 23 |
}); |
| 24 |
} |
| 25 |
|
| 26 |
/******************************************************************************* |
| 27 |
* back to top button |
| 28 |
*/ |
| 29 |
function backToTop() { |
| 30 |
var btn = document.getElementById("pst-back-to-top"); |
| 31 |
// Config allows button to be disabled, so check it exists |
| 32 |
if (btn) { |
| 33 |
btn.addEventListener("click", function () { |
| 34 |
document.body.scrollTop = 0; |
| 35 |
document.documentElement.scrollTop = 0; |
| 36 |
}); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
function showBackToTop() { |
| 41 |
var btn = document.getElementById("pst-back-to-top"); |
| 42 |
if (!btn) return; |
| 43 |
var header = document |
| 44 |
.getElementsByClassName("bd-header")[0] |
| 45 |
.getBoundingClientRect(); |
| 46 |
window.addEventListener("scroll", function () { |
| 47 |
if (this.oldScroll > this.scrollY && this.scrollY > header.bottom) { |
| 48 |
btn.style.display = "block"; |
| 49 |
} else { |
| 50 |
btn.style.display = "none"; |
| 51 |
} |
| 52 |
this.oldScroll = this.scrollY; |
| 53 |
}); |
| 54 |
} |
| 55 |
|
| 56 |
/******************************************************************************* |
| 57 |
* Call functions after document loading. |
| 58 |
*/ |
| 59 |
|
| 60 |
documentReady(TriggerTooltip); |
| 61 |
documentReady(backToTop); |
| 62 |
documentReady(showBackToTop); |
| 63 |
|
| 64 |
window.bootstrap = bootstrap; |