Skip to content

Commit

Permalink
reader mode can be turned off without reload, add Reveal.toggleReader()
Browse files Browse the repository at this point in the history
  • Loading branch information
hakimel committed Sep 19, 2023
1 parent 4da6f6b commit 5de7da7
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 27 deletions.
7 changes: 5 additions & 2 deletions css/reveal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,10 @@ $notesWidthPercent: 25%;
/*********************************************
* READER MODE
*********************************************/
.reveal-viewport.loading-scroll-mode {
visibility: hidden;
}

.reveal-viewport.reveal-reader {
& {
margin: 0 auto !important;
Expand Down Expand Up @@ -1910,14 +1914,13 @@ $notesWidthPercent: 25%;
position: relative;
overflow: hidden;
z-index: 1;

page-break-after: always;
}

.reveal .slides .reader-page section {
visibility: visible !important;
display: block !important;
position: relative !important;
top: auto !important;

margin: 0 !important;
padding: 0 !important;
Expand Down
2 changes: 1 addition & 1 deletion dist/reveal.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.esm.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.js.map

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions js/controllers/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,16 +360,20 @@ export default class Keyboard {
}
// A
else if( keyCode === 65 ) {
if ( config.autoSlideStoppable ) {
if( config.autoSlideStoppable ) {
this.Reveal.toggleAutoSlide( autoSlideWasPaused );
}
}
// G
else if( keyCode === 71 ) {
if ( config.jumpToSlide ) {
if( config.jumpToSlide ) {
this.Reveal.toggleJumpToSlide();
}
}
// R
else if( keyCode === 82 ) {
this.Reveal.toggleReader();
}
else {
triggered = false;
}
Expand Down
55 changes: 40 additions & 15 deletions js/controllers/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,28 @@ export default class Reader {

this.Reveal = Reveal;

this.activated = false;
this.active = false;
this.activatedCallbacks = [];

}

async activate() {

const slides = queryAll( this.Reveal.getRevealElement(), SLIDES_SELECTOR );
if( this.active ) return;

const viewportElement = this.Reveal.getViewportElement();
this.active = true;

const slideSize = this.Reveal.getComputedSlideSize( window.innerWidth, window.innerHeight );
this.slideHTMLBeforeActivation = this.Reveal.getSlidesElement().innerHTML;

const viewportElement = this.Reveal.getViewportElement();
const slides = queryAll( this.Reveal.getRevealElement(), SLIDES_SELECTOR );

// Dimensions of slides within the pages
const slideSize = this.Reveal.getComputedSlideSize( window.innerWidth, window.innerHeight );
const slideWidth = slideSize.width,
slideHeight = slideSize.height;

await new Promise( requestAnimationFrame );

viewportElement.classList.add( 'reveal-reader' );
viewportElement.classList.add( 'loading-scroll-mode', 'reveal-reader' );
viewportElement.addEventListener( 'scroll', this.onScroll.bind( this ) );

let presentationBackground;
Expand Down Expand Up @@ -93,22 +95,45 @@ export default class Reader {

this.Reveal.layout();

this.activated = true;
viewportElement.classList.remove( 'loading-scroll-mode' );

this.activatedCallbacks.forEach( callback => callback() );
this.activatedCallbacks = [];

}

deactivate() {

if( !this.active ) return;

this.active = false;

this.Reveal.getViewportElement().classList.remove( 'reveal-reader' );
this.Reveal.getSlidesElement().innerHTML = this.slideHTMLBeforeActivation;
this.Reveal.sync();

// TODO Navigate to the slide that is currently scrolled into view
this.Reveal.slide( 0 );

}

toggle() {

if( this.active === true ) {
this.deactivate();
}
else {
this.activate();
}

}

/**
* Checks if the reader mode is/should be activated.
* Checks if the reader mode is currently active.
*/
isActive() {

if( typeof this._isReaderMode === 'undefined' ) {
this._isReaderMode = this.Reveal.getConfig().mode === 'reader';
}

return this._isReaderMode;
return this.active;

}

Expand Down Expand Up @@ -187,7 +212,7 @@ export default class Reader {

scrollToSlide( slideElement ) {

if( !this.activated ) {
if( !this.active ) {
this.activatedCallbacks.push( () => this.scrollToSlide( slideElement ) );
}
else {
Expand Down
8 changes: 5 additions & 3 deletions js/reveal.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export default function( revealElement, options ) {
}, 1 );

const isPrintMode = print.isActive();
const isReaderMode = reader.isActive();
const isReaderMode = config.mode === 'reader';

// Special setup and config is required when initializing a deck
// to be read or printed linearly
Expand All @@ -238,12 +238,11 @@ export default function( revealElement, options ) {
removeEventListeners();
}
else {
keyboard.unbind();
touch.unbind();
}

// Avoid content flickering during layout
revealElement.style.visibility = 'hidden';
dom.viewport.classList.add( 'loading-scroll-mode' );

const activate = () => {
if( isPrintMode ) {
Expand Down Expand Up @@ -2722,6 +2721,9 @@ export default function( revealElement, options ) {
// Toggles the overview mode on/off
toggleOverview: overview.toggle.bind( overview ),

// Toggles the reader mode on/off
toggleReader: reader.toggle.bind( reader ),

// Toggles the "black screen" mode on/off
togglePause,

Expand Down

0 comments on commit 5de7da7

Please sign in to comment.