From d5cc38e666c12263bed91e4d1e2ab450a71c795a Mon Sep 17 00:00:00 2001 From: Frederic Hemberger Date: Sun, 30 Dec 2012 12:54:16 +0100 Subject: [PATCH 1/2] Add presenter notes support --- shower.js | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/shower.js b/shower.js index 93e4a4d..bb2626a 100755 --- a/shower.js +++ b/shower.js @@ -18,7 +18,7 @@ window.shower = (function(window, document, undefined) { */ shower._getData = function(element, name) { return element.dataset ? element.dataset[name] : element.getAttribute('data-' + name); - } + }; for (i = 0; i < l; i++) { // Slide ID's are optional. In case of missing ID we set it to the @@ -133,9 +133,13 @@ window.shower = (function(window, document, undefined) { shower.enterSlideMode = function() { // check if it's already in slide mode... if ( body.classList.contains('full') ) { return; } - + body.classList.remove('list'); body.classList.add('full'); + + if ( window.console && window.console.clear ) { console.clear(); } + shower.showPresenterNotes( shower.getCurrentSlideNumber() ); + return shower._applyTransform(shower._getTransform()); }; @@ -146,7 +150,7 @@ window.shower = (function(window, document, undefined) { shower.enterListMode = function() { // check if it's already in list mode... if ( body.classList.contains('list') ) { return; } - + body.classList.remove('full'); body.classList.add('list'); return shower._applyTransform('none'); @@ -306,6 +310,29 @@ window.shower = (function(window, document, undefined) { return true; }; + /** + * Show presenter notes in console. + * @param {number} slideNumber slide number (sic!). Attention: starts from zero. + */ + shower.showPresenterNotes = function(slideNumber) { + if (window.console) { + var slide = slideList[ shower._normalizeSlideNumber(slideNumber) ].id; + var nextSlide = slideList[ shower._normalizeSlideNumber(slideNumber + 1) ].id; + + var notes = document.getElementById(slide).querySelector('.presenter-notes'); + if (notes) { + console.info(notes.innerHTML.replace(/\n\s+/g,'\n')); + } + if (nextSlide !== slide) { + var next = document.getElementById(nextSlide).querySelector('h2'); + if (next) { + next = next.innerHTML.replace(/^\s+|<[^>]+>/g,''); + console.info('NEXT: ' + next); + } + } + } + }; + /** * Get slide hash. * @param {number} slideNumber slide number (sic!). Attention: starts from zero. @@ -336,6 +363,7 @@ window.shower = (function(window, document, undefined) { if ( ! shower.isListMode()) { shower.updateProgress(slideNumber); shower.updateCurrentAndPassedSlides(slideNumber); + shower.showPresenterNotes(slideNumber); } return slideNumber; From 0fe9b48470fc4242cbe20c7ee40a606099b83eee Mon Sep 17 00:00:00 2001 From: Frederic Hemberger Date: Tue, 1 Jan 2013 16:46:52 +0100 Subject: [PATCH 2/2] Adjust styling after code review --- shower.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/shower.js b/shower.js index bb2626a..3d13985 100755 --- a/shower.js +++ b/shower.js @@ -132,13 +132,13 @@ window.shower = (function(window, document, undefined) { */ shower.enterSlideMode = function() { // check if it's already in slide mode... - if ( body.classList.contains('full') ) { return; } + if (body.classList.contains('full')) { return; } body.classList.remove('list'); body.classList.add('full'); - if ( window.console && window.console.clear ) { console.clear(); } - shower.showPresenterNotes( shower.getCurrentSlideNumber() ); + if (window.console && window.console.clear) { console.clear(); } + shower.showPresenterNotes(shower.getCurrentSlideNumber()); return shower._applyTransform(shower._getTransform()); }; @@ -149,7 +149,7 @@ window.shower = (function(window, document, undefined) { */ shower.enterListMode = function() { // check if it's already in list mode... - if ( body.classList.contains('list') ) { return; } + if (body.classList.contains('list')) { return; } body.classList.remove('full'); body.classList.add('list'); @@ -316,15 +316,17 @@ window.shower = (function(window, document, undefined) { */ shower.showPresenterNotes = function(slideNumber) { if (window.console) { - var slide = slideList[ shower._normalizeSlideNumber(slideNumber) ].id; - var nextSlide = slideList[ shower._normalizeSlideNumber(slideNumber + 1) ].id; + slideNumber = shower._normalizeSlideNumber(slideNumber); - var notes = document.getElementById(slide).querySelector('.presenter-notes'); + var slideId = slideList[slideNumber].id; + var nextSlideId = slideList[slideNumber + 1] ? slideList[slideNumber + 1].id : null; + + var notes = document.getElementById(slideId).querySelector('.presenter-notes'); if (notes) { console.info(notes.innerHTML.replace(/\n\s+/g,'\n')); } - if (nextSlide !== slide) { - var next = document.getElementById(nextSlide).querySelector('h2'); + if (nextSlideId) { + var next = document.getElementById(nextSlideId).querySelector('h2'); if (next) { next = next.innerHTML.replace(/^\s+|<[^>]+>/g,''); console.info('NEXT: ' + next);