Skip to content

Commit 9bb9006

Browse files
committed
html, tabby - also trigger event for html document when bootstrap is not used
1 parent 99b8b16 commit 9bb9006

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

src/resources/formats/html/quarto.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,41 @@ window.document.addEventListener("DOMContentLoaded", function (_event) {
6666
}
6767
};
6868

69-
// fire slideEnter for bootstrap tab activations (for htmlwidget resize behavior)
70-
function fireSlideEnter(e) {
69+
// dispatch for htmlwidgets
70+
// they use slideenter event to trigger resize
71+
function fireSlideEnter() {
7172
const event = window.document.createEvent("Event");
7273
event.initEvent("slideenter", true, true);
7374
window.document.dispatchEvent(event);
7475
}
76+
7577
const tabs = window.document.querySelectorAll('a[data-bs-toggle="tab"]');
7678
tabs.forEach((tab) => {
7779
tab.addEventListener("shown.bs.tab", fireSlideEnter);
7880
});
7981

80-
// fire slideEnter for tabby tab activations (for htmlwidget resize behavior)
81-
document.addEventListener("tabby", fireSlideEnter, false);
82+
// dispatch for shiny
83+
// they use BS shown and hidden events to trigger rendering
84+
function distpatchShinyEvents(previous, current) {
85+
if (window.jQuery) {
86+
if (previous) {
87+
window.jQuery(previous).trigger("hidden");
88+
}
89+
if (current) {
90+
window.jQuery(current).trigger("shown");
91+
}
92+
}
93+
}
94+
95+
// tabby.js listener: Trigger event for htmlwidget and shiny
96+
document.addEventListener(
97+
"tabby",
98+
function (event) {
99+
fireSlideEnter();
100+
distpatchShinyEvents(event.detail.previousTab, event.detail.tab);
101+
},
102+
false
103+
);
82104

83105
// Track scrolling and mark TOC links as active
84106
// get table of contents and sidebar (bail if we don't have at least one)

0 commit comments

Comments
 (0)