2012-10-21 02:40:52 +02:00
|
|
|
/**
|
|
|
|
* Handles opening of and synchronization with the reveal.js
|
|
|
|
* notes window.
|
|
|
|
*/
|
|
|
|
var RevealNotes = (function() {
|
|
|
|
|
|
|
|
function openNotes() {
|
2013-02-07 01:15:30 +01:00
|
|
|
var jsFileLocation = document.querySelector('script[src$="notes.js"]').src; // this js file path
|
2013-02-06 12:24:04 +01:00
|
|
|
jsFileLocation = jsFileLocation.replace(/notes\.js(\?.*)?$/, ''); // the js folder path
|
|
|
|
var notesPopup = window.open( jsFileLocation + 'notes.html', 'reveal.js - Notes', 'width=1120,height=850' );
|
2012-10-21 02:40:52 +02:00
|
|
|
|
2012-10-24 14:33:16 +02:00
|
|
|
// Fires when slide is changed
|
2013-07-26 15:48:21 +02:00
|
|
|
Reveal.addEventListener( 'slidechanged', post );
|
2012-10-21 02:40:52 +02:00
|
|
|
|
2012-10-24 14:33:16 +02:00
|
|
|
// Fires when a fragment is shown
|
2013-07-26 15:48:21 +02:00
|
|
|
Reveal.addEventListener( 'fragmentshown', post );
|
2012-10-21 02:40:52 +02:00
|
|
|
|
2012-10-24 14:33:16 +02:00
|
|
|
// Fires when a fragment is hidden
|
2013-07-26 15:48:21 +02:00
|
|
|
Reveal.addEventListener( 'fragmenthidden', post );
|
2012-10-21 02:40:52 +02:00
|
|
|
|
2012-10-24 14:33:16 +02:00
|
|
|
/**
|
2012-10-25 15:36:25 +02:00
|
|
|
* Posts the current slide data to the notes window
|
2012-10-24 14:33:16 +02:00
|
|
|
*/
|
2013-07-26 15:48:21 +02:00
|
|
|
function post() {
|
2012-10-21 02:40:52 +02:00
|
|
|
var slideElement = Reveal.getCurrentSlide(),
|
2013-07-26 15:48:21 +02:00
|
|
|
slideIndices = Reveal.getIndices(),
|
2012-10-25 15:36:25 +02:00
|
|
|
messageData;
|
2012-10-21 02:40:52 +02:00
|
|
|
|
2013-07-26 15:48:21 +02:00
|
|
|
var notes = slideElement.querySelector( 'aside.notes' ),
|
|
|
|
nextindexh,
|
|
|
|
nextindexv;
|
2012-10-21 02:40:52 +02:00
|
|
|
|
2013-07-26 15:48:21 +02:00
|
|
|
if( slideElement.nextElementSibling && slideElement.parentNode.nodeName == 'SECTION' ) {
|
|
|
|
nextindexh = slideIndices.h;
|
|
|
|
nextindexv = slideIndices.v + 1;
|
|
|
|
} else {
|
|
|
|
nextindexh = slideIndices.h + 1;
|
|
|
|
nextindexv = 0;
|
2012-10-24 14:33:16 +02:00
|
|
|
}
|
2012-10-21 02:40:52 +02:00
|
|
|
|
2013-07-26 15:48:21 +02:00
|
|
|
messageData = {
|
|
|
|
notes : notes ? notes.innerHTML : '',
|
|
|
|
indexh : slideIndices.h,
|
|
|
|
indexv : slideIndices.v,
|
|
|
|
indexf : slideIndices.f,
|
|
|
|
nextindexh : nextindexh,
|
|
|
|
nextindexv : nextindexv,
|
|
|
|
markdown : notes ? typeof notes.getAttribute( 'data-markdown' ) === 'string' : false
|
|
|
|
};
|
|
|
|
|
2012-10-25 15:36:25 +02:00
|
|
|
notesPopup.postMessage( JSON.stringify( messageData ), '*' );
|
2012-10-21 02:40:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Navigate to the current slide when the notes are loaded
|
2012-10-24 14:33:16 +02:00
|
|
|
notesPopup.addEventListener( 'load', function( event ) {
|
2013-07-26 15:48:21 +02:00
|
|
|
post();
|
2012-10-24 14:33:16 +02:00
|
|
|
}, false );
|
2012-10-21 02:40:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the there's a 'notes' query set, open directly
|
2012-10-25 15:36:25 +02:00
|
|
|
if( window.location.search.match( /(\?|\&)notes/gi ) !== null ) {
|
2012-10-21 02:40:52 +02:00
|
|
|
openNotes();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open the notes when the 's' key is hit
|
|
|
|
document.addEventListener( 'keydown', function( event ) {
|
2012-10-21 03:05:14 +02:00
|
|
|
// Disregard the event if the target is editable or a
|
2012-10-21 02:40:52 +02:00
|
|
|
// modifier is present
|
|
|
|
if ( document.querySelector( ':focus' ) !== null || event.shiftKey || event.altKey || event.ctrlKey || event.metaKey ) return;
|
|
|
|
|
|
|
|
if( event.keyCode === 83 ) {
|
|
|
|
event.preventDefault();
|
|
|
|
openNotes();
|
|
|
|
}
|
|
|
|
}, false );
|
|
|
|
|
2012-10-24 14:33:16 +02:00
|
|
|
return { open: openNotes };
|
|
|
|
})();
|