Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
| Download
Project: KOB1
Views: 16973/**1* Handles opening of and synchronization with the reveal.js2* notes window.3*4* Handshake process:5* 1. This window posts 'connect' to notes window6* - Includes URL of presentation to show7* 2. Notes window responds with 'connected' when it is available8* 3. This window proceeds to send the current presentation state9* to the notes window10*/11var RevealNotes = (function() {1213function openNotes( notesFilePath ) {1415if( !notesFilePath ) {16var jsFileLocation = document.querySelector('script[src$="notes.js"]').src; // this js file path17jsFileLocation = jsFileLocation.replace(/notes\.js(\?.*)?$/, ''); // the js folder path18notesFilePath = jsFileLocation + 'notes.html';19}2021var notesPopup = window.open( notesFilePath, 'reveal.js - Notes', 'width=1100,height=700' );2223// Allow popup window access to Reveal API24notesPopup.Reveal = this.Reveal;2526/**27* Connect to the notes window through a postmessage handshake.28* Using postmessage enables us to work in situations where the29* origins differ, such as a presentation being opened from the30* file system.31*/32function connect() {33// Keep trying to connect until we get a 'connected' message back34var connectInterval = setInterval( function() {35notesPopup.postMessage( JSON.stringify( {36namespace: 'reveal-notes',37type: 'connect',38url: window.location.protocol + '//' + window.location.host + window.location.pathname + window.location.search,39state: Reveal.getState()40} ), '*' );41}, 500 );4243window.addEventListener( 'message', function( event ) {44var data = JSON.parse( event.data );45if( data && data.namespace === 'reveal-notes' && data.type === 'connected' ) {46clearInterval( connectInterval );47onConnected();48}49} );50}5152/**53* Posts the current slide data to the notes window54*/55function post( event ) {5657var slideElement = Reveal.getCurrentSlide(),58notesElement = slideElement.querySelector( 'aside.notes' ),59fragmentElement = slideElement.querySelector( '.current-fragment' );6061var messageData = {62namespace: 'reveal-notes',63type: 'state',64notes: '',65markdown: false,66whitespace: 'normal',67state: Reveal.getState()68};6970// Look for notes defined in a slide attribute71if( slideElement.hasAttribute( 'data-notes' ) ) {72messageData.notes = slideElement.getAttribute( 'data-notes' );73messageData.whitespace = 'pre-wrap';74}7576// Look for notes defined in a fragment77if( fragmentElement ) {78var fragmentNotes = fragmentElement.querySelector( 'aside.notes' );79if( fragmentNotes ) {80notesElement = fragmentNotes;81}82else if( fragmentElement.hasAttribute( 'data-notes' ) ) {83messageData.notes = fragmentElement.getAttribute( 'data-notes' );84messageData.whitespace = 'pre-wrap';8586// In case there are slide notes87notesElement = null;88}89}9091// Look for notes defined in an aside element92if( notesElement ) {93messageData.notes = notesElement.innerHTML;94messageData.markdown = typeof notesElement.getAttribute( 'data-markdown' ) === 'string';95}9697notesPopup.postMessage( JSON.stringify( messageData ), '*' );9899}100101/**102* Called once we have established a connection to the notes103* window.104*/105function onConnected() {106107// Monitor events that trigger a change in state108Reveal.addEventListener( 'slidechanged', post );109Reveal.addEventListener( 'fragmentshown', post );110Reveal.addEventListener( 'fragmenthidden', post );111Reveal.addEventListener( 'overviewhidden', post );112Reveal.addEventListener( 'overviewshown', post );113Reveal.addEventListener( 'paused', post );114Reveal.addEventListener( 'resumed', post );115116// Post the initial state117post();118119}120121connect();122123}124125if( !/receiver/i.test( window.location.search ) ) {126127// If the there's a 'notes' query set, open directly128if( window.location.search.match( /(\?|\&)notes/gi ) !== null ) {129openNotes();130}131132// Open the notes when the 's' key is hit133document.addEventListener( 'keydown', function( event ) {134// Disregard the event if the target is editable or a135// modifier is present136if ( document.querySelector( ':focus' ) !== null || event.shiftKey || event.altKey || event.ctrlKey || event.metaKey ) return;137138// Disregard the event if keyboard is disabled139if ( Reveal.getConfig().keyboard === false ) return;140141if( event.keyCode === 83 ) {142event.preventDefault();143openNotes();144}145}, false );146147// Show our keyboard shortcut in the reveal.js help overlay148if( window.Reveal ) Reveal.registerKeyboardShortcut( 'S', 'Speaker notes view' );149150}151152return { open: openNotes };153154})();155156157