2012-10-21 02:40:52 +02:00
< html lang = "en" >
< head >
< meta charset = "utf-8" >
2020-05-18 15:59:18 +02:00
< title > reveal.js - Speaker View< / title >
2012-10-21 02:40:52 +02:00
< style >
body {
font-family: Helvetica;
2016-09-21 13:54:42 +02:00
font-size: 18px;
2012-10-21 02:40:52 +02:00
}
2014-04-20 10:26:00 +02:00
#current-slide,
2014-04-22 14:14:21 +02:00
#upcoming-slide,
2014-04-20 10:26:00 +02:00
#speaker-controls {
padding: 6px;
box-sizing: border-box;
-moz-box-sizing: border-box;
2012-10-21 02:40:52 +02:00
}
2014-04-20 10:26:00 +02:00
#current-slide iframe,
2014-04-22 14:14:21 +02:00
#upcoming-slide iframe {
2014-04-20 10:26:00 +02:00
width: 100%;
height: 100%;
border: 1px solid #ddd;
2012-10-21 02:40:52 +02:00
}
2014-04-20 10:26:00 +02:00
#current-slide .label,
2014-04-22 14:14:21 +02:00
#upcoming-slide .label {
2014-04-20 10:26:00 +02:00
position: absolute;
top: 10px;
left: 10px;
z-index: 2;
2016-09-21 13:54:42 +02:00
}
2018-04-24 14:23:28 +02:00
#connection-status {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 20;
padding: 30% 20% 20% 20%;
font-size: 18px;
color: #222;
background: #fff;
text-align: center;
box-sizing: border-box;
line-height: 1.4;
}
2016-09-21 13:54:42 +02:00
.overlay-element {
height: 34px;
line-height: 34px;
padding: 0 10px;
text-shadow: none;
background: rgba( 220, 220, 220, 0.8 );
color: #222;
font-size: 14px;
}
.overlay-element.interactive:hover {
background: rgba( 220, 220, 220, 1 );
2012-10-21 02:40:52 +02:00
}
2014-04-20 10:26:00 +02:00
#current-slide {
position: absolute;
2016-09-21 13:54:42 +02:00
width: 60%;
height: 100%;
2014-04-20 10:26:00 +02:00
top: 0;
left: 0;
padding-right: 0;
2012-10-21 02:40:52 +02:00
}
2014-04-22 14:14:21 +02:00
#upcoming-slide {
2014-04-20 10:26:00 +02:00
position: absolute;
2016-09-21 13:54:42 +02:00
width: 40%;
height: 40%;
2014-04-20 10:26:00 +02:00
right: 0;
top: 0;
2012-10-21 02:40:52 +02:00
}
2016-09-21 13:54:42 +02:00
/* Speaker controls */
2014-04-20 10:26:00 +02:00
#speaker-controls {
2012-10-21 02:40:52 +02:00
position: absolute;
2016-09-21 13:54:42 +02:00
top: 40%;
right: 0;
width: 40%;
height: 60%;
2014-10-16 13:09:54 +02:00
overflow: auto;
2014-04-20 10:26:00 +02:00
font-size: 18px;
2013-01-23 17:04:04 +01:00
}
2014-04-20 10:26:00 +02:00
.speaker-controls-time.hidden,
.speaker-controls-notes.hidden {
display: none;
}
.speaker-controls-time .label,
2016-04-16 16:43:44 +02:00
.speaker-controls-pace .label,
2014-04-20 10:26:00 +02:00
.speaker-controls-notes .label {
text-transform: uppercase;
font-weight: normal;
font-size: 0.66em;
color: #666;
margin: 0;
}
2016-04-16 16:43:44 +02:00
.speaker-controls-time, .speaker-controls-pace {
2014-04-20 10:26:00 +02:00
border-bottom: 1px solid rgba( 200, 200, 200, 0.5 );
margin-bottom: 10px;
padding: 10px 16px;
padding-bottom: 20px;
2014-05-04 08:13:03 +02:00
cursor: pointer;
}
.speaker-controls-time .reset-button {
opacity: 0;
float: right;
color: #666;
text-decoration: none;
}
.speaker-controls-time:hover .reset-button {
opacity: 1;
2014-04-20 10:26:00 +02:00
}
.speaker-controls-time .timer,
.speaker-controls-time .clock {
width: 50%;
2016-04-16 16:43:44 +02:00
}
.speaker-controls-time .timer,
.speaker-controls-time .clock,
.speaker-controls-time .pacing .hours-value,
.speaker-controls-time .pacing .minutes-value,
.speaker-controls-time .pacing .seconds-value {
2014-04-20 10:26:00 +02:00
font-size: 1.9em;
}
.speaker-controls-time .timer {
float: left;
}
2013-01-26 19:32:07 +01:00
2014-04-20 10:26:00 +02:00
.speaker-controls-time .clock {
float: right;
text-align: right;
}
.speaker-controls-time span.mute {
2016-04-16 18:10:58 +02:00
opacity: 0.3;
2014-04-20 10:26:00 +02:00
}
2017-04-21 09:35:51 +02:00
.speaker-controls-time .pacing-title {
margin-top: 5px;
}
2016-04-16 16:43:44 +02:00
.speaker-controls-time .pacing.ahead {
color: blue;
}
.speaker-controls-time .pacing.on-track {
color: green;
}
.speaker-controls-time .pacing.behind {
color: red;
}
2014-04-20 10:26:00 +02:00
.speaker-controls-notes {
padding: 10px 16px;
}
.speaker-controls-notes .value {
margin-top: 5px;
line-height: 1.4;
font-size: 1.2em;
}
2016-09-21 13:54:42 +02:00
/* Layout selector */
#speaker-layout {
position: absolute;
top: 10px;
right: 10px;
color: #222;
z-index: 10;
}
#speaker-layout select {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
border: 0;
box-shadow: 0;
cursor: pointer;
opacity: 0;
font-size: 1em;
background-color: transparent;
-moz-appearance: none;
-webkit-appearance: none;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
#speaker-layout select:focus {
outline: none;
box-shadow: none;
}
2014-04-20 10:26:00 +02:00
.clear {
clear: both;
2013-01-26 17:49:19 +01:00
}
2013-01-26 19:32:07 +01:00
2016-09-21 13:54:42 +02:00
/* Speaker layout: Wide */
body[data-speaker-layout="wide"] #current-slide,
body[data-speaker-layout="wide"] #upcoming-slide {
width: 50%;
height: 45%;
padding: 6px;
}
body[data-speaker-layout="wide"] #current-slide {
top: 0;
left: 0;
}
body[data-speaker-layout="wide"] #upcoming-slide {
top: 0;
left: 50%;
}
body[data-speaker-layout="wide"] #speaker-controls {
top: 45%;
left: 0;
width: 100%;
height: 50%;
font-size: 1.25em;
}
/* Speaker layout: Tall */
body[data-speaker-layout="tall"] #current-slide,
body[data-speaker-layout="tall"] #upcoming-slide {
width: 45%;
height: 50%;
padding: 6px;
}
body[data-speaker-layout="tall"] #current-slide {
top: 0;
left: 0;
}
body[data-speaker-layout="tall"] #upcoming-slide {
top: 50%;
left: 0;
}
body[data-speaker-layout="tall"] #speaker-controls {
padding-top: 40px;
top: 0;
left: 45%;
width: 55%;
height: 100%;
font-size: 1.25em;
}
/* Speaker layout: Notes only */
body[data-speaker-layout="notes-only"] #current-slide,
body[data-speaker-layout="notes-only"] #upcoming-slide {
display: none;
}
body[data-speaker-layout="notes-only"] #speaker-controls {
padding-top: 40px;
top: 0;
left: 0;
width: 100%;
height: 100%;
font-size: 1.25em;
}
2014-04-20 10:26:00 +02:00
@media screen and (max-width: 1080px) {
2016-09-21 13:54:42 +02:00
body[data-speaker-layout="default"] #speaker-controls {
2014-04-20 10:26:00 +02:00
font-size: 16px;
}
2013-01-26 17:49:19 +01:00
}
2013-01-26 19:32:07 +01:00
2014-04-20 10:26:00 +02:00
@media screen and (max-width: 900px) {
2016-09-21 13:54:42 +02:00
body[data-speaker-layout="default"] #speaker-controls {
2014-04-20 10:26:00 +02:00
font-size: 14px;
}
2013-01-26 17:49:19 +01:00
}
2013-01-26 19:32:07 +01:00
2014-04-20 10:26:00 +02:00
@media screen and (max-width: 800px) {
2016-09-21 13:54:42 +02:00
body[data-speaker-layout="default"] #speaker-controls {
2014-04-20 10:26:00 +02:00
font-size: 12px;
}
2013-01-26 17:49:19 +01:00
}
2012-10-21 02:40:52 +02:00
< / style >
< / head >
< body >
2018-04-24 14:23:28 +02:00
< div id = "connection-status" > Loading speaker view...< / div >
2014-04-20 10:26:00 +02:00
< div id = "current-slide" > < / div >
2016-09-21 13:54:42 +02:00
< div id = "upcoming-slide" > < span class = "overlay-element label" > Upcoming< / span > < / div >
2014-04-20 10:26:00 +02:00
< div id = "speaker-controls" >
< div class = "speaker-controls-time" >
2014-05-04 08:13:03 +02:00
< h4 class = "label" > Time < span class = "reset-button" > Click to Reset< / span > < / h4 >
2014-04-20 10:26:00 +02:00
< div class = "clock" >
< span class = "clock-value" > 0:00 AM< / span >
< / div >
< div class = "timer" >
< span class = "hours-value" > 00< / span > < span class = "minutes-value" > :00< / span > < span class = "seconds-value" > :00< / span >
< / div >
< div class = "clear" > < / div >
2016-04-16 16:43:44 +02:00
2017-04-21 09:35:51 +02:00
< h4 class = "label pacing-title" style = "display: none" > Pacing – Time to finish current slide< / h4 >
2016-04-16 16:43:44 +02:00
< div class = "pacing" style = "display: none" >
< span class = "hours-value" > 00< / span > < span class = "minutes-value" > :00< / span > < span class = "seconds-value" > :00< / span >
< / div >
2013-01-26 17:49:19 +01:00
< / div >
2014-04-20 10:26:00 +02:00
< div class = "speaker-controls-notes hidden" >
< h4 class = "label" > Notes< / h4 >
< div class = "value" > < / div >
2013-01-26 17:49:19 +01:00
< / div >
< / div >
2016-09-21 13:54:42 +02:00
< div id = "speaker-layout" class = "overlay-element interactive" >
< span class = "speaker-layout-label" > < / span >
< select class = "speaker-layout-dropdown" > < / select >
< / div >
2013-01-26 19:32:07 +01:00
2012-10-21 02:40:52 +02:00
< script >
2013-01-26 19:32:07 +01:00
2014-04-19 10:54:14 +02:00
(function() {
var notes,
2014-04-20 10:26:00 +02:00
notesValue,
2014-04-19 10:54:14 +02:00
currentState,
currentSlide,
2014-04-22 14:14:21 +02:00
upcomingSlide,
2016-09-21 13:54:42 +02:00
layoutLabel,
layoutDropdown,
2018-02-18 21:30:17 +01:00
pendingCalls = {},
lastRevealApiCallId = 0,
2014-04-19 10:54:14 +02:00
connected = false;
2016-09-21 13:54:42 +02:00
var SPEAKER_LAYOUTS = {
'default': 'Default',
'wide': 'Wide',
'tall': 'Tall',
'notes-only': 'Notes only'
};
setupLayout();
2018-04-24 14:23:28 +02:00
var connectionStatus = document.querySelector( '#connection-status' );
var connectionTimeout = setTimeout( function() {
connectionStatus.innerHTML = 'Error connecting to main window.< br > Please try closing and reopening the speaker view.';
}, 5000 );
2014-04-19 10:54:14 +02:00
window.addEventListener( 'message', function( event ) {
2018-04-24 14:23:28 +02:00
clearTimeout( connectionTimeout );
connectionStatus.style.display = 'none';
2014-04-19 10:54:14 +02:00
var data = JSON.parse( event.data );
2016-03-09 09:57:58 +01:00
// The overview mode is only useful to the reveal.js instance
// where navigation occurs so we don't sync it
if( data.state ) delete data.state.overview;
2014-04-19 10:54:14 +02:00
// Messages sent by the notes plugin inside of the main window
if( data & & data.namespace === 'reveal-notes' ) {
if( data.type === 'connect' ) {
handleConnectMessage( data );
}
else if( data.type === 'state' ) {
handleStateMessage( data );
}
2018-02-18 21:30:17 +01:00
else if( data.type === 'return' ) {
pendingCalls[data.callId](data.result);
delete pendingCalls[data.callId];
}
2014-04-19 10:54:14 +02:00
}
// Messages sent by the reveal.js inside of the current slide preview
else if( data & & data.namespace === 'reveal' ) {
if( /ready/.test( data.eventName ) ) {
// Send a message back to notify that the handshake is complete
window.opener.postMessage( JSON.stringify({ namespace: 'reveal-notes', type: 'connected'} ), '*' );
}
2016-03-09 09:57:58 +01:00
else if( /slidechanged|fragmentshown|fragmenthidden|paused|resumed/.test( data.eventName ) & & currentState !== JSON.stringify( data.state ) ) {
2014-04-19 10:54:14 +02:00
window.opener.postMessage( JSON.stringify({ method: 'setState', args: [ data.state ]} ), '*' );
2016-03-09 09:57:58 +01:00
2014-04-19 10:54:14 +02:00
}
}
} );
2018-02-20 10:30:56 +01:00
/**
* Asynchronously calls the Reveal.js API of the main frame.
*/
2018-02-18 21:30:17 +01:00
function callRevealApi( methodName, methodArguments, callback ) {
2018-10-04 13:26:16 +02:00
2018-02-18 21:30:17 +01:00
var callId = ++lastRevealApiCallId;
pendingCalls[callId] = callback;
window.opener.postMessage( JSON.stringify( {
namespace: 'reveal-notes',
type: 'call',
callId: callId,
methodName: methodName,
arguments: methodArguments
} ), '*' );
2018-10-04 13:26:16 +02:00
2018-02-18 21:30:17 +01:00
}
2014-04-19 10:54:14 +02:00
/**
* Called when the main window is trying to establish a
* connection.
*/
function handleConnectMessage( data ) {
if( connected === false ) {
connected = true;
setupIframes( data );
2014-04-26 11:35:55 +02:00
setupKeyboard();
2014-04-20 10:26:00 +02:00
setupNotes();
2014-04-19 10:54:14 +02:00
setupTimer();
}
2012-10-21 02:40:52 +02:00
2014-04-19 10:54:14 +02:00
}
2013-01-23 17:04:04 +01:00
2014-04-19 10:54:14 +02:00
/**
* Called when the main window sends an updated state.
*/
function handleStateMessage( data ) {
2013-01-23 17:04:04 +01:00
2014-04-19 10:54:14 +02:00
// Store the most recently set state to avoid circular loops
// applying the same state
currentState = JSON.stringify( data.state );
2013-07-26 15:48:21 +02:00
2014-04-19 10:54:14 +02:00
// No need for updating the notes in case of fragment changes
2014-04-20 10:26:00 +02:00
if ( data.notes ) {
notes.classList.remove( 'hidden' );
2015-09-25 09:41:05 +02:00
notesValue.style.whiteSpace = data.whitespace;
2014-04-19 10:54:14 +02:00
if( data.markdown ) {
2014-04-20 10:26:00 +02:00
notesValue.innerHTML = marked( data.notes );
2014-04-19 10:54:14 +02:00
}
else {
2014-04-20 10:26:00 +02:00
notesValue.innerHTML = data.notes;
2013-01-26 19:32:07 +01:00
}
2014-04-19 10:54:14 +02:00
}
2014-04-20 10:26:00 +02:00
else {
notes.classList.add( 'hidden' );
}
2014-04-19 10:54:14 +02:00
// Update the note slides
currentSlide.contentWindow.postMessage( JSON.stringify({ method: 'setState', args: [ data.state ] }), '*' );
2014-04-22 14:14:21 +02:00
upcomingSlide.contentWindow.postMessage( JSON.stringify({ method: 'setState', args: [ data.state ] }), '*' );
upcomingSlide.contentWindow.postMessage( JSON.stringify({ method: 'next' }), '*' );
2013-01-26 19:32:07 +01:00
2014-04-19 10:54:14 +02:00
}
2013-07-26 16:03:59 +02:00
2014-04-22 14:50:50 +02:00
// Limit to max one state update per X ms
handleStateMessage = debounce( handleStateMessage, 200 );
2014-04-26 11:35:55 +02:00
/**
* Forward keyboard events to the current slide window.
* This enables keyboard events to work even if focus
* isn't set on the current slide iframe.
2017-08-12 13:38:46 +02:00
*
* Block F5 default handling, it reloads and disconnects
* the speaker notes window.
2014-04-26 11:35:55 +02:00
*/
function setupKeyboard() {
document.addEventListener( 'keydown', function( event ) {
2017-12-04 13:57:19 +01:00
if( event.keyCode === 116 || ( event.metaKey & & event.keyCode === 82 ) ) {
2017-08-12 13:38:46 +02:00
event.preventDefault();
2017-12-04 13:57:19 +01:00
return false;
2017-08-12 13:38:46 +02:00
}
2014-04-26 11:35:55 +02:00
currentSlide.contentWindow.postMessage( JSON.stringify({ method: 'triggerKey', args: [ event.keyCode ] }), '*' );
} );
}
2014-04-19 10:54:14 +02:00
/**
* Creates the preview iframes.
*/
function setupIframes( data ) {
2013-01-26 19:32:07 +01:00
2014-04-22 15:05:06 +02:00
var params = [
2014-04-22 14:06:58 +02:00
'receiver',
'progress=false',
2014-04-22 14:14:21 +02:00
'history=false',
'transition=none',
2014-09-28 17:13:49 +02:00
'autoSlide=0',
2014-04-22 14:14:21 +02:00
'backgroundTransition=none'
].join( '& ' );
2014-04-22 14:06:58 +02:00
2016-03-09 09:37:10 +01:00
var urlSeparator = /\?/.test(data.url) ? '& ' : '?';
2014-04-19 10:54:14 +02:00
var hash = '#/' + data.state.indexh + '/' + data.state.indexv;
2016-03-06 11:28:08 +01:00
var currentURL = data.url + urlSeparator + params + '& postMessageEvents=true' + hash;
var upcomingURL = data.url + urlSeparator + params + '& controls=false' + hash;
2014-04-19 10:54:14 +02:00
currentSlide = document.createElement( 'iframe' );
currentSlide.setAttribute( 'width', 1280 );
currentSlide.setAttribute( 'height', 1024 );
2014-04-22 14:14:21 +02:00
currentSlide.setAttribute( 'src', currentURL );
2014-04-20 10:26:00 +02:00
document.querySelector( '#current-slide' ).appendChild( currentSlide );
2014-04-19 10:54:14 +02:00
2014-04-22 14:14:21 +02:00
upcomingSlide = document.createElement( 'iframe' );
upcomingSlide.setAttribute( 'width', 640 );
upcomingSlide.setAttribute( 'height', 512 );
upcomingSlide.setAttribute( 'src', upcomingURL );
document.querySelector( '#upcoming-slide' ).appendChild( upcomingSlide );
2014-04-20 10:26:00 +02:00
}
/**
* Setup the notes UI.
*/
function setupNotes() {
notes = document.querySelector( '.speaker-controls-notes' );
notesValue = document.querySelector( '.speaker-controls-notes .value' );
2014-04-19 10:54:14 +02:00
}
2013-07-26 16:03:59 +02:00
2018-02-18 21:30:17 +01:00
function getTimings( callback ) {
2016-04-16 16:43:44 +02:00
2018-10-04 13:26:16 +02:00
callRevealApi( 'getSlidesAttributes', [], function ( slideAttributes ) {
2018-02-18 21:30:17 +01:00
callRevealApi( 'getConfig', [], function ( config ) {
Notes: Introduce alternate pacing timer, based on total presentation time
The current pacing timer operates on the assumption that there is
a default amount of time to be allocated to each slide, and that
individual slides can deviate from that default by specifying their
own data-timing attribute.
This patch introduces an alternate pacing method: by specifying
the totalTime configuration option, the presenter can set the total
time available to present. The pacing timer will then continue to
allocate the exact pacing time for slides that do have data-timing
set, as before. However, rather than applying the defaultTiming
constant to all others, it will
- Add up the time already allocated to slides via data-timing;
- subtract that from totalTime;
- divide the difference by the number of slides without data-timing set;
- apply the thus-calculated average to those slides.
totalTime has no default, and if both defaultTiming and totalTime are
set, totalTime wins. This preserves backward compatibility: if a
presenter has set defaultTiming and updates reveal.js, totalTime will
be null and defaultTiming is still applied to all slides without a
data-timing attribute. The presenter can then switch to the automatic
calculation, if desired, by setting a value for totalTime.
2019-05-10 00:03:30 +02:00
var totalTime = config.totalTime;
2019-05-11 22:23:28 +02:00
var minTimePerSlide = config.minimumTimePerSlide || 0;
2018-02-18 21:30:17 +01:00
var defaultTiming = config.defaultTiming;
Notes: Introduce alternate pacing timer, based on total presentation time
The current pacing timer operates on the assumption that there is
a default amount of time to be allocated to each slide, and that
individual slides can deviate from that default by specifying their
own data-timing attribute.
This patch introduces an alternate pacing method: by specifying
the totalTime configuration option, the presenter can set the total
time available to present. The pacing timer will then continue to
allocate the exact pacing time for slides that do have data-timing
set, as before. However, rather than applying the defaultTiming
constant to all others, it will
- Add up the time already allocated to slides via data-timing;
- subtract that from totalTime;
- divide the difference by the number of slides without data-timing set;
- apply the thus-calculated average to those slides.
totalTime has no default, and if both defaultTiming and totalTime are
set, totalTime wins. This preserves backward compatibility: if a
presenter has set defaultTiming and updates reveal.js, totalTime will
be null and defaultTiming is still applied to all slides without a
data-timing attribute. The presenter can then switch to the automatic
calculation, if desired, by setting a value for totalTime.
2019-05-10 00:03:30 +02:00
if ((defaultTiming == null) & & (totalTime == null)) {
2018-02-18 21:30:17 +01:00
callback(null);
return;
2016-04-16 16:43:44 +02:00
}
Notes: Introduce alternate pacing timer, based on total presentation time
The current pacing timer operates on the assumption that there is
a default amount of time to be allocated to each slide, and that
individual slides can deviate from that default by specifying their
own data-timing attribute.
This patch introduces an alternate pacing method: by specifying
the totalTime configuration option, the presenter can set the total
time available to present. The pacing timer will then continue to
allocate the exact pacing time for slides that do have data-timing
set, as before. However, rather than applying the defaultTiming
constant to all others, it will
- Add up the time already allocated to slides via data-timing;
- subtract that from totalTime;
- divide the difference by the number of slides without data-timing set;
- apply the thus-calculated average to those slides.
totalTime has no default, and if both defaultTiming and totalTime are
set, totalTime wins. This preserves backward compatibility: if a
presenter has set defaultTiming and updates reveal.js, totalTime will
be null and defaultTiming is still applied to all slides without a
data-timing attribute. The presenter can then switch to the automatic
calculation, if desired, by setting a value for totalTime.
2019-05-10 00:03:30 +02:00
// Setting totalTime overrides defaultTiming
if (totalTime) {
defaultTiming = 0;
}
2018-02-18 21:30:17 +01:00
var timings = [];
2018-10-04 13:26:16 +02:00
for ( var i in slideAttributes ) {
var slide = slideAttributes[ i ];
2018-02-18 21:30:17 +01:00
var timing = defaultTiming;
if( slide.hasOwnProperty( 'data-timing' )) {
var t = slide[ 'data-timing' ];
timing = parseInt(t);
if( isNaN(timing) ) {
console.warn("Could not parse timing '" + t + "' of slide " + i + "; using default of " + defaultTiming);
timing = defaultTiming;
}
}
timings.push(timing);
2016-04-16 16:43:44 +02:00
}
Notes: Introduce alternate pacing timer, based on total presentation time
The current pacing timer operates on the assumption that there is
a default amount of time to be allocated to each slide, and that
individual slides can deviate from that default by specifying their
own data-timing attribute.
This patch introduces an alternate pacing method: by specifying
the totalTime configuration option, the presenter can set the total
time available to present. The pacing timer will then continue to
allocate the exact pacing time for slides that do have data-timing
set, as before. However, rather than applying the defaultTiming
constant to all others, it will
- Add up the time already allocated to slides via data-timing;
- subtract that from totalTime;
- divide the difference by the number of slides without data-timing set;
- apply the thus-calculated average to those slides.
totalTime has no default, and if both defaultTiming and totalTime are
set, totalTime wins. This preserves backward compatibility: if a
presenter has set defaultTiming and updates reveal.js, totalTime will
be null and defaultTiming is still applied to all slides without a
data-timing attribute. The presenter can then switch to the automatic
calculation, if desired, by setting a value for totalTime.
2019-05-10 00:03:30 +02:00
if ( totalTime ) {
// After we've allocated time to individual slides, we summarize it and
// subtract it from the total time
var remainingTime = totalTime - timings.reduce( function(a, b) { return a + b; }, 0 );
// The remaining time is divided by the number of slides that have 0 seconds
// allocated at the moment, giving the average time-per-slide on the remaining slides
var remainingSlides = (timings.filter( function(x) { return x == 0 }) ).length
var timePerSlide = Math.round( remainingTime / remainingSlides, 0 )
// And now we replace every zero-value timing with that average
timings = timings.map( function(x) { return (x==0 ? timePerSlide : x) } );
}
2019-05-11 22:23:28 +02:00
var slidesUnderMinimum = timings.filter( function(x) { return (x < minTimePerSlide ) } ) . length
if ( slidesUnderMinimum ) {
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).";
alert(message);
}
2018-02-18 21:30:17 +01:00
callback( timings );
} );
} );
2016-04-16 16:43:44 +02:00
}
/**
* Return the number of seconds allocated for presenting
* all slides up to and including this one.
*/
2018-02-18 21:30:17 +01:00
function getTimeAllocated( timings, callback ) {
2016-04-16 16:43:44 +02:00
2018-02-18 21:30:17 +01:00
callRevealApi( 'getSlidePastCount', [], function ( currentSlide ) {
var allocated = 0;
for (var i in timings.slice(0, currentSlide + 1)) {
allocated += timings[i];
}
callback( allocated );
} );
2016-04-16 16:43:44 +02:00
}
2014-04-19 10:54:14 +02:00
/**
* Create the timer and clock and start updating them
* at an interval.
*/
function setupTimer() {
2013-01-26 19:32:07 +01:00
var start = new Date(),
2016-04-16 16:43:44 +02:00
timeEl = document.querySelector( '.speaker-controls-time' ),
clockEl = timeEl.querySelector( '.clock-value' ),
hoursEl = timeEl.querySelector( '.hours-value' ),
minutesEl = timeEl.querySelector( '.minutes-value' ),
secondsEl = timeEl.querySelector( '.seconds-value' ),
pacingTitleEl = timeEl.querySelector( '.pacing-title' ),
pacingEl = timeEl.querySelector( '.pacing' ),
pacingHoursEl = pacingEl.querySelector( '.hours-value' ),
pacingMinutesEl = pacingEl.querySelector( '.minutes-value' ),
pacingSecondsEl = pacingEl.querySelector( '.seconds-value' );
2018-02-18 21:30:17 +01:00
var timings = null;
getTimings( function ( _timings ) {
timings = _timings;
if (_timings !== null) {
pacingTitleEl.style.removeProperty('display');
pacingEl.style.removeProperty('display');
}
// Update once directly
_updateTimer();
// Then update every second
setInterval( _updateTimer, 1000 );
} );
function _resetTimer() {
if (timings == null) {
start = new Date();
_updateTimer();
}
else {
// Reset timer to beginning of current slide
getTimeAllocated( timings, function ( slideEndTimingSeconds ) {
var slideEndTiming = slideEndTimingSeconds * 1000;
callRevealApi( 'getSlidePastCount', [], function ( currentSlide ) {
var currentSlideTiming = timings[currentSlide] * 1000;
var previousSlidesTiming = slideEndTiming - currentSlideTiming;
var now = new Date();
start = new Date(now.getTime() - previousSlidesTiming);
_updateTimer();
} );
} );
}
2016-04-16 16:43:44 +02:00
}
2013-01-26 19:32:07 +01:00
2018-02-18 21:30:17 +01:00
timeEl.addEventListener( 'click', function() {
_resetTimer();
return false;
} );
2016-04-16 17:52:34 +02:00
function _displayTime( hrEl, minEl, secEl, time) {
2016-04-16 16:43:44 +02:00
2016-04-16 19:00:27 +02:00
var sign = Math.sign(time) == -1 ? "-" : "";
time = Math.abs(Math.round(time / 1000));
2016-04-16 19:11:48 +02:00
var seconds = time % 60;
2016-04-16 16:43:44 +02:00
var minutes = Math.floor( time / 60 ) % 60 ;
var hours = Math.floor( time / ( 60 * 60 )) ;
2016-04-16 19:00:27 +02:00
hrEl.innerHTML = sign + zeroPadInteger( hours );
2016-04-16 18:40:21 +02:00
if (hours == 0) {
hrEl.classList.add( 'mute' );
}
else {
hrEl.classList.remove( 'mute' );
}
2016-04-16 17:52:34 +02:00
minEl.innerHTML = ':' + zeroPadInteger( minutes );
2016-04-16 18:40:21 +02:00
if (hours == 0 & & minutes == 0) {
minEl.classList.add( 'mute' );
}
else {
minEl.classList.remove( 'mute' );
}
2016-04-16 17:52:34 +02:00
secEl.innerHTML = ':' + zeroPadInteger( seconds );
}
2014-04-20 10:26:00 +02:00
function _updateTimer() {
2013-01-26 19:32:07 +01:00
var diff, hours, minutes, seconds,
2016-04-16 16:43:44 +02:00
now = new Date();
2013-01-26 19:32:07 +01:00
diff = now.getTime() - start.getTime();
2014-04-20 10:26:00 +02:00
clockEl.innerHTML = now.toLocaleTimeString( 'en-US', { hour12: true, hour: '2-digit', minute:'2-digit' } );
2016-04-16 17:52:34 +02:00
_displayTime( hoursEl, minutesEl, secondsEl, diff );
2016-04-16 16:43:44 +02:00
if (timings !== null) {
_updatePacing(diff);
}
}
function _updatePacing(diff) {
2018-02-18 21:30:17 +01:00
getTimeAllocated( timings, function ( slideEndTimingSeconds ) {
var slideEndTiming = slideEndTimingSeconds * 1000;
callRevealApi( 'getSlidePastCount', [], function ( currentSlide ) {
var currentSlideTiming = timings[currentSlide] * 1000;
var timeLeftCurrentSlide = slideEndTiming - diff;
if (timeLeftCurrentSlide < 0 ) {
pacingEl.className = 'pacing behind';
}
else if (timeLeftCurrentSlide < currentSlideTiming ) {
pacingEl.className = 'pacing on-track';
}
else {
pacingEl.className = 'pacing ahead';
}
_displayTime( pacingHoursEl, pacingMinutesEl, pacingSecondsEl, timeLeftCurrentSlide );
} );
} );
2014-04-20 10:26:00 +02:00
}
2013-01-23 17:04:04 +01:00
}
2016-09-21 13:54:42 +02:00
/**
* Sets up the speaker view layout and layout selector.
*/
function setupLayout() {
layoutDropdown = document.querySelector( '.speaker-layout-dropdown' );
layoutLabel = document.querySelector( '.speaker-layout-label' );
// Render the list of available layouts
for( var id in SPEAKER_LAYOUTS ) {
var option = document.createElement( 'option' );
option.setAttribute( 'value', id );
option.textContent = SPEAKER_LAYOUTS[ id ];
layoutDropdown.appendChild( option );
}
// Monitor the dropdown for changes
layoutDropdown.addEventListener( 'change', function( event ) {
setLayout( layoutDropdown.value );
}, false );
// Restore any currently persisted layout
setLayout( getLayout() );
}
/**
* Sets a new speaker view layout. The layout is persisted
* in local storage.
*/
function setLayout( value ) {
var title = SPEAKER_LAYOUTS[ value ];
layoutLabel.innerHTML = 'Layout' + ( title ? ( ': ' + title ) : '' );
layoutDropdown.value = value;
document.body.setAttribute( 'data-speaker-layout', value );
// Persist locally
2017-07-13 20:19:16 +02:00
if( supportsLocalStorage() ) {
2016-09-21 13:54:42 +02:00
window.localStorage.setItem( 'reveal-speaker-layout', value );
}
}
2016-09-21 14:10:14 +02:00
/**
* Returns the ID of the most recently set speaker layout
* or our default layout if none has been set.
*/
2016-09-21 13:54:42 +02:00
function getLayout() {
2017-07-13 20:19:16 +02:00
if( supportsLocalStorage() ) {
2016-09-21 13:54:42 +02:00
var layout = window.localStorage.getItem( 'reveal-speaker-layout' );
if( layout ) {
return layout;
}
}
// Default to the first record in the layouts hash
for( var id in SPEAKER_LAYOUTS ) {
return id;
}
}
2017-07-13 20:19:16 +02:00
function supportsLocalStorage() {
try {
localStorage.setItem('test', 'test');
localStorage.removeItem('test');
return true;
}
catch( e ) {
return false;
}
}
2014-04-19 10:54:14 +02:00
function zeroPadInteger( num ) {
2012-10-21 02:40:52 +02:00
2014-04-19 10:54:14 +02:00
var str = '00' + parseInt( num );
return str.substring( str.length - 2 );
2013-01-26 17:49:19 +01:00
2014-04-19 10:54:14 +02:00
}
2012-10-21 02:40:52 +02:00
2014-04-22 14:50:50 +02:00
/**
* Limits the frequency at which a function can be called.
*/
function debounce( fn, ms ) {
var lastTime = 0,
timeout;
return function() {
var args = arguments;
var context = this;
clearTimeout( timeout );
var timeSinceLastCall = Date.now() - lastTime;
if( timeSinceLastCall > ms ) {
fn.apply( context, args );
lastTime = Date.now();
}
else {
timeout = setTimeout( function() {
fn.apply( context, args );
lastTime = Date.now();
}, ms - timeSinceLastCall );
}
}
}
2014-04-19 10:54:14 +02:00
})();
2013-01-26 19:32:07 +01:00
2012-10-21 02:40:52 +02:00
< / script >
< / body >
2020-05-18 15:59:18 +02:00
< / html >