Skip to content

Commit 99b8b16

Browse files
committed
revealjs, tabby - Trigger event for shiny rendering when tab change
1 parent 64e9791 commit 99b8b16

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

news/changelog-1.7.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ All changes included in 1.7:
5353
- ([#11903](https://github.com/quarto-dev/quarto-cli/issues/11903)): `crossref` configuration like `fig-title` or `tbl-title` now correctly supports multi word values, e.g. `fig-title: 'Supplementary Figure'`.
5454
- ([#11878](https://github.com/quarto-dev/quarto-cli/issues/11878), [#12085](https://github.com/quarto-dev/quarto-cli/issues/12085)): Correctly fixup raw LaTeX table having an unexpected table env with options (e.g `\begin{table}[!ht]`) to be handled as crossref table.
5555

56+
## `revealjs` format
57+
58+
- ([#12307](https://github.com/quarto-dev/quarto-cli/issues/12307)): Tabset in Revealjs now correctly render reactive content when `server: shiny` is used.
59+
5660
### Quarto PDF engine
5761

5862
- ([#12194](https://github.com/quarto-dev/quarto-cli/issues/12194)): More specific checks added in log parsing to automatically find missing fonts.

src/resources/formats/revealjs/plugins/support/support.js

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -281,36 +281,49 @@ window.QuartoSupport = function () {
281281
}
282282
}
283283

284+
// dispatch for htmlwidgets
285+
// they use slideenter event to trigger resize
286+
const fireSlideEnter = () => {
287+
const event = window.document.createEvent("Event");
288+
event.initEvent("slideenter", true, true);
289+
window.document.dispatchEvent(event);
290+
};
291+
292+
// dispatch for shiny
293+
// they use BS shown and hidden events to trigger rendering
294+
const distpatchShinyEvents = (previous, current) => {
295+
if (window.jQuery) {
296+
if (previous) {
297+
window.jQuery(previous).trigger("hidden");
298+
}
299+
if (current) {
300+
window.jQuery(current).trigger("shown");
301+
}
302+
}
303+
};
304+
284305
function handleSlideChanges(deck) {
285-
// dispatch for htmlwidgets
286-
const fireSlideEnter = () => {
287-
const event = window.document.createEvent("Event");
288-
event.initEvent("slideenter", true, true);
289-
window.document.dispatchEvent(event);
290-
};
291306

292307
const fireSlideChanged = (previousSlide, currentSlide) => {
293308
fireSlideEnter();
294-
295-
// dispatch for shiny
296-
if (window.jQuery) {
297-
if (previousSlide) {
298-
window.jQuery(previousSlide).trigger("hidden");
299-
}
300-
if (currentSlide) {
301-
window.jQuery(currentSlide).trigger("shown");
302-
}
303-
}
309+
distpatchShinyEvents(previousSlide, currentSlide);
304310
};
305311

306-
// fire slideEnter for tabby tab activations (for htmlwidget resize behavior)
307-
document.addEventListener("tabby", fireSlideEnter, false);
308-
309312
deck.on("slidechanged", function (event) {
310313
fireSlideChanged(event.previousSlide, event.currentSlide);
311314
});
312315
}
313316

317+
function handleTabbyChanges() {
318+
const fireTabChanged = (previousTab, currentTab) => {
319+
fireSlideEnter()
320+
distpatchShinyEvents(previousTab, currentTab);
321+
};
322+
document.addEventListener("tabby", function(event) {
323+
fireTabChanged(event.detail.previousTab, event.detail.tab);
324+
}, false);
325+
}
326+
314327
function workaroundMermaidDistance(deck) {
315328
if (window.document.querySelector("pre.mermaid-js")) {
316329
const slideCount = deck.getTotalSlides();
@@ -390,6 +403,7 @@ window.QuartoSupport = function () {
390403
addFooter(deck);
391404
addChalkboardButtons(deck);
392405
handleTabbyClicks();
406+
handleTabbyChanges();
393407
handleSlideChanges(deck);
394408
workaroundMermaidDistance(deck);
395409
handleWhiteSpaceInColumns(deck);

0 commit comments

Comments
 (0)