-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# PdfExport | ||
|
||
A [reveal.js](https://github.com/hakimel/reveal.js/) plugin to easly switch between screen and the built-in PDF export mode. | ||
|
||
## Installation | ||
|
||
Copy this repository into the plugins folder of your reveal.js presentation, ie ```plugin/pdfexport```. | ||
|
||
Add the plugin to the dependencies in your presentation, as below. | ||
|
||
```javascript | ||
Reveal.initialize({ | ||
// ... | ||
dependencies: [ | ||
// ... | ||
{ src: 'plugin/pdfexport/pdfexport.js', async: true }, | ||
] | ||
}); | ||
``` | ||
|
||
You need to remove all of the following or similar lines from your presentation. Paper or PDF stylesheets will be set by the plugin. | ||
|
||
```html | ||
<!-- Printing and PDF exports --> | ||
<script> | ||
var link = document.createElement( 'link' ); | ||
link.rel = 'stylesheet'; | ||
link.type = 'text/css'; | ||
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css'; | ||
document.getElementsByTagName( 'head' )[0].appendChild( link ); | ||
</script> | ||
``` | ||
|
||
## Usage | ||
|
||
To toggle between screen and PDF mode you can press the ```E``` shortcut on the keyboard. | ||
|
||
### Parameter | ||
|
||
```javascript | ||
Reveal.initialize({ | ||
// ... | ||
|
||
// Shortcut for toggling between screen and PDF mode | ||
pdfExportShortcut: 'E', | ||
}); | ||
``` | ||
|
||
## License | ||
|
||
[MIT licensed](https://en.wikipedia.org/wiki/MIT_License). | ||
|
||
Copyright (C) 2018 [Sören Weber](https://soeren-weber.de) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
var PdfExport = ( function( Reveal ){ | ||
|
||
var defMode = false; | ||
|
||
function getRevealJsPath(){ | ||
var regex = /\/js\/reveal.js$/i; | ||
var script = Array.from( document.querySelectorAll( 'script' ) ).find( function( e ){ | ||
return e.attributes.src && e.attributes.src.value.search( regex ) >= 0; | ||
}); | ||
if( !script ){ | ||
console.error( 'reveal.js script could not be found in included <script> elements. Did you rename this file?' ); | ||
return ''; | ||
} | ||
return script.attributes.src.value.replace( regex, '' ); | ||
} | ||
|
||
function setStylesheet( pdf ){ | ||
var link = document.querySelector( '#print' ); | ||
if( !link ){ | ||
link = document.createElement( 'link' ); | ||
link.rel = 'stylesheet'; | ||
link.id = 'print'; | ||
document.querySelector( 'head' ).appendChild( link ); | ||
} | ||
var style = 'paper'; | ||
if( pdf ){ | ||
style = 'pdf'; | ||
} | ||
link.href = getRevealJsPath() + '/css/print/' + style + '.css'; | ||
} | ||
|
||
function setPdfExport( pdfExport ){ | ||
var config = Reveal.getConfig(); | ||
pdfExport = pdfExport !== null ? pdfExport : config.pdfExport !== undefined ? !!config.pdfExport : defMode; | ||
setStylesheet( pdfExport ); | ||
} | ||
|
||
function isPrintingPDF(){ | ||
return ( /print-pdf/gi ).test( window.location.search ); | ||
} | ||
|
||
function togglePdfExport(){ | ||
var url_doc = new URL( document.URL ); | ||
var query_doc = new URLSearchParams( url_doc.searchParams ); | ||
if( isPrintingPDF() ){ | ||
query_doc.delete( 'print-pdf' ); | ||
}else{ | ||
query_doc.set( 'print-pdf', '' ); | ||
} | ||
url_doc.search = ( query_doc.toString() ? '?' + query_doc.toString() : '' ); | ||
window.location.href = url_doc.toString(); | ||
} | ||
|
||
function applyPdfExportParameter(){ | ||
setPdfExport( isPrintingPDF() ); | ||
} | ||
|
||
function installKeyBindings(){ | ||
var config = Reveal.getConfig(); | ||
var shortcut = config.pdfExportShortcut || 'E'; | ||
var keyboard = {}; | ||
keyboard[ shortcut.toUpperCase().charCodeAt( 0 ) ] = togglePdfExport; | ||
|
||
Reveal.registerKeyboardShortcut( shortcut, 'PDF export mode' ); | ||
Reveal.configure({ | ||
keyboard: keyboard | ||
}); | ||
} | ||
|
||
function install(){ | ||
installKeyBindings(); | ||
applyPdfExportParameter(); | ||
} | ||
|
||
install(); | ||
|
||
return { | ||
}; | ||
|
||
})( Reveal ); |