From a22d00ab25b13b82d19890428f124b4ed3759f92 Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Mon, 17 Feb 2014 20:07:41 +0100 Subject: server side notes plugin now supports input via data-notes attribute --- plugin/notes/notes.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'plugin/notes/notes.js') diff --git a/plugin/notes/notes.js b/plugin/notes/notes.js index 9a82c3c..3f68b5d 100644 --- a/plugin/notes/notes.js +++ b/plugin/notes/notes.js @@ -24,9 +24,7 @@ var RevealNotes = (function() { function post() { var slideElement = Reveal.getCurrentSlide(), slideIndices = Reveal.getIndices(), - messageData; - - var notes = slideElement.querySelector( 'aside.notes' ), + notesElement = slideElement.querySelector( 'aside.notes' ), nextindexh, nextindexv; @@ -38,16 +36,27 @@ var RevealNotes = (function() { nextindexv = 0; } - messageData = { - notes : notes ? notes.innerHTML : '', + var messageData = { + notes : '', indexh : slideIndices.h, indexv : slideIndices.v, indexf : slideIndices.f, nextindexh : nextindexh, nextindexv : nextindexv, - markdown : notes ? typeof notes.getAttribute( 'data-markdown' ) === 'string' : false + markdown : false }; + // Look for notes defined in a slide attribute + if( slideElement.hasAttribute( 'data-notes' ) ) { + messageData.notes = slideElement.getAttribute( 'data-notes' ); + } + + // Look for notes defined in an aside element + if( notesElement ) { + messageData.notes = notesElement.innerHTML; + messageData.markdown = typeof notesElement.getAttribute( 'data-markdown' ) === 'string'; + } + notesPopup.postMessage( JSON.stringify( messageData ), '*' ); } -- cgit v1.2.3 From 5b18c1f308523527566cefc85414170e922bc4a2 Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Sat, 19 Apr 2014 10:54:14 +0200 Subject: notes plugin now operates entirely through window.postMessage, adding support for file protocol --- plugin/notes/notes.html | 176 ++++++++++++++++++++++++++++++------------------ plugin/notes/notes.js | 88 ++++++++++++++++-------- 2 files changed, 168 insertions(+), 96 deletions(-) (limited to 'plugin/notes/notes.js') diff --git a/plugin/notes/notes.html b/plugin/notes/notes.html index 847499d..3e9e8b7 100644 --- a/plugin/notes/notes.html +++ b/plugin/notes/notes.html @@ -82,6 +82,7 @@ left: 3px; font-weight: bold; font-size: 14px; + z-index: 2; color: rgba( 255, 255, 255, 0.9 ); } @@ -138,22 +139,8 @@ - - -
- -
- -
- - UPCOMING: -
+
+
UPCOMING:
@@ -171,37 +158,112 @@ diff --git a/plugin/notes/notes.js b/plugin/notes/notes.js index 3f68b5d..31efd81 100644 --- a/plugin/notes/notes.js +++ b/plugin/notes/notes.js @@ -1,6 +1,13 @@ /** * Handles opening of and synchronization with the reveal.js * notes window. + * + * Handshake process: + * 1. This window posts 'connect' to notes window + * - Includes URL of presentation to show + * 2. Notes window responds with 'connected' when it is available + * 3. This window proceeds to send the current presentation state + * to the notes window */ var RevealNotes = (function() { @@ -9,41 +16,46 @@ var RevealNotes = (function() { jsFileLocation = jsFileLocation.replace(/notes\.js(\?.*)?$/, ''); // the js folder path var notesPopup = window.open( jsFileLocation + 'notes.html', 'reveal.js - Notes', 'width=1120,height=850' ); - // Fires when slide is changed - Reveal.addEventListener( 'slidechanged', post ); - - // Fires when a fragment is shown - Reveal.addEventListener( 'fragmentshown', post ); + /** + * Connect to the notes window through a postmessage handshake. + * Using postmessage enables us to work in situations where the + * origins differ, such as a presentation being opened from the + * file system. + */ + function connect() { + // Keep trying to connect until we get a 'connected' message back + var connectInterval = setInterval( function() { + notesPopup.postMessage( JSON.stringify( { + namespace: 'reveal-notes', + type: 'connect', + url: window.location.protocol + '//' + window.location.host + window.location.pathname, + state: Reveal.getState() + } ), '*' ); + }, 500 ); - // Fires when a fragment is hidden - Reveal.addEventListener( 'fragmenthidden', post ); + window.addEventListener( 'message', function( event ) { + var data = JSON.parse( event.data ); + if( data && data.namespace === 'reveal-notes' && data.type === 'connected' ) { + clearInterval( connectInterval ); + onConnected(); + } + } ); + } /** * Posts the current slide data to the notes window */ function post() { + var slideElement = Reveal.getCurrentSlide(), - slideIndices = Reveal.getIndices(), - notesElement = slideElement.querySelector( 'aside.notes' ), - nextindexh, - nextindexv; - - if( slideElement.nextElementSibling && slideElement.parentNode.nodeName == 'SECTION' ) { - nextindexh = slideIndices.h; - nextindexv = slideIndices.v + 1; - } else { - nextindexh = slideIndices.h + 1; - nextindexv = 0; - } + notesElement = slideElement.querySelector( 'aside.notes' ); var messageData = { - notes : '', - indexh : slideIndices.h, - indexv : slideIndices.v, - indexf : slideIndices.f, - nextindexh : nextindexh, - nextindexv : nextindexv, - markdown : false + namespace: 'reveal-notes', + type: 'state', + notes: '', + markdown: false, + state: Reveal.getState() }; // Look for notes defined in a slide attribute @@ -58,12 +70,30 @@ var RevealNotes = (function() { } notesPopup.postMessage( JSON.stringify( messageData ), '*' ); + } - // Navigate to the current slide when the notes are loaded - notesPopup.addEventListener( 'load', function( event ) { + /** + * Called once we have established a connection to the notes + * window. + */ + function onConnected() { + + // Monitor events that trigger a change in state + Reveal.addEventListener( 'slidechanged', post ); + Reveal.addEventListener( 'fragmentshown', post ); + Reveal.addEventListener( 'fragmenthidden', post ); + Reveal.addEventListener( 'overviewhidden', post ); + Reveal.addEventListener( 'overviewshown', post ); + Reveal.addEventListener( 'paused', post ); + Reveal.addEventListener( 'resumed', post ); + + // Post the initial state post(); - }, false ); + + } + + connect(); } // If the there's a 'notes' query set, open directly -- cgit v1.2.3 From ce05138f9a9065526ee584d2f59e48952910522f Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Tue, 22 Apr 2014 14:06:58 +0200 Subject: dont toggle paused/overview modes needlessly when setting state --- js/reveal.js | 15 +++++++++++---- plugin/notes/notes.html | 10 ++++++++-- plugin/notes/notes.js | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) (limited to 'plugin/notes/notes.js') diff --git a/js/reveal.js b/js/reveal.js index cba8121..e133887 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -968,8 +968,6 @@ var Reveal = (function(){ */ function dispatchEvent( type, args ) { - console.log('event', type); - var event = document.createEvent( 'HTMLEvents', 1, 2 ); event.initEvent( type, true, true ); extend( event, args ); @@ -2498,8 +2496,17 @@ var Reveal = (function(){ if( typeof state === 'object' ) { slide( deserialize( state.indexh ), deserialize( state.indexv ), deserialize( state.indexf ) ); - togglePause( deserialize( state.paused ) ); - toggleOverview( deserialize( state.overview ) ); + + var pausedFlag = deserialize( state.paused ), + overviewFlag = deserialize( state.overview ); + + if( typeof pausedFlag === 'boolean' && pausedFlag !== isPaused() ) { + togglePause( pausedFlag ); + } + + if( typeof overviewFlag === 'boolean' && overviewFlag !== isOverview() ) { + toggleOverview( overviewFlag ); + } } } diff --git a/plugin/notes/notes.html b/plugin/notes/notes.html index 15c7ae9..95cc525 100644 --- a/plugin/notes/notes.html +++ b/plugin/notes/notes.html @@ -249,7 +249,13 @@ */ function setupIframes( data ) { - var url = data.url + '?receiver&progress=false&overview=false&history=false'; + var params = [ + 'receiver', + 'progress=false', + 'history=false' + ]; + + var url = data.url + '?' + params.join( '&' ); var hash = '#/' + data.state.indexh + '/' + data.state.indexv; currentSlide = document.createElement( 'iframe' ); @@ -261,7 +267,7 @@ nextSlide = document.createElement( 'iframe' ); nextSlide.setAttribute( 'width', 640 ); nextSlide.setAttribute( 'height', 512 ); - nextSlide.setAttribute( 'src', url + '&controls=false' + hash ); + nextSlide.setAttribute( 'src', url + '&controls=false&transition=none&backgroundTransition=none' + hash ); document.querySelector( '#next-slide' ).appendChild( nextSlide ); } diff --git a/plugin/notes/notes.js b/plugin/notes/notes.js index 31efd81..a0b6a5a 100644 --- a/plugin/notes/notes.js +++ b/plugin/notes/notes.js @@ -14,7 +14,7 @@ var RevealNotes = (function() { function openNotes() { var jsFileLocation = document.querySelector('script[src$="notes.js"]').src; // this js file path jsFileLocation = jsFileLocation.replace(/notes\.js(\?.*)?$/, ''); // the js folder path - var notesPopup = window.open( jsFileLocation + 'notes.html', 'reveal.js - Notes', 'width=1120,height=850' ); + var notesPopup = window.open( jsFileLocation + 'notes.html', 'reveal.js - Notes', 'width=1100,height=700' ); /** * Connect to the notes window through a postmessage handshake. -- cgit v1.2.3