notes.html 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>reveal.js - Slide Notes</title>
  6. <style>
  7. body {
  8. font-family: Helvetica;
  9. }
  10. #current-slide,
  11. #upcoming-slide,
  12. #speaker-controls {
  13. padding: 6px;
  14. box-sizing: border-box;
  15. -moz-box-sizing: border-box;
  16. }
  17. #current-slide iframe,
  18. #upcoming-slide iframe {
  19. width: 100%;
  20. height: 100%;
  21. border: 1px solid #ddd;
  22. }
  23. #current-slide .label,
  24. #upcoming-slide .label {
  25. position: absolute;
  26. top: 10px;
  27. left: 10px;
  28. font-weight: bold;
  29. font-size: 14px;
  30. z-index: 2;
  31. color: rgba( 255, 255, 255, 0.9 );
  32. }
  33. #current-slide {
  34. position: absolute;
  35. width: 65%;
  36. height: 100%;
  37. top: 0;
  38. left: 0;
  39. padding-right: 0;
  40. }
  41. #upcoming-slide {
  42. position: absolute;
  43. width: 35%;
  44. height: 40%;
  45. right: 0;
  46. top: 0;
  47. }
  48. #speaker-controls {
  49. position: absolute;
  50. top: 40%;
  51. right: 0;
  52. width: 35%;
  53. height: 60%;
  54. overflow: auto;
  55. font-size: 18px;
  56. }
  57. .speaker-controls-time.hidden,
  58. .speaker-controls-notes.hidden {
  59. display: none;
  60. }
  61. .speaker-controls-time .label,
  62. .speaker-controls-notes .label {
  63. text-transform: uppercase;
  64. font-weight: normal;
  65. font-size: 0.66em;
  66. color: #666;
  67. margin: 0;
  68. }
  69. .speaker-controls-time {
  70. border-bottom: 1px solid rgba( 200, 200, 200, 0.5 );
  71. margin-bottom: 10px;
  72. padding: 10px 16px;
  73. padding-bottom: 20px;
  74. cursor: pointer;
  75. }
  76. .speaker-controls-time .reset-button {
  77. opacity: 0;
  78. float: right;
  79. color: #666;
  80. text-decoration: none;
  81. }
  82. .speaker-controls-time:hover .reset-button {
  83. opacity: 1;
  84. }
  85. .speaker-controls-time .timer,
  86. .speaker-controls-time .clock {
  87. width: 50%;
  88. font-size: 1.9em;
  89. }
  90. .speaker-controls-time .timer {
  91. float: left;
  92. }
  93. .speaker-controls-time .clock {
  94. float: right;
  95. text-align: right;
  96. }
  97. .speaker-controls-time span.mute {
  98. color: #bbb;
  99. }
  100. .speaker-controls-notes {
  101. padding: 10px 16px;
  102. }
  103. .speaker-controls-notes .value {
  104. margin-top: 5px;
  105. line-height: 1.4;
  106. font-size: 1.2em;
  107. }
  108. .clear {
  109. clear: both;
  110. }
  111. @media screen and (max-width: 1080px) {
  112. #speaker-controls {
  113. font-size: 16px;
  114. }
  115. }
  116. @media screen and (max-width: 900px) {
  117. #speaker-controls {
  118. font-size: 14px;
  119. }
  120. }
  121. @media screen and (max-width: 800px) {
  122. #speaker-controls {
  123. font-size: 12px;
  124. }
  125. }
  126. </style>
  127. </head>
  128. <body>
  129. <div id="current-slide"></div>
  130. <div id="upcoming-slide"><span class="label">UPCOMING:</span></div>
  131. <div id="speaker-controls">
  132. <div class="speaker-controls-time">
  133. <h4 class="label">Time <span class="reset-button">Click to Reset</span></h4>
  134. <div class="clock">
  135. <span class="clock-value">0:00 AM</span>
  136. </div>
  137. <div class="timer">
  138. <span class="hours-value">00</span><span class="minutes-value">:00</span><span class="seconds-value">:00</span>
  139. </div>
  140. <div class="clear"></div>
  141. </div>
  142. <div class="speaker-controls-notes hidden">
  143. <h4 class="label">Notes</h4>
  144. <div class="value"></div>
  145. </div>
  146. </div>
  147. <script src="../../plugin/markdown/marked.js"></script>
  148. <script>
  149. (function() {
  150. var notes,
  151. notesValue,
  152. currentState,
  153. currentSlide,
  154. upcomingSlide,
  155. connected = false;
  156. window.addEventListener( 'message', function( event ) {
  157. var data = JSON.parse( event.data );
  158. // Messages sent by the notes plugin inside of the main window
  159. if( data && data.namespace === 'reveal-notes' ) {
  160. if( data.type === 'connect' ) {
  161. handleConnectMessage( data );
  162. }
  163. else if( data.type === 'state' ) {
  164. handleStateMessage( data );
  165. }
  166. }
  167. // Messages sent by the reveal.js inside of the current slide preview
  168. else if( data && data.namespace === 'reveal' ) {
  169. if( /ready/.test( data.eventName ) ) {
  170. // Send a message back to notify that the handshake is complete
  171. window.opener.postMessage( JSON.stringify({ namespace: 'reveal-notes', type: 'connected'} ), '*' );
  172. }
  173. else if( /slidechanged|fragmentshown|fragmenthidden|overviewshown|overviewhidden|paused|resumed/.test( data.eventName ) && currentState !== JSON.stringify( data.state ) ) {
  174. window.opener.postMessage( JSON.stringify({ method: 'setState', args: [ data.state ]} ), '*' );
  175. }
  176. }
  177. } );
  178. /**
  179. * Called when the main window is trying to establish a
  180. * connection.
  181. */
  182. function handleConnectMessage( data ) {
  183. if( connected === false ) {
  184. connected = true;
  185. setupIframes( data );
  186. setupKeyboard();
  187. setupNotes();
  188. setupTimer();
  189. }
  190. }
  191. /**
  192. * Called when the main window sends an updated state.
  193. */
  194. function handleStateMessage( data ) {
  195. // Store the most recently set state to avoid circular loops
  196. // applying the same state
  197. currentState = JSON.stringify( data.state );
  198. // No need for updating the notes in case of fragment changes
  199. if ( data.notes ) {
  200. notes.classList.remove( 'hidden' );
  201. notesValue.style.whiteSpace = data.whitespace;
  202. if( data.markdown ) {
  203. notesValue.innerHTML = marked( data.notes );
  204. }
  205. else {
  206. notesValue.innerHTML = data.notes;
  207. }
  208. }
  209. else {
  210. notes.classList.add( 'hidden' );
  211. }
  212. // Update the note slides
  213. currentSlide.contentWindow.postMessage( JSON.stringify({ method: 'setState', args: [ data.state ] }), '*' );
  214. upcomingSlide.contentWindow.postMessage( JSON.stringify({ method: 'setState', args: [ data.state ] }), '*' );
  215. upcomingSlide.contentWindow.postMessage( JSON.stringify({ method: 'next' }), '*' );
  216. }
  217. // Limit to max one state update per X ms
  218. handleStateMessage = debounce( handleStateMessage, 200 );
  219. /**
  220. * Forward keyboard events to the current slide window.
  221. * This enables keyboard events to work even if focus
  222. * isn't set on the current slide iframe.
  223. */
  224. function setupKeyboard() {
  225. document.addEventListener( 'keydown', function( event ) {
  226. currentSlide.contentWindow.postMessage( JSON.stringify({ method: 'triggerKey', args: [ event.keyCode ] }), '*' );
  227. } );
  228. }
  229. /**
  230. * Creates the preview iframes.
  231. */
  232. function setupIframes( data ) {
  233. var params = [
  234. 'receiver',
  235. 'progress=false',
  236. 'history=false',
  237. 'transition=none',
  238. 'autoSlide=0',
  239. 'backgroundTransition=none'
  240. ].join( '&' );
  241. var hash = '#/' + data.state.indexh + '/' + data.state.indexv;
  242. var currentURL = data.url + '?' + params + '&postMessageEvents=true' + hash;
  243. var upcomingURL = data.url + '?' + params + '&controls=false' + hash;
  244. currentSlide = document.createElement( 'iframe' );
  245. currentSlide.setAttribute( 'width', 1280 );
  246. currentSlide.setAttribute( 'height', 1024 );
  247. currentSlide.setAttribute( 'src', currentURL );
  248. document.querySelector( '#current-slide' ).appendChild( currentSlide );
  249. upcomingSlide = document.createElement( 'iframe' );
  250. upcomingSlide.setAttribute( 'width', 640 );
  251. upcomingSlide.setAttribute( 'height', 512 );
  252. upcomingSlide.setAttribute( 'src', upcomingURL );
  253. document.querySelector( '#upcoming-slide' ).appendChild( upcomingSlide );
  254. }
  255. /**
  256. * Setup the notes UI.
  257. */
  258. function setupNotes() {
  259. notes = document.querySelector( '.speaker-controls-notes' );
  260. notesValue = document.querySelector( '.speaker-controls-notes .value' );
  261. }
  262. /**
  263. * Create the timer and clock and start updating them
  264. * at an interval.
  265. */
  266. function setupTimer() {
  267. var start = new Date(),
  268. timeEl = document.querySelector( '.speaker-controls-time' ),
  269. clockEl = timeEl.querySelector( '.clock-value' ),
  270. hoursEl = timeEl.querySelector( '.hours-value' ),
  271. minutesEl = timeEl.querySelector( '.minutes-value' ),
  272. secondsEl = timeEl.querySelector( '.seconds-value' );
  273. function _updateTimer() {
  274. var diff, hours, minutes, seconds,
  275. now = new Date();
  276. diff = now.getTime() - start.getTime();
  277. hours = Math.floor( diff / ( 1000 * 60 * 60 ) );
  278. minutes = Math.floor( ( diff / ( 1000 * 60 ) ) % 60 );
  279. seconds = Math.floor( ( diff / 1000 ) % 60 );
  280. clockEl.innerHTML = now.toLocaleTimeString( 'en-US', { hour12: true, hour: '2-digit', minute:'2-digit' } );
  281. hoursEl.innerHTML = zeroPadInteger( hours );
  282. hoursEl.className = hours > 0 ? '' : 'mute';
  283. minutesEl.innerHTML = ':' + zeroPadInteger( minutes );
  284. minutesEl.className = minutes > 0 ? '' : 'mute';
  285. secondsEl.innerHTML = ':' + zeroPadInteger( seconds );
  286. }
  287. // Update once directly
  288. _updateTimer();
  289. // Then update every second
  290. setInterval( _updateTimer, 1000 );
  291. timeEl.addEventListener( 'click', function() {
  292. start = new Date();
  293. _updateTimer();
  294. return false;
  295. } );
  296. }
  297. function zeroPadInteger( num ) {
  298. var str = '00' + parseInt( num );
  299. return str.substring( str.length - 2 );
  300. }
  301. /**
  302. * Limits the frequency at which a function can be called.
  303. */
  304. function debounce( fn, ms ) {
  305. var lastTime = 0,
  306. timeout;
  307. return function() {
  308. var args = arguments;
  309. var context = this;
  310. clearTimeout( timeout );
  311. var timeSinceLastCall = Date.now() - lastTime;
  312. if( timeSinceLastCall > ms ) {
  313. fn.apply( context, args );
  314. lastTime = Date.now();
  315. }
  316. else {
  317. timeout = setTimeout( function() {
  318. fn.apply( context, args );
  319. lastTime = Date.now();
  320. }, ms - timeSinceLastCall );
  321. }
  322. }
  323. }
  324. })();
  325. </script>
  326. </body>
  327. </html>