Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 1 | <html lang="en"> |
| 2 | <head> |
| 3 | <meta charset="utf-8"> |
| 4 | |
| 5 | <title>reveal.js - Speaker View</title> |
| 6 | |
| 7 | <style> |
| 8 | body { |
| 9 | font-family: Helvetica; |
| 10 | font-size: 18px; |
| 11 | } |
| 12 | |
| 13 | #current-slide, |
| 14 | #upcoming-slide, |
| 15 | #speaker-controls { |
| 16 | padding: 6px; |
| 17 | box-sizing: border-box; |
| 18 | -moz-box-sizing: border-box; |
| 19 | } |
| 20 | |
| 21 | #current-slide iframe, |
| 22 | #upcoming-slide iframe { |
| 23 | width: 100%; |
| 24 | height: 100%; |
| 25 | border: 1px solid #ddd; |
| 26 | } |
| 27 | |
| 28 | #current-slide .label, |
| 29 | #upcoming-slide .label { |
| 30 | position: absolute; |
| 31 | top: 10px; |
| 32 | left: 10px; |
| 33 | z-index: 2; |
| 34 | } |
| 35 | |
| 36 | #connection-status { |
| 37 | position: absolute; |
| 38 | top: 0; |
| 39 | left: 0; |
| 40 | width: 100%; |
| 41 | height: 100%; |
| 42 | z-index: 20; |
| 43 | padding: 30% 20% 20% 20%; |
| 44 | font-size: 18px; |
| 45 | color: #222; |
| 46 | background: #fff; |
| 47 | text-align: center; |
| 48 | box-sizing: border-box; |
| 49 | line-height: 1.4; |
| 50 | } |
| 51 | |
| 52 | .overlay-element { |
| 53 | height: 34px; |
| 54 | line-height: 34px; |
| 55 | padding: 0 10px; |
| 56 | text-shadow: none; |
| 57 | background: rgba( 220, 220, 220, 0.8 ); |
| 58 | color: #222; |
| 59 | font-size: 14px; |
| 60 | } |
| 61 | |
| 62 | .overlay-element.interactive:hover { |
| 63 | background: rgba( 220, 220, 220, 1 ); |
| 64 | } |
| 65 | |
| 66 | #current-slide { |
| 67 | position: absolute; |
| 68 | width: 60%; |
| 69 | height: 100%; |
| 70 | top: 0; |
| 71 | left: 0; |
| 72 | padding-right: 0; |
| 73 | } |
| 74 | |
| 75 | #upcoming-slide { |
| 76 | position: absolute; |
| 77 | width: 40%; |
| 78 | height: 40%; |
| 79 | right: 0; |
| 80 | top: 0; |
| 81 | } |
| 82 | |
| 83 | /* Speaker controls */ |
| 84 | #speaker-controls { |
| 85 | position: absolute; |
| 86 | top: 40%; |
| 87 | right: 0; |
| 88 | width: 40%; |
| 89 | height: 60%; |
| 90 | overflow: auto; |
| 91 | font-size: 18px; |
| 92 | } |
| 93 | |
| 94 | .speaker-controls-time.hidden, |
| 95 | .speaker-controls-notes.hidden { |
| 96 | display: none; |
| 97 | } |
| 98 | |
| 99 | .speaker-controls-time .label, |
| 100 | .speaker-controls-pace .label, |
| 101 | .speaker-controls-notes .label { |
| 102 | text-transform: uppercase; |
| 103 | font-weight: normal; |
| 104 | font-size: 0.66em; |
| 105 | color: #666; |
| 106 | margin: 0; |
| 107 | } |
| 108 | |
| 109 | .speaker-controls-time, .speaker-controls-pace { |
| 110 | border-bottom: 1px solid rgba( 200, 200, 200, 0.5 ); |
| 111 | margin-bottom: 10px; |
| 112 | padding: 10px 16px; |
| 113 | padding-bottom: 20px; |
| 114 | cursor: pointer; |
| 115 | } |
| 116 | |
| 117 | .speaker-controls-time .reset-button { |
| 118 | opacity: 0; |
| 119 | float: right; |
| 120 | color: #666; |
| 121 | text-decoration: none; |
| 122 | } |
| 123 | .speaker-controls-time:hover .reset-button { |
| 124 | opacity: 1; |
| 125 | } |
| 126 | |
| 127 | .speaker-controls-time .timer, |
| 128 | .speaker-controls-time .clock { |
| 129 | width: 50%; |
| 130 | } |
| 131 | |
| 132 | .speaker-controls-time .timer, |
| 133 | .speaker-controls-time .clock, |
| 134 | .speaker-controls-time .pacing .hours-value, |
| 135 | .speaker-controls-time .pacing .minutes-value, |
| 136 | .speaker-controls-time .pacing .seconds-value { |
| 137 | font-size: 1.9em; |
| 138 | } |
| 139 | |
| 140 | .speaker-controls-time .timer { |
| 141 | float: left; |
| 142 | } |
| 143 | |
| 144 | .speaker-controls-time .clock { |
| 145 | float: right; |
| 146 | text-align: right; |
| 147 | } |
| 148 | |
| 149 | .speaker-controls-time span.mute { |
| 150 | opacity: 0.3; |
| 151 | } |
| 152 | |
| 153 | .speaker-controls-time .pacing-title { |
| 154 | margin-top: 5px; |
| 155 | } |
| 156 | |
| 157 | .speaker-controls-time .pacing.ahead { |
| 158 | color: blue; |
| 159 | } |
| 160 | |
| 161 | .speaker-controls-time .pacing.on-track { |
| 162 | color: green; |
| 163 | } |
| 164 | |
| 165 | .speaker-controls-time .pacing.behind { |
| 166 | color: red; |
| 167 | } |
| 168 | |
| 169 | .speaker-controls-notes { |
| 170 | padding: 10px 16px; |
| 171 | } |
| 172 | |
| 173 | .speaker-controls-notes .value { |
| 174 | margin-top: 5px; |
| 175 | line-height: 1.4; |
| 176 | font-size: 1.2em; |
| 177 | } |
| 178 | |
| 179 | /* Layout selector */ |
| 180 | #speaker-layout { |
| 181 | position: absolute; |
| 182 | top: 10px; |
| 183 | right: 10px; |
| 184 | color: #222; |
| 185 | z-index: 10; |
| 186 | } |
| 187 | #speaker-layout select { |
| 188 | position: absolute; |
| 189 | width: 100%; |
| 190 | height: 100%; |
| 191 | top: 0; |
| 192 | left: 0; |
| 193 | border: 0; |
| 194 | box-shadow: 0; |
| 195 | cursor: pointer; |
| 196 | opacity: 0; |
| 197 | |
| 198 | font-size: 1em; |
| 199 | background-color: transparent; |
| 200 | |
| 201 | -moz-appearance: none; |
| 202 | -webkit-appearance: none; |
| 203 | -webkit-tap-highlight-color: rgba(0, 0, 0, 0); |
| 204 | } |
| 205 | |
| 206 | #speaker-layout select:focus { |
| 207 | outline: none; |
| 208 | box-shadow: none; |
| 209 | } |
| 210 | |
| 211 | .clear { |
| 212 | clear: both; |
| 213 | } |
| 214 | |
| 215 | /* Speaker layout: Wide */ |
| 216 | body[data-speaker-layout="wide"] #current-slide, |
| 217 | body[data-speaker-layout="wide"] #upcoming-slide { |
| 218 | width: 50%; |
| 219 | height: 45%; |
| 220 | padding: 6px; |
| 221 | } |
| 222 | |
| 223 | body[data-speaker-layout="wide"] #current-slide { |
| 224 | top: 0; |
| 225 | left: 0; |
| 226 | } |
| 227 | |
| 228 | body[data-speaker-layout="wide"] #upcoming-slide { |
| 229 | top: 0; |
| 230 | left: 50%; |
| 231 | } |
| 232 | |
| 233 | body[data-speaker-layout="wide"] #speaker-controls { |
| 234 | top: 45%; |
| 235 | left: 0; |
| 236 | width: 100%; |
| 237 | height: 50%; |
| 238 | font-size: 1.25em; |
| 239 | } |
| 240 | |
| 241 | /* Speaker layout: Tall */ |
| 242 | body[data-speaker-layout="tall"] #current-slide, |
| 243 | body[data-speaker-layout="tall"] #upcoming-slide { |
| 244 | width: 45%; |
| 245 | height: 50%; |
| 246 | padding: 6px; |
| 247 | } |
| 248 | |
| 249 | body[data-speaker-layout="tall"] #current-slide { |
| 250 | top: 0; |
| 251 | left: 0; |
| 252 | } |
| 253 | |
| 254 | body[data-speaker-layout="tall"] #upcoming-slide { |
| 255 | top: 50%; |
| 256 | left: 0; |
| 257 | } |
| 258 | |
| 259 | body[data-speaker-layout="tall"] #speaker-controls { |
| 260 | padding-top: 40px; |
| 261 | top: 0; |
| 262 | left: 45%; |
| 263 | width: 55%; |
| 264 | height: 100%; |
| 265 | font-size: 1.25em; |
| 266 | } |
| 267 | |
| 268 | /* Speaker layout: Notes only */ |
| 269 | body[data-speaker-layout="notes-only"] #current-slide, |
| 270 | body[data-speaker-layout="notes-only"] #upcoming-slide { |
| 271 | display: none; |
| 272 | } |
| 273 | |
| 274 | body[data-speaker-layout="notes-only"] #speaker-controls { |
| 275 | padding-top: 40px; |
| 276 | top: 0; |
| 277 | left: 0; |
| 278 | width: 100%; |
| 279 | height: 100%; |
| 280 | font-size: 1.25em; |
| 281 | } |
| 282 | |
| 283 | @media screen and (max-width: 1080px) { |
| 284 | body[data-speaker-layout="default"] #speaker-controls { |
| 285 | font-size: 16px; |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | @media screen and (max-width: 900px) { |
| 290 | body[data-speaker-layout="default"] #speaker-controls { |
| 291 | font-size: 14px; |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | @media screen and (max-width: 800px) { |
| 296 | body[data-speaker-layout="default"] #speaker-controls { |
| 297 | font-size: 12px; |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | </style> |
| 302 | </head> |
| 303 | |
| 304 | <body> |
| 305 | |
| 306 | <div id="connection-status">Loading speaker view...</div> |
| 307 | |
| 308 | <div id="current-slide"></div> |
| 309 | <div id="upcoming-slide"><span class="overlay-element label">Upcoming</span></div> |
| 310 | <div id="speaker-controls"> |
| 311 | <div class="speaker-controls-time"> |
| 312 | <h4 class="label">Time <span class="reset-button">Click to Reset</span></h4> |
| 313 | <div class="clock"> |
| 314 | <span class="clock-value">0:00 AM</span> |
| 315 | </div> |
| 316 | <div class="timer"> |
| 317 | <span class="hours-value">00</span><span class="minutes-value">:00</span><span class="seconds-value">:00</span> |
| 318 | </div> |
| 319 | <div class="clear"></div> |
| 320 | |
| 321 | <h4 class="label pacing-title" style="display: none">Pacing – Time to finish current slide</h4> |
| 322 | <div class="pacing" style="display: none"> |
| 323 | <span class="hours-value">00</span><span class="minutes-value">:00</span><span class="seconds-value">:00</span> |
| 324 | </div> |
| 325 | </div> |
| 326 | |
| 327 | <div class="speaker-controls-notes hidden"> |
| 328 | <h4 class="label">Notes</h4> |
| 329 | <div class="value"></div> |
| 330 | </div> |
| 331 | </div> |
| 332 | <div id="speaker-layout" class="overlay-element interactive"> |
| 333 | <span class="speaker-layout-label"></span> |
| 334 | <select class="speaker-layout-dropdown"></select> |
| 335 | </div> |
| 336 | |
| 337 | <script> |
| 338 | |
| 339 | (function() { |
| 340 | |
| 341 | var notes, |
| 342 | notesValue, |
| 343 | currentState, |
| 344 | currentSlide, |
| 345 | upcomingSlide, |
| 346 | layoutLabel, |
| 347 | layoutDropdown, |
| 348 | pendingCalls = {}, |
| 349 | lastRevealApiCallId = 0, |
| 350 | connected = false; |
| 351 | |
| 352 | var SPEAKER_LAYOUTS = { |
| 353 | 'default': 'Default', |
| 354 | 'wide': 'Wide', |
| 355 | 'tall': 'Tall', |
| 356 | 'notes-only': 'Notes only' |
| 357 | }; |
| 358 | |
| 359 | setupLayout(); |
| 360 | |
| 361 | var connectionStatus = document.querySelector( '#connection-status' ); |
| 362 | var connectionTimeout = setTimeout( function() { |
| 363 | connectionStatus.innerHTML = 'Error connecting to main window.<br>Please try closing and reopening the speaker view.'; |
| 364 | }, 5000 ); |
| 365 | |
| 366 | window.addEventListener( 'message', function( event ) { |
| 367 | |
| 368 | clearTimeout( connectionTimeout ); |
| 369 | connectionStatus.style.display = 'none'; |
| 370 | |
| 371 | var data = JSON.parse( event.data ); |
| 372 | |
| 373 | // The overview mode is only useful to the reveal.js instance |
| 374 | // where navigation occurs so we don't sync it |
| 375 | if( data.state ) delete data.state.overview; |
| 376 | |
| 377 | // Messages sent by the notes plugin inside of the main window |
| 378 | if( data && data.namespace === 'reveal-notes' ) { |
| 379 | if( data.type === 'connect' ) { |
| 380 | handleConnectMessage( data ); |
| 381 | } |
| 382 | else if( data.type === 'state' ) { |
| 383 | handleStateMessage( data ); |
| 384 | } |
| 385 | else if( data.type === 'return' ) { |
| 386 | pendingCalls[data.callId](data.result); |
| 387 | delete pendingCalls[data.callId]; |
| 388 | } |
| 389 | } |
| 390 | // Messages sent by the reveal.js inside of the current slide preview |
| 391 | else if( data && data.namespace === 'reveal' ) { |
| 392 | if( /ready/.test( data.eventName ) ) { |
| 393 | // Send a message back to notify that the handshake is complete |
| 394 | window.opener.postMessage( JSON.stringify({ namespace: 'reveal-notes', type: 'connected'} ), '*' ); |
| 395 | } |
| 396 | else if( /slidechanged|fragmentshown|fragmenthidden|paused|resumed/.test( data.eventName ) && currentState !== JSON.stringify( data.state ) ) { |
| 397 | |
| 398 | window.opener.postMessage( JSON.stringify({ method: 'setState', args: [ data.state ]} ), '*' ); |
| 399 | |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | } ); |
| 404 | |
| 405 | /** |
| 406 | * Asynchronously calls the Reveal.js API of the main frame. |
| 407 | */ |
| 408 | function callRevealApi( methodName, methodArguments, callback ) { |
| 409 | |
| 410 | var callId = ++lastRevealApiCallId; |
| 411 | pendingCalls[callId] = callback; |
| 412 | window.opener.postMessage( JSON.stringify( { |
| 413 | namespace: 'reveal-notes', |
| 414 | type: 'call', |
| 415 | callId: callId, |
| 416 | methodName: methodName, |
| 417 | arguments: methodArguments |
| 418 | } ), '*' ); |
| 419 | |
| 420 | } |
| 421 | |
| 422 | /** |
| 423 | * Called when the main window is trying to establish a |
| 424 | * connection. |
| 425 | */ |
| 426 | function handleConnectMessage( data ) { |
| 427 | |
| 428 | if( connected === false ) { |
| 429 | connected = true; |
| 430 | |
| 431 | setupIframes( data ); |
| 432 | setupKeyboard(); |
| 433 | setupNotes(); |
| 434 | setupTimer(); |
| 435 | } |
| 436 | |
| 437 | } |
| 438 | |
| 439 | /** |
| 440 | * Called when the main window sends an updated state. |
| 441 | */ |
| 442 | function handleStateMessage( data ) { |
| 443 | |
| 444 | // Store the most recently set state to avoid circular loops |
| 445 | // applying the same state |
| 446 | currentState = JSON.stringify( data.state ); |
| 447 | |
| 448 | // No need for updating the notes in case of fragment changes |
| 449 | if ( data.notes ) { |
| 450 | notes.classList.remove( 'hidden' ); |
| 451 | notesValue.style.whiteSpace = data.whitespace; |
| 452 | if( data.markdown ) { |
| 453 | notesValue.innerHTML = marked( data.notes ); |
| 454 | } |
| 455 | else { |
| 456 | notesValue.innerHTML = data.notes; |
| 457 | } |
| 458 | } |
| 459 | else { |
| 460 | notes.classList.add( 'hidden' ); |
| 461 | } |
| 462 | |
| 463 | // Update the note slides |
| 464 | currentSlide.contentWindow.postMessage( JSON.stringify({ method: 'setState', args: [ data.state ] }), '*' ); |
| 465 | upcomingSlide.contentWindow.postMessage( JSON.stringify({ method: 'setState', args: [ data.state ] }), '*' ); |
| 466 | upcomingSlide.contentWindow.postMessage( JSON.stringify({ method: 'next' }), '*' ); |
| 467 | |
| 468 | } |
| 469 | |
| 470 | // Limit to max one state update per X ms |
| 471 | handleStateMessage = debounce( handleStateMessage, 200 ); |
| 472 | |
| 473 | /** |
| 474 | * Forward keyboard events to the current slide window. |
| 475 | * This enables keyboard events to work even if focus |
| 476 | * isn't set on the current slide iframe. |
| 477 | * |
| 478 | * Block F5 default handling, it reloads and disconnects |
| 479 | * the speaker notes window. |
| 480 | */ |
| 481 | function setupKeyboard() { |
| 482 | |
| 483 | document.addEventListener( 'keydown', function( event ) { |
| 484 | if( event.keyCode === 116 || ( event.metaKey && event.keyCode === 82 ) ) { |
| 485 | event.preventDefault(); |
| 486 | return false; |
| 487 | } |
| 488 | currentSlide.contentWindow.postMessage( JSON.stringify({ method: 'triggerKey', args: [ event.keyCode ] }), '*' ); |
| 489 | } ); |
| 490 | |
| 491 | } |
| 492 | |
| 493 | /** |
| 494 | * Creates the preview iframes. |
| 495 | */ |
| 496 | function setupIframes( data ) { |
| 497 | |
| 498 | var params = [ |
| 499 | 'receiver', |
| 500 | 'progress=false', |
| 501 | 'history=false', |
| 502 | 'transition=none', |
| 503 | 'autoSlide=0', |
| 504 | 'backgroundTransition=none' |
| 505 | ].join( '&' ); |
| 506 | |
| 507 | var urlSeparator = /\?/.test(data.url) ? '&' : '?'; |
| 508 | var hash = '#/' + data.state.indexh + '/' + data.state.indexv; |
| 509 | var currentURL = data.url + urlSeparator + params + '&postMessageEvents=true' + hash; |
| 510 | var upcomingURL = data.url + urlSeparator + params + '&controls=false' + hash; |
| 511 | |
| 512 | currentSlide = document.createElement( 'iframe' ); |
| 513 | currentSlide.setAttribute( 'width', 1280 ); |
| 514 | currentSlide.setAttribute( 'height', 1024 ); |
| 515 | currentSlide.setAttribute( 'src', currentURL ); |
| 516 | document.querySelector( '#current-slide' ).appendChild( currentSlide ); |
| 517 | |
| 518 | upcomingSlide = document.createElement( 'iframe' ); |
| 519 | upcomingSlide.setAttribute( 'width', 640 ); |
| 520 | upcomingSlide.setAttribute( 'height', 512 ); |
| 521 | upcomingSlide.setAttribute( 'src', upcomingURL ); |
| 522 | document.querySelector( '#upcoming-slide' ).appendChild( upcomingSlide ); |
| 523 | |
| 524 | } |
| 525 | |
| 526 | /** |
| 527 | * Setup the notes UI. |
| 528 | */ |
| 529 | function setupNotes() { |
| 530 | |
| 531 | notes = document.querySelector( '.speaker-controls-notes' ); |
| 532 | notesValue = document.querySelector( '.speaker-controls-notes .value' ); |
| 533 | |
| 534 | } |
| 535 | |
| 536 | function getTimings( callback ) { |
| 537 | |
| 538 | callRevealApi( 'getSlidesAttributes', [], function ( slideAttributes ) { |
| 539 | callRevealApi( 'getConfig', [], function ( config ) { |
| 540 | var totalTime = config.totalTime; |
| 541 | var minTimePerSlide = config.minimumTimePerSlide || 0; |
| 542 | var defaultTiming = config.defaultTiming; |
| 543 | if ((defaultTiming == null) && (totalTime == null)) { |
| 544 | callback(null); |
| 545 | return; |
| 546 | } |
| 547 | // Setting totalTime overrides defaultTiming |
| 548 | if (totalTime) { |
| 549 | defaultTiming = 0; |
| 550 | } |
| 551 | var timings = []; |
| 552 | for ( var i in slideAttributes ) { |
| 553 | var slide = slideAttributes[ i ]; |
| 554 | var timing = defaultTiming; |
| 555 | if( slide.hasOwnProperty( 'data-timing' )) { |
| 556 | var t = slide[ 'data-timing' ]; |
| 557 | timing = parseInt(t); |
| 558 | if( isNaN(timing) ) { |
| 559 | console.warn("Could not parse timing '" + t + "' of slide " + i + "; using default of " + defaultTiming); |
| 560 | timing = defaultTiming; |
| 561 | } |
| 562 | } |
| 563 | timings.push(timing); |
| 564 | } |
| 565 | if ( totalTime ) { |
| 566 | // After we've allocated time to individual slides, we summarize it and |
| 567 | // subtract it from the total time |
| 568 | var remainingTime = totalTime - timings.reduce( function(a, b) { return a + b; }, 0 ); |
| 569 | // The remaining time is divided by the number of slides that have 0 seconds |
| 570 | // allocated at the moment, giving the average time-per-slide on the remaining slides |
| 571 | var remainingSlides = (timings.filter( function(x) { return x == 0 }) ).length |
| 572 | var timePerSlide = Math.round( remainingTime / remainingSlides, 0 ) |
| 573 | // And now we replace every zero-value timing with that average |
| 574 | timings = timings.map( function(x) { return (x==0 ? timePerSlide : x) } ); |
| 575 | } |
| 576 | var slidesUnderMinimum = timings.filter( function(x) { return (x < minTimePerSlide) } ).length |
| 577 | if ( slidesUnderMinimum ) { |
| 578 | message = "The pacing time for " + slidesUnderMinimum + " slide(s) is under the configured minimum of " + minTimePerSlide + " seconds. Check the data-timing attribute on individual slides, or consider increasing the totalTime or minimumTimePerSlide configuration options (or removing some slides)."; |
| 579 | alert(message); |
| 580 | } |
| 581 | callback( timings ); |
| 582 | } ); |
| 583 | } ); |
| 584 | |
| 585 | } |
| 586 | |
| 587 | /** |
| 588 | * Return the number of seconds allocated for presenting |
| 589 | * all slides up to and including this one. |
| 590 | */ |
| 591 | function getTimeAllocated( timings, callback ) { |
| 592 | |
| 593 | callRevealApi( 'getSlidePastCount', [], function ( currentSlide ) { |
| 594 | var allocated = 0; |
| 595 | for (var i in timings.slice(0, currentSlide + 1)) { |
| 596 | allocated += timings[i]; |
| 597 | } |
| 598 | callback( allocated ); |
| 599 | } ); |
| 600 | |
| 601 | } |
| 602 | |
| 603 | /** |
| 604 | * Create the timer and clock and start updating them |
| 605 | * at an interval. |
| 606 | */ |
| 607 | function setupTimer() { |
| 608 | |
| 609 | var start = new Date(), |
| 610 | timeEl = document.querySelector( '.speaker-controls-time' ), |
| 611 | clockEl = timeEl.querySelector( '.clock-value' ), |
| 612 | hoursEl = timeEl.querySelector( '.hours-value' ), |
| 613 | minutesEl = timeEl.querySelector( '.minutes-value' ), |
| 614 | secondsEl = timeEl.querySelector( '.seconds-value' ), |
| 615 | pacingTitleEl = timeEl.querySelector( '.pacing-title' ), |
| 616 | pacingEl = timeEl.querySelector( '.pacing' ), |
| 617 | pacingHoursEl = pacingEl.querySelector( '.hours-value' ), |
| 618 | pacingMinutesEl = pacingEl.querySelector( '.minutes-value' ), |
| 619 | pacingSecondsEl = pacingEl.querySelector( '.seconds-value' ); |
| 620 | |
| 621 | var timings = null; |
| 622 | getTimings( function ( _timings ) { |
| 623 | |
| 624 | timings = _timings; |
| 625 | if (_timings !== null) { |
| 626 | pacingTitleEl.style.removeProperty('display'); |
| 627 | pacingEl.style.removeProperty('display'); |
| 628 | } |
| 629 | |
| 630 | // Update once directly |
| 631 | _updateTimer(); |
| 632 | |
| 633 | // Then update every second |
| 634 | setInterval( _updateTimer, 1000 ); |
| 635 | |
| 636 | } ); |
| 637 | |
| 638 | |
| 639 | function _resetTimer() { |
| 640 | |
| 641 | if (timings == null) { |
| 642 | start = new Date(); |
| 643 | _updateTimer(); |
| 644 | } |
| 645 | else { |
| 646 | // Reset timer to beginning of current slide |
| 647 | getTimeAllocated( timings, function ( slideEndTimingSeconds ) { |
| 648 | var slideEndTiming = slideEndTimingSeconds * 1000; |
| 649 | callRevealApi( 'getSlidePastCount', [], function ( currentSlide ) { |
| 650 | var currentSlideTiming = timings[currentSlide] * 1000; |
| 651 | var previousSlidesTiming = slideEndTiming - currentSlideTiming; |
| 652 | var now = new Date(); |
| 653 | start = new Date(now.getTime() - previousSlidesTiming); |
| 654 | _updateTimer(); |
| 655 | } ); |
| 656 | } ); |
| 657 | } |
| 658 | |
| 659 | } |
| 660 | |
| 661 | timeEl.addEventListener( 'click', function() { |
| 662 | _resetTimer(); |
| 663 | return false; |
| 664 | } ); |
| 665 | |
| 666 | function _displayTime( hrEl, minEl, secEl, time) { |
| 667 | |
| 668 | var sign = Math.sign(time) == -1 ? "-" : ""; |
| 669 | time = Math.abs(Math.round(time / 1000)); |
| 670 | var seconds = time % 60; |
| 671 | var minutes = Math.floor( time / 60 ) % 60 ; |
| 672 | var hours = Math.floor( time / ( 60 * 60 )) ; |
| 673 | hrEl.innerHTML = sign + zeroPadInteger( hours ); |
| 674 | if (hours == 0) { |
| 675 | hrEl.classList.add( 'mute' ); |
| 676 | } |
| 677 | else { |
| 678 | hrEl.classList.remove( 'mute' ); |
| 679 | } |
| 680 | minEl.innerHTML = ':' + zeroPadInteger( minutes ); |
| 681 | if (hours == 0 && minutes == 0) { |
| 682 | minEl.classList.add( 'mute' ); |
| 683 | } |
| 684 | else { |
| 685 | minEl.classList.remove( 'mute' ); |
| 686 | } |
| 687 | secEl.innerHTML = ':' + zeroPadInteger( seconds ); |
| 688 | } |
| 689 | |
| 690 | function _updateTimer() { |
| 691 | |
| 692 | var diff, hours, minutes, seconds, |
| 693 | now = new Date(); |
| 694 | |
| 695 | diff = now.getTime() - start.getTime(); |
| 696 | |
| 697 | clockEl.innerHTML = now.toLocaleTimeString( 'en-US', { hour12: true, hour: '2-digit', minute:'2-digit' } ); |
| 698 | _displayTime( hoursEl, minutesEl, secondsEl, diff ); |
| 699 | if (timings !== null) { |
| 700 | _updatePacing(diff); |
| 701 | } |
| 702 | |
| 703 | } |
| 704 | |
| 705 | function _updatePacing(diff) { |
| 706 | |
| 707 | getTimeAllocated( timings, function ( slideEndTimingSeconds ) { |
| 708 | var slideEndTiming = slideEndTimingSeconds * 1000; |
| 709 | |
| 710 | callRevealApi( 'getSlidePastCount', [], function ( currentSlide ) { |
| 711 | var currentSlideTiming = timings[currentSlide] * 1000; |
| 712 | var timeLeftCurrentSlide = slideEndTiming - diff; |
| 713 | if (timeLeftCurrentSlide < 0) { |
| 714 | pacingEl.className = 'pacing behind'; |
| 715 | } |
| 716 | else if (timeLeftCurrentSlide < currentSlideTiming) { |
| 717 | pacingEl.className = 'pacing on-track'; |
| 718 | } |
| 719 | else { |
| 720 | pacingEl.className = 'pacing ahead'; |
| 721 | } |
| 722 | _displayTime( pacingHoursEl, pacingMinutesEl, pacingSecondsEl, timeLeftCurrentSlide ); |
| 723 | } ); |
| 724 | } ); |
| 725 | } |
| 726 | |
| 727 | } |
| 728 | |
| 729 | /** |
| 730 | * Sets up the speaker view layout and layout selector. |
| 731 | */ |
| 732 | function setupLayout() { |
| 733 | |
| 734 | layoutDropdown = document.querySelector( '.speaker-layout-dropdown' ); |
| 735 | layoutLabel = document.querySelector( '.speaker-layout-label' ); |
| 736 | |
| 737 | // Render the list of available layouts |
| 738 | for( var id in SPEAKER_LAYOUTS ) { |
| 739 | var option = document.createElement( 'option' ); |
| 740 | option.setAttribute( 'value', id ); |
| 741 | option.textContent = SPEAKER_LAYOUTS[ id ]; |
| 742 | layoutDropdown.appendChild( option ); |
| 743 | } |
| 744 | |
| 745 | // Monitor the dropdown for changes |
| 746 | layoutDropdown.addEventListener( 'change', function( event ) { |
| 747 | |
| 748 | setLayout( layoutDropdown.value ); |
| 749 | |
| 750 | }, false ); |
| 751 | |
| 752 | // Restore any currently persisted layout |
| 753 | setLayout( getLayout() ); |
| 754 | |
| 755 | } |
| 756 | |
| 757 | /** |
| 758 | * Sets a new speaker view layout. The layout is persisted |
| 759 | * in local storage. |
| 760 | */ |
| 761 | function setLayout( value ) { |
| 762 | |
| 763 | var title = SPEAKER_LAYOUTS[ value ]; |
| 764 | |
| 765 | layoutLabel.innerHTML = 'Layout' + ( title ? ( ': ' + title ) : '' ); |
| 766 | layoutDropdown.value = value; |
| 767 | |
| 768 | document.body.setAttribute( 'data-speaker-layout', value ); |
| 769 | |
| 770 | // Persist locally |
| 771 | if( supportsLocalStorage() ) { |
| 772 | window.localStorage.setItem( 'reveal-speaker-layout', value ); |
| 773 | } |
| 774 | |
| 775 | } |
| 776 | |
| 777 | /** |
| 778 | * Returns the ID of the most recently set speaker layout |
| 779 | * or our default layout if none has been set. |
| 780 | */ |
| 781 | function getLayout() { |
| 782 | |
| 783 | if( supportsLocalStorage() ) { |
| 784 | var layout = window.localStorage.getItem( 'reveal-speaker-layout' ); |
| 785 | if( layout ) { |
| 786 | return layout; |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | // Default to the first record in the layouts hash |
| 791 | for( var id in SPEAKER_LAYOUTS ) { |
| 792 | return id; |
| 793 | } |
| 794 | |
| 795 | } |
| 796 | |
| 797 | function supportsLocalStorage() { |
| 798 | |
| 799 | try { |
| 800 | localStorage.setItem('test', 'test'); |
| 801 | localStorage.removeItem('test'); |
| 802 | return true; |
| 803 | } |
| 804 | catch( e ) { |
| 805 | return false; |
| 806 | } |
| 807 | |
| 808 | } |
| 809 | |
| 810 | function zeroPadInteger( num ) { |
| 811 | |
| 812 | var str = '00' + parseInt( num ); |
| 813 | return str.substring( str.length - 2 ); |
| 814 | |
| 815 | } |
| 816 | |
| 817 | /** |
| 818 | * Limits the frequency at which a function can be called. |
| 819 | */ |
| 820 | function debounce( fn, ms ) { |
| 821 | |
| 822 | var lastTime = 0, |
| 823 | timeout; |
| 824 | |
| 825 | return function() { |
| 826 | |
| 827 | var args = arguments; |
| 828 | var context = this; |
| 829 | |
| 830 | clearTimeout( timeout ); |
| 831 | |
| 832 | var timeSinceLastCall = Date.now() - lastTime; |
| 833 | if( timeSinceLastCall > ms ) { |
| 834 | fn.apply( context, args ); |
| 835 | lastTime = Date.now(); |
| 836 | } |
| 837 | else { |
| 838 | timeout = setTimeout( function() { |
| 839 | fn.apply( context, args ); |
| 840 | lastTime = Date.now(); |
| 841 | }, ms - timeSinceLastCall ); |
| 842 | } |
| 843 | |
| 844 | } |
| 845 | |
| 846 | } |
| 847 | |
| 848 | })(); |
| 849 | |
| 850 | </script> |
| 851 | </body> |
| 852 | </html> |