2012-10-21 00:40:52 +00:00
|
|
|
/**
|
|
|
|
* Handles opening of and synchronization with the reveal.js
|
|
|
|
* notes window.
|
|
|
|
*/
|
|
|
|
var RevealNotes = (function() {
|
|
|
|
|
|
|
|
function openNotes() {
|
2013-02-07 00:15:30 +00:00
|
|
|
var jsFileLocation = document.querySelector('script[src$="notes.js"]').src; // this js file path
|
2013-02-06 11:24:04 +00: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 00:40:52 +00:00
|
|
|
|
2012-10-24 12:33:16 +00:00
|
|
|
// Fires when slide is changed
|
2013-07-26 13:48:21 +00:00
|
|
|
Reveal.addEventListener( 'slidechanged', post );
|
2012-10-21 00:40:52 +00:00
|
|
|
|
2012-10-24 12:33:16 +00:00
|
|
|
// Fires when a fragment is shown
|
2013-07-26 13:48:21 +00:00
|
|
|
Reveal.addEventListener( 'fragmentshown', post );
|
2012-10-21 00:40:52 +00:00
|
|
|
|
2012-10-24 12:33:16 +00:00
|
|
|
// Fires when a fragment is hidden
|
2013-07-26 13:48:21 +00:00
|
|
|
Reveal.addEventListener( 'fragmenthidden', post );
|
2012-10-21 00:40:52 +00:00
|
|
|
|
2012-10-24 12:33:16 +00:00
|
|
|
/**
|
2012-10-25 13:36:25 +00:00
|
|
|
* Posts the current slide data to the notes window
|
2012-10-24 12:33:16 +00:00
|
|
|
*/
|
2013-07-26 13:48:21 +00:00
|
|
|
function post() {
|
2012-10-21 00:40:52 +00:00
|
|
|
var slideElement = Reveal.getCurrentSlide(),
|
2013-07-26 13:48:21 +00:00
|
|
|
slideIndices = Reveal.getIndices(),
|
2014-02-17 19:07:41 +00:00
|
|
|
notesElement = slideElement.querySelector( 'aside.notes' ),
|
2013-07-26 13:48:21 +00:00
|
|
|
nextindexh,
|
|
|
|
nextindexv;
|
2012-10-21 00:40:52 +00:00
|
|
|
|
2013-07-26 13:48:21 +00: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 12:33:16 +00:00
|
|
|
}
|
2012-10-21 00:40:52 +00:00
|
|
|
|
2014-02-17 19:07:41 +00:00
|
|
|
var messageData = {
|
|
|
|
notes : '',
|
2013-07-26 13:48:21 +00:00
|
|
|
indexh : slideIndices.h,
|
|
|
|
indexv : slideIndices.v,
|
|
|
|
indexf : slideIndices.f,
|
|
|
|
nextindexh : nextindexh,
|
|
|
|
nextindexv : nextindexv,
|
2014-02-17 19:07:41 +00:00
|
|
|
markdown : false
|
2013-07-26 13:48:21 +00:00
|
|
|
};
|
|
|
|
|
2014-02-17 19:07:41 +00:00
|
|
|
// 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';
|
|
|
|
}
|
|
|
|
|
2012-10-25 13:36:25 +00:00
|
|
|
notesPopup.postMessage( JSON.stringify( messageData ), '*' );
|
2012-10-21 00:40:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Navigate to the current slide when the notes are loaded
|
2012-10-24 12:33:16 +00:00
|
|
|
notesPopup.addEventListener( 'load', function( event ) {
|
2013-07-26 13:48:21 +00:00
|
|
|
post();
|
2012-10-24 12:33:16 +00:00
|
|
|
}, false );
|
2012-10-21 00:40:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the there's a 'notes' query set, open directly
|
2012-10-25 13:36:25 +00:00
|
|
|
if( window.location.search.match( /(\?|\&)notes/gi ) !== null ) {
|
2012-10-21 00:40:52 +00:00
|
|
|
openNotes();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open the notes when the 's' key is hit
|
|
|
|
document.addEventListener( 'keydown', function( event ) {
|
2012-10-21 01:05:14 +00:00
|
|
|
// Disregard the event if the target is editable or a
|
2012-10-21 00:40:52 +00: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 12:33:16 +00:00
|
|
|
return { open: openNotes };
|
|
|
|
})();
|