From a2cf23b30cbd962d752df5b9a8fc46f074fab20d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20K=C3=B6hl?= Date: Tue, 8 Aug 2017 22:47:10 +0200 Subject: [PATCH 1/2] PDF export: add option to export one page per fragment --- js/reveal.js | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/js/reveal.js b/js/reveal.js index d3ba03c..4508add 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -727,14 +727,39 @@ numberElement.innerHTML = formatSlideNumber( slideNumberH, '.', slideNumberV ); page.appendChild( numberElement ); } + + // Copy page and show fragments one after another + if ( isPrintingPDFFragments() ) { + + var numberOfFragments = toArray( page.querySelectorAll( '.fragment' ) ).length; + + for ( var currentFragment = 0; currentFragment < numberOfFragments; currentFragment++ ) { + var clonedPage = page.cloneNode( true ); + page.parentNode.insertBefore( clonedPage, page.nextSibling ); + + toArray( sortFragments( clonedPage.querySelectorAll( '.fragment' ))).forEach( function ( fragment, fragmentIndex ) { + if ( fragmentIndex <= currentFragment ) { + fragment.classList.add( 'visible' ); + } else { + fragment.classList.remove( 'visible' ); + } + } ); + + page = clonedPage; + } + + } + // Show all fragments + else { + toArray( page.querySelectorAll( '.fragment' ) ).forEach( function( fragment ) { + fragment.classList.add( 'visible' ); + } ); + } + } } ); - // Show all fragments - toArray( dom.wrapper.querySelectorAll( SLIDES_SELECTOR + ' .fragment' ) ).forEach( function( fragment ) { - fragment.classList.add( 'visible' ); - } ); // Notify subscribers that the PDF layout is good to go dispatchEvent( 'pdf-ready' ); @@ -1497,6 +1522,15 @@ } + /** + * Check if this instance is being used to print a PDF with fragments. + */ + function isPrintingPDFFragments() { + + return ( /print-pdf-fragments/gi ).test( window.location.search ); + + } + /** * Hides the address bar if we're on a mobile device. */ From 08e0f5e47b73d01f5afa82e79b9046a2a694855d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20K=C3=B6hl?= Date: Tue, 8 Aug 2017 22:53:32 +0200 Subject: [PATCH 2/2] fix indent: replace spaces with tabs --- js/reveal.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/js/reveal.js b/js/reveal.js index 4508add..0f5cacd 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -734,19 +734,19 @@ var numberOfFragments = toArray( page.querySelectorAll( '.fragment' ) ).length; for ( var currentFragment = 0; currentFragment < numberOfFragments; currentFragment++ ) { - var clonedPage = page.cloneNode( true ); - page.parentNode.insertBefore( clonedPage, page.nextSibling ); + var clonedPage = page.cloneNode( true ); + page.parentNode.insertBefore( clonedPage, page.nextSibling ); - toArray( sortFragments( clonedPage.querySelectorAll( '.fragment' ))).forEach( function ( fragment, fragmentIndex ) { - if ( fragmentIndex <= currentFragment ) { - fragment.classList.add( 'visible' ); - } else { - fragment.classList.remove( 'visible' ); - } - } ); + toArray( sortFragments( clonedPage.querySelectorAll( '.fragment' ))).forEach( function ( fragment, fragmentIndex ) { + if ( fragmentIndex <= currentFragment ) { + fragment.classList.add( 'visible' ); + } else { + fragment.classList.remove( 'visible' ); + } + } ); - page = clonedPage; - } + page = clonedPage; + } } // Show all fragments @@ -1522,12 +1522,12 @@ } - /** + /** * Check if this instance is being used to print a PDF with fragments. - */ - function isPrintingPDFFragments() { + */ + function isPrintingPDFFragments() { - return ( /print-pdf-fragments/gi ).test( window.location.search ); + return ( /print-pdf-fragments/gi ).test( window.location.search ); }