diff --git a/src/resources/formats/revealjs/plugins/menu/quarto-menu.js b/src/resources/formats/revealjs/plugins/menu/quarto-menu.js index f23962e3b9e..e5c53c4dc77 100644 --- a/src/resources/formats/revealjs/plugins/menu/quarto-menu.js +++ b/src/resources/formats/revealjs/plugins/menu/quarto-menu.js @@ -41,6 +41,6 @@ window.RevealMenuToolHandlers = { PdfExport.togglePdfExport(); }), toggleScrollView: revealMenuToolHandler(function() { - Reveal.getPlugin("quarto-support").toggleScrollView(Reveal)(); + Reveal.getPlugin("quarto-support").toggleScrollView(); }) }; diff --git a/src/resources/formats/revealjs/plugins/support/support.js b/src/resources/formats/revealjs/plugins/support/support.js index 727cc4f632d..73246a7899f 100644 --- a/src/resources/formats/revealjs/plugins/support/support.js +++ b/src/resources/formats/revealjs/plugins/support/support.js @@ -345,23 +345,28 @@ window.QuartoSupport = function () { } } - // FIXME: Possibly remove this wrapper when upstream trigger is fixed + // FIXME: Possibly remove this wrapper class when upstream trigger is fixed // https://github.com/hakimel/reveal.js/issues/3688 // Currently, scrollActivationWidth needs to be unset for toggle to work - function toggleScrollViewWrapper(deck) { - let oldscrollActivationWidth; - return () => { - if (deck.isScrollView() === true) { - deck.configure({scrollActivationWidth: oldscrollActivationWidth}); - deck.toggleScrollView(false); - } else if (deck.isScrollView() === false) { - oldscrollActivationWidth = deck.getConfig()['scrollActivationWidth']; - deck.configure({scrollActivationWidth: null}); - deck.toggleScrollView(true); + class ScrollViewToggler { + constructor(deck) { + this.deck = deck; + this.oldScrollActivationWidth = deck.getConfig()['scrollActivationWidth']; + } + + toggleScrollViewWrapper() { + if (this.deck.isScrollView() === true) { + this.deck.configure({ scrollActivationWidth: this.oldScrollActivationWidth }); + this.deck.toggleScrollView(false); + } else if (this.deck.isScrollView() === false) { + this.deck.configure({ scrollActivationWidth: null }); + this.deck.toggleScrollView(true); } } } + let scrollViewToggler; + function installScollViewKeyBindings(deck) { var config = deck.getConfig(); var shortcut = config.scrollViewShortcut || 'R'; @@ -369,12 +374,13 @@ window.QuartoSupport = function () { keyCode: shortcut.toUpperCase().charCodeAt( 0 ), key: shortcut.toUpperCase(), description: 'Scroll View Mode' - }, toggleScrollViewWrapper(deck) ); + }, () => { scrollViewToggler.toggleScrollViewWrapper() } ); } return { id: "quarto-support", init: function (deck) { + scrollViewToggler = new ScrollViewToggler(deck); controlsAuto(deck); previewLinksAuto(deck); fixupForPrint(deck); @@ -392,6 +398,8 @@ window.QuartoSupport = function () { cleanEmptyAutoGeneratedContent(deck); }, // Export for adding in menu - toggleScrollView: toggleScrollViewWrapper, + toggleScrollView: function() { + scrollViewToggler.toggleScrollViewWrapper(); + } }; };