Skip to content

Commit fa39ff1

Browse files
authored
Merge pull request #11103 from quarto-dev/revealjs/improve-scrollmode-toggling
2 parents a172c18 + d9d50dc commit fa39ff1

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

src/resources/formats/revealjs/plugins/menu/quarto-menu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ window.RevealMenuToolHandlers = {
4141
PdfExport.togglePdfExport();
4242
}),
4343
toggleScrollView: revealMenuToolHandler(function() {
44-
Reveal.getPlugin("quarto-support").toggleScrollView(Reveal)();
44+
Reveal.getPlugin("quarto-support").toggleScrollView();
4545
})
4646
};

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -345,36 +345,42 @@ window.QuartoSupport = function () {
345345
}
346346
}
347347

348-
// FIXME: Possibly remove this wrapper when upstream trigger is fixed
348+
// FIXME: Possibly remove this wrapper class when upstream trigger is fixed
349349
// https://github.com/hakimel/reveal.js/issues/3688
350350
// Currently, scrollActivationWidth needs to be unset for toggle to work
351-
function toggleScrollViewWrapper(deck) {
352-
let oldscrollActivationWidth;
353-
return () => {
354-
if (deck.isScrollView() === true) {
355-
deck.configure({scrollActivationWidth: oldscrollActivationWidth});
356-
deck.toggleScrollView(false);
357-
} else if (deck.isScrollView() === false) {
358-
oldscrollActivationWidth = deck.getConfig()['scrollActivationWidth'];
359-
deck.configure({scrollActivationWidth: null});
360-
deck.toggleScrollView(true);
351+
class ScrollViewToggler {
352+
constructor(deck) {
353+
this.deck = deck;
354+
this.oldScrollActivationWidth = deck.getConfig()['scrollActivationWidth'];
355+
}
356+
357+
toggleScrollViewWrapper() {
358+
if (this.deck.isScrollView() === true) {
359+
this.deck.configure({ scrollActivationWidth: this.oldScrollActivationWidth });
360+
this.deck.toggleScrollView(false);
361+
} else if (this.deck.isScrollView() === false) {
362+
this.deck.configure({ scrollActivationWidth: null });
363+
this.deck.toggleScrollView(true);
361364
}
362365
}
363366
}
364367

368+
let scrollViewToggler;
369+
365370
function installScollViewKeyBindings(deck) {
366371
var config = deck.getConfig();
367372
var shortcut = config.scrollViewShortcut || 'R';
368373
Reveal.addKeyBinding({
369374
keyCode: shortcut.toUpperCase().charCodeAt( 0 ),
370375
key: shortcut.toUpperCase(),
371376
description: 'Scroll View Mode'
372-
}, toggleScrollViewWrapper(deck) );
377+
}, () => { scrollViewToggler.toggleScrollViewWrapper() } );
373378
}
374379

375380
return {
376381
id: "quarto-support",
377382
init: function (deck) {
383+
scrollViewToggler = new ScrollViewToggler(deck);
378384
controlsAuto(deck);
379385
previewLinksAuto(deck);
380386
fixupForPrint(deck);
@@ -392,6 +398,8 @@ window.QuartoSupport = function () {
392398
cleanEmptyAutoGeneratedContent(deck);
393399
},
394400
// Export for adding in menu
395-
toggleScrollView: toggleScrollViewWrapper,
401+
toggleScrollView: function() {
402+
scrollViewToggler.toggleScrollViewWrapper();
403+
}
396404
};
397405
};

0 commit comments

Comments
 (0)