CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

| Download
Project: KOB1
Views: 16973
1
/*!
2
* reveal.js
3
* http://revealjs.com
4
* MIT licensed
5
*
6
* Copyright (C) 2017 Hakim El Hattab, http://hakim.se
7
*/
8
(function( root, factory ) {
9
if( typeof define === 'function' && define.amd ) {
10
// AMD. Register as an anonymous module.
11
define( function() {
12
root.Reveal = factory();
13
return root.Reveal;
14
} );
15
} else if( typeof exports === 'object' ) {
16
// Node. Does not work with strict CommonJS.
17
module.exports = factory();
18
} else {
19
// Browser globals.
20
root.Reveal = factory();
21
}
22
}( this, function() {
23
24
'use strict';
25
26
var Reveal;
27
28
// The reveal.js version
29
var VERSION = '3.6.0';
30
31
var SLIDES_SELECTOR = '.slides section',
32
HORIZONTAL_SLIDES_SELECTOR = '.slides>section',
33
VERTICAL_SLIDES_SELECTOR = '.slides>section.present>section',
34
HOME_SLIDE_SELECTOR = '.slides>section:first-of-type',
35
UA = navigator.userAgent,
36
37
// Configuration defaults, can be overridden at initialization time
38
config = {
39
40
// The "normal" size of the presentation, aspect ratio will be preserved
41
// when the presentation is scaled to fit different resolutions
42
width: 960,
43
height: 700,
44
45
// Factor of the display size that should remain empty around the content
46
margin: 0.04,
47
48
// Bounds for smallest/largest possible scale to apply to content
49
minScale: 0.2,
50
maxScale: 2.0,
51
52
// Display presentation control arrows
53
controls: true,
54
55
// Help the user learn the controls by providing hints, for example by
56
// bouncing the down arrow when they first encounter a vertical slide
57
controlsTutorial: true,
58
59
// Determines where controls appear, "edges" or "bottom-right"
60
controlsLayout: 'bottom-right',
61
62
// Visibility rule for backwards navigation arrows; "faded", "hidden"
63
// or "visible"
64
controlsBackArrows: 'faded',
65
66
// Display a presentation progress bar
67
progress: true,
68
69
// Display the page number of the current slide
70
slideNumber: false,
71
72
// Determine which displays to show the slide number on
73
showSlideNumber: 'all',
74
75
// Push each slide change to the browser history
76
history: false,
77
78
// Enable keyboard shortcuts for navigation
79
keyboard: true,
80
81
// Optional function that blocks keyboard events when retuning false
82
keyboardCondition: null,
83
84
// Enable the slide overview mode
85
overview: true,
86
87
// Vertical centering of slides
88
center: true,
89
90
// Enables touch navigation on devices with touch input
91
touch: true,
92
93
// Loop the presentation
94
loop: false,
95
96
// Change the presentation direction to be RTL
97
rtl: false,
98
99
// Randomizes the order of slides each time the presentation loads
100
shuffle: false,
101
102
// Turns fragments on and off globally
103
fragments: true,
104
105
// Flags if the presentation is running in an embedded mode,
106
// i.e. contained within a limited portion of the screen
107
embedded: false,
108
109
// Flags if we should show a help overlay when the question-mark
110
// key is pressed
111
help: true,
112
113
// Flags if it should be possible to pause the presentation (blackout)
114
pause: true,
115
116
// Flags if speaker notes should be visible to all viewers
117
showNotes: false,
118
119
// Global override for autolaying embedded media (video/audio/iframe)
120
// - null: Media will only autoplay if data-autoplay is present
121
// - true: All media will autoplay, regardless of individual setting
122
// - false: No media will autoplay, regardless of individual setting
123
autoPlayMedia: null,
124
125
// Controls automatic progression to the next slide
126
// - 0: Auto-sliding only happens if the data-autoslide HTML attribute
127
// is present on the current slide or fragment
128
// - 1+: All slides will progress automatically at the given interval
129
// - false: No auto-sliding, even if data-autoslide is present
130
autoSlide: 0,
131
132
// Stop auto-sliding after user input
133
autoSlideStoppable: true,
134
135
// Use this method for navigation when auto-sliding (defaults to navigateNext)
136
autoSlideMethod: null,
137
138
// Enable slide navigation via mouse wheel
139
mouseWheel: false,
140
141
// Apply a 3D roll to links on hover
142
rollingLinks: false,
143
144
// Hides the address bar on mobile devices
145
hideAddressBar: true,
146
147
// Opens links in an iframe preview overlay
148
previewLinks: false,
149
150
// Exposes the reveal.js API through window.postMessage
151
postMessage: true,
152
153
// Dispatches all reveal.js events to the parent window through postMessage
154
postMessageEvents: false,
155
156
// Focuses body when page changes visibility to ensure keyboard shortcuts work
157
focusBodyOnPageVisibilityChange: true,
158
159
// Transition style
160
transition: 'slide', // none/fade/slide/convex/concave/zoom
161
162
// Transition speed
163
transitionSpeed: 'default', // default/fast/slow
164
165
// Transition style for full page slide backgrounds
166
backgroundTransition: 'fade', // none/fade/slide/convex/concave/zoom
167
168
// Parallax background image
169
parallaxBackgroundImage: '', // CSS syntax, e.g. "a.jpg"
170
171
// Parallax background size
172
parallaxBackgroundSize: '', // CSS syntax, e.g. "3000px 2000px"
173
174
// Amount of pixels to move the parallax background per slide step
175
parallaxBackgroundHorizontal: null,
176
parallaxBackgroundVertical: null,
177
178
// The maximum number of pages a single slide can expand onto when printing
179
// to PDF, unlimited by default
180
pdfMaxPagesPerSlide: Number.POSITIVE_INFINITY,
181
182
// Offset used to reduce the height of content within exported PDF pages.
183
// This exists to account for environment differences based on how you
184
// print to PDF. CLI printing options, like phantomjs and wkpdf, can end
185
// on precisely the total height of the document whereas in-browser
186
// printing has to end one pixel before.
187
pdfPageHeightOffset: -1,
188
189
// Number of slides away from the current that are visible
190
viewDistance: 3,
191
192
// The display mode that will be used to show slides
193
display: 'block',
194
195
// Script dependencies to load
196
dependencies: []
197
198
},
199
200
// Flags if Reveal.initialize() has been called
201
initialized = false,
202
203
// Flags if reveal.js is loaded (has dispatched the 'ready' event)
204
loaded = false,
205
206
// Flags if the overview mode is currently active
207
overview = false,
208
209
// Holds the dimensions of our overview slides, including margins
210
overviewSlideWidth = null,
211
overviewSlideHeight = null,
212
213
// The horizontal and vertical index of the currently active slide
214
indexh,
215
indexv,
216
217
// The previous and current slide HTML elements
218
previousSlide,
219
currentSlide,
220
221
previousBackground,
222
223
// Remember which directions that the user has navigated towards
224
hasNavigatedRight = false,
225
hasNavigatedDown = false,
226
227
// Slides may hold a data-state attribute which we pick up and apply
228
// as a class to the body. This list contains the combined state of
229
// all current slides.
230
state = [],
231
232
// The current scale of the presentation (see width/height config)
233
scale = 1,
234
235
// CSS transform that is currently applied to the slides container,
236
// split into two groups
237
slidesTransform = { layout: '', overview: '' },
238
239
// Cached references to DOM elements
240
dom = {},
241
242
// Features supported by the browser, see #checkCapabilities()
243
features = {},
244
245
// Client is a mobile device, see #checkCapabilities()
246
isMobileDevice,
247
248
// Client is a desktop Chrome, see #checkCapabilities()
249
isChrome,
250
251
// Throttles mouse wheel navigation
252
lastMouseWheelStep = 0,
253
254
// Delays updates to the URL due to a Chrome thumbnailer bug
255
writeURLTimeout = 0,
256
257
// Flags if the interaction event listeners are bound
258
eventsAreBound = false,
259
260
// The current auto-slide duration
261
autoSlide = 0,
262
263
// Auto slide properties
264
autoSlidePlayer,
265
autoSlideTimeout = 0,
266
autoSlideStartTime = -1,
267
autoSlidePaused = false,
268
269
// Holds information about the currently ongoing touch input
270
touch = {
271
startX: 0,
272
startY: 0,
273
startSpan: 0,
274
startCount: 0,
275
captured: false,
276
threshold: 40
277
},
278
279
// Holds information about the keyboard shortcuts
280
keyboardShortcuts = {
281
'N , SPACE': 'Next slide',
282
'P': 'Previous slide',
283
'← , H': 'Navigate left',
284
'→ , L': 'Navigate right',
285
'↑ , K': 'Navigate up',
286
'↓ , J': 'Navigate down',
287
'Home': 'First slide',
288
'End': 'Last slide',
289
'B , .': 'Pause',
290
'F': 'Fullscreen',
291
'ESC, O': 'Slide overview'
292
};
293
294
/**
295
* Starts up the presentation if the client is capable.
296
*/
297
function initialize( options ) {
298
299
// Make sure we only initialize once
300
if( initialized === true ) return;
301
302
initialized = true;
303
304
checkCapabilities();
305
306
if( !features.transforms2d && !features.transforms3d ) {
307
document.body.setAttribute( 'class', 'no-transforms' );
308
309
// Since JS won't be running any further, we load all lazy
310
// loading elements upfront
311
var images = toArray( document.getElementsByTagName( 'img' ) ),
312
iframes = toArray( document.getElementsByTagName( 'iframe' ) );
313
314
var lazyLoadable = images.concat( iframes );
315
316
for( var i = 0, len = lazyLoadable.length; i < len; i++ ) {
317
var element = lazyLoadable[i];
318
if( element.getAttribute( 'data-src' ) ) {
319
element.setAttribute( 'src', element.getAttribute( 'data-src' ) );
320
element.removeAttribute( 'data-src' );
321
}
322
}
323
324
// If the browser doesn't support core features we won't be
325
// using JavaScript to control the presentation
326
return;
327
}
328
329
// Cache references to key DOM elements
330
dom.wrapper = document.querySelector( '.reveal' );
331
dom.slides = document.querySelector( '.reveal .slides' );
332
333
// Force a layout when the whole page, incl fonts, has loaded
334
window.addEventListener( 'load', layout, false );
335
336
var query = Reveal.getQueryHash();
337
338
// Do not accept new dependencies via query config to avoid
339
// the potential of malicious script injection
340
if( typeof query['dependencies'] !== 'undefined' ) delete query['dependencies'];
341
342
// Copy options over to our config object
343
extend( config, options );
344
extend( config, query );
345
346
// Hide the address bar in mobile browsers
347
hideAddressBar();
348
349
// Loads the dependencies and continues to #start() once done
350
load();
351
352
}
353
354
/**
355
* Inspect the client to see what it's capable of, this
356
* should only happens once per runtime.
357
*/
358
function checkCapabilities() {
359
360
isMobileDevice = /(iphone|ipod|ipad|android)/gi.test( UA );
361
isChrome = /chrome/i.test( UA ) && !/edge/i.test( UA );
362
363
var testElement = document.createElement( 'div' );
364
365
features.transforms3d = 'WebkitPerspective' in testElement.style ||
366
'MozPerspective' in testElement.style ||
367
'msPerspective' in testElement.style ||
368
'OPerspective' in testElement.style ||
369
'perspective' in testElement.style;
370
371
features.transforms2d = 'WebkitTransform' in testElement.style ||
372
'MozTransform' in testElement.style ||
373
'msTransform' in testElement.style ||
374
'OTransform' in testElement.style ||
375
'transform' in testElement.style;
376
377
features.requestAnimationFrameMethod = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame;
378
features.requestAnimationFrame = typeof features.requestAnimationFrameMethod === 'function';
379
380
features.canvas = !!document.createElement( 'canvas' ).getContext;
381
382
// Transitions in the overview are disabled in desktop and
383
// Safari due to lag
384
features.overviewTransitions = !/Version\/[\d\.]+.*Safari/.test( UA );
385
386
// Flags if we should use zoom instead of transform to scale
387
// up slides. Zoom produces crisper results but has a lot of
388
// xbrowser quirks so we only use it in whitelsited browsers.
389
features.zoom = 'zoom' in testElement.style && !isMobileDevice &&
390
( isChrome || /Version\/[\d\.]+.*Safari/.test( UA ) );
391
392
}
393
394
/**
395
* Loads the dependencies of reveal.js. Dependencies are
396
* defined via the configuration option 'dependencies'
397
* and will be loaded prior to starting/binding reveal.js.
398
* Some dependencies may have an 'async' flag, if so they
399
* will load after reveal.js has been started up.
400
*/
401
function load() {
402
403
var scripts = [],
404
scriptsAsync = [],
405
scriptsToPreload = 0;
406
407
// Called once synchronous scripts finish loading
408
function proceed() {
409
if( scriptsAsync.length ) {
410
// Load asynchronous scripts
411
head.js.apply( null, scriptsAsync );
412
}
413
414
start();
415
}
416
417
function loadScript( s ) {
418
head.ready( s.src.match( /([\w\d_\-]*)\.?js$|[^\\\/]*$/i )[0], function() {
419
// Extension may contain callback functions
420
if( typeof s.callback === 'function' ) {
421
s.callback.apply( this );
422
}
423
424
if( --scriptsToPreload === 0 ) {
425
proceed();
426
}
427
});
428
}
429
430
for( var i = 0, len = config.dependencies.length; i < len; i++ ) {
431
var s = config.dependencies[i];
432
433
// Load if there's no condition or the condition is truthy
434
if( !s.condition || s.condition() ) {
435
if( s.async ) {
436
scriptsAsync.push( s.src );
437
}
438
else {
439
scripts.push( s.src );
440
}
441
442
loadScript( s );
443
}
444
}
445
446
if( scripts.length ) {
447
scriptsToPreload = scripts.length;
448
449
// Load synchronous scripts
450
head.js.apply( null, scripts );
451
}
452
else {
453
proceed();
454
}
455
456
}
457
458
/**
459
* Starts up reveal.js by binding input events and navigating
460
* to the current URL deeplink if there is one.
461
*/
462
function start() {
463
464
loaded = true;
465
466
// Make sure we've got all the DOM elements we need
467
setupDOM();
468
469
// Listen to messages posted to this window
470
setupPostMessage();
471
472
// Prevent the slides from being scrolled out of view
473
setupScrollPrevention();
474
475
// Resets all vertical slides so that only the first is visible
476
resetVerticalSlides();
477
478
// Updates the presentation to match the current configuration values
479
configure();
480
481
// Read the initial hash
482
readURL();
483
484
// Update all backgrounds
485
updateBackground( true );
486
487
// Notify listeners that the presentation is ready but use a 1ms
488
// timeout to ensure it's not fired synchronously after #initialize()
489
setTimeout( function() {
490
// Enable transitions now that we're loaded
491
dom.slides.classList.remove( 'no-transition' );
492
493
dom.wrapper.classList.add( 'ready' );
494
495
dispatchEvent( 'ready', {
496
'indexh': indexh,
497
'indexv': indexv,
498
'currentSlide': currentSlide
499
} );
500
}, 1 );
501
502
// Special setup and config is required when printing to PDF
503
if( isPrintingPDF() ) {
504
removeEventListeners();
505
506
// The document needs to have loaded for the PDF layout
507
// measurements to be accurate
508
if( document.readyState === 'complete' ) {
509
setupPDF();
510
}
511
else {
512
window.addEventListener( 'load', setupPDF );
513
}
514
}
515
516
}
517
518
/**
519
* Finds and stores references to DOM elements which are
520
* required by the presentation. If a required element is
521
* not found, it is created.
522
*/
523
function setupDOM() {
524
525
// Prevent transitions while we're loading
526
dom.slides.classList.add( 'no-transition' );
527
528
if( isMobileDevice ) {
529
dom.wrapper.classList.add( 'no-hover' );
530
}
531
else {
532
dom.wrapper.classList.remove( 'no-hover' );
533
}
534
535
if( /iphone/gi.test( UA ) ) {
536
dom.wrapper.classList.add( 'ua-iphone' );
537
}
538
else {
539
dom.wrapper.classList.remove( 'ua-iphone' );
540
}
541
542
// Background element
543
dom.background = createSingletonNode( dom.wrapper, 'div', 'backgrounds', null );
544
545
// Progress bar
546
dom.progress = createSingletonNode( dom.wrapper, 'div', 'progress', '<span></span>' );
547
dom.progressbar = dom.progress.querySelector( 'span' );
548
549
// Arrow controls
550
dom.controls = createSingletonNode( dom.wrapper, 'aside', 'controls',
551
'<button class="navigate-left" aria-label="previous slide"><div class="controls-arrow"></div></button>' +
552
'<button class="navigate-right" aria-label="next slide"><div class="controls-arrow"></div></button>' +
553
'<button class="navigate-up" aria-label="above slide"><div class="controls-arrow"></div></button>' +
554
'<button class="navigate-down" aria-label="below slide"><div class="controls-arrow"></div></button>' );
555
556
// Slide number
557
dom.slideNumber = createSingletonNode( dom.wrapper, 'div', 'slide-number', '' );
558
559
// Element containing notes that are visible to the audience
560
dom.speakerNotes = createSingletonNode( dom.wrapper, 'div', 'speaker-notes', null );
561
dom.speakerNotes.setAttribute( 'data-prevent-swipe', '' );
562
dom.speakerNotes.setAttribute( 'tabindex', '0' );
563
564
// Overlay graphic which is displayed during the paused mode
565
createSingletonNode( dom.wrapper, 'div', 'pause-overlay', null );
566
567
dom.wrapper.setAttribute( 'role', 'application' );
568
569
// There can be multiple instances of controls throughout the page
570
dom.controlsLeft = toArray( document.querySelectorAll( '.navigate-left' ) );
571
dom.controlsRight = toArray( document.querySelectorAll( '.navigate-right' ) );
572
dom.controlsUp = toArray( document.querySelectorAll( '.navigate-up' ) );
573
dom.controlsDown = toArray( document.querySelectorAll( '.navigate-down' ) );
574
dom.controlsPrev = toArray( document.querySelectorAll( '.navigate-prev' ) );
575
dom.controlsNext = toArray( document.querySelectorAll( '.navigate-next' ) );
576
577
// The right and down arrows in the standard reveal.js controls
578
dom.controlsRightArrow = dom.controls.querySelector( '.navigate-right' );
579
dom.controlsDownArrow = dom.controls.querySelector( '.navigate-down' );
580
581
dom.statusDiv = createStatusDiv();
582
}
583
584
/**
585
* Creates a hidden div with role aria-live to announce the
586
* current slide content. Hide the div off-screen to make it
587
* available only to Assistive Technologies.
588
*
589
* @return {HTMLElement}
590
*/
591
function createStatusDiv() {
592
593
var statusDiv = document.getElementById( 'aria-status-div' );
594
if( !statusDiv ) {
595
statusDiv = document.createElement( 'div' );
596
statusDiv.style.position = 'absolute';
597
statusDiv.style.height = '1px';
598
statusDiv.style.width = '1px';
599
statusDiv.style.overflow = 'hidden';
600
statusDiv.style.clip = 'rect( 1px, 1px, 1px, 1px )';
601
statusDiv.setAttribute( 'id', 'aria-status-div' );
602
statusDiv.setAttribute( 'aria-live', 'polite' );
603
statusDiv.setAttribute( 'aria-atomic','true' );
604
dom.wrapper.appendChild( statusDiv );
605
}
606
return statusDiv;
607
608
}
609
610
/**
611
* Converts the given HTML element into a string of text
612
* that can be announced to a screen reader. Hidden
613
* elements are excluded.
614
*/
615
function getStatusText( node ) {
616
617
var text = '';
618
619
// Text node
620
if( node.nodeType === 3 ) {
621
text += node.textContent;
622
}
623
// Element node
624
else if( node.nodeType === 1 ) {
625
626
var isAriaHidden = node.getAttribute( 'aria-hidden' );
627
var isDisplayHidden = window.getComputedStyle( node )['display'] === 'none';
628
if( isAriaHidden !== 'true' && !isDisplayHidden ) {
629
630
toArray( node.childNodes ).forEach( function( child ) {
631
text += getStatusText( child );
632
} );
633
634
}
635
636
}
637
638
return text;
639
640
}
641
642
/**
643
* Configures the presentation for printing to a static
644
* PDF.
645
*/
646
function setupPDF() {
647
648
var slideSize = getComputedSlideSize( window.innerWidth, window.innerHeight );
649
650
// Dimensions of the PDF pages
651
var pageWidth = Math.floor( slideSize.width * ( 1 + config.margin ) ),
652
pageHeight = Math.floor( slideSize.height * ( 1 + config.margin ) );
653
654
// Dimensions of slides within the pages
655
var slideWidth = slideSize.width,
656
slideHeight = slideSize.height;
657
658
// Let the browser know what page size we want to print
659
injectStyleSheet( '@page{size:'+ pageWidth +'px '+ pageHeight +'px; margin: 0px;}' );
660
661
// Limit the size of certain elements to the dimensions of the slide
662
injectStyleSheet( '.reveal section>img, .reveal section>video, .reveal section>iframe{max-width: '+ slideWidth +'px; max-height:'+ slideHeight +'px}' );
663
664
document.body.classList.add( 'print-pdf' );
665
document.body.style.width = pageWidth + 'px';
666
document.body.style.height = pageHeight + 'px';
667
668
// Make sure stretch elements fit on slide
669
layoutSlideContents( slideWidth, slideHeight );
670
671
// Add each slide's index as attributes on itself, we need these
672
// indices to generate slide numbers below
673
toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ).forEach( function( hslide, h ) {
674
hslide.setAttribute( 'data-index-h', h );
675
676
if( hslide.classList.contains( 'stack' ) ) {
677
toArray( hslide.querySelectorAll( 'section' ) ).forEach( function( vslide, v ) {
678
vslide.setAttribute( 'data-index-h', h );
679
vslide.setAttribute( 'data-index-v', v );
680
} );
681
}
682
} );
683
684
// Slide and slide background layout
685
toArray( dom.wrapper.querySelectorAll( SLIDES_SELECTOR ) ).forEach( function( slide ) {
686
687
// Vertical stacks are not centred since their section
688
// children will be
689
if( slide.classList.contains( 'stack' ) === false ) {
690
// Center the slide inside of the page, giving the slide some margin
691
var left = ( pageWidth - slideWidth ) / 2,
692
top = ( pageHeight - slideHeight ) / 2;
693
694
var contentHeight = slide.scrollHeight;
695
var numberOfPages = Math.max( Math.ceil( contentHeight / pageHeight ), 1 );
696
697
// Adhere to configured pages per slide limit
698
numberOfPages = Math.min( numberOfPages, config.pdfMaxPagesPerSlide );
699
700
// Center slides vertically
701
if( numberOfPages === 1 && config.center || slide.classList.contains( 'center' ) ) {
702
top = Math.max( ( pageHeight - contentHeight ) / 2, 0 );
703
}
704
705
// Wrap the slide in a page element and hide its overflow
706
// so that no page ever flows onto another
707
var page = document.createElement( 'div' );
708
page.className = 'pdf-page';
709
page.style.height = ( ( pageHeight + config.pdfPageHeightOffset ) * numberOfPages ) + 'px';
710
slide.parentNode.insertBefore( page, slide );
711
page.appendChild( slide );
712
713
// Position the slide inside of the page
714
slide.style.left = left + 'px';
715
slide.style.top = top + 'px';
716
slide.style.width = slideWidth + 'px';
717
718
if( slide.slideBackgroundElement ) {
719
page.insertBefore( slide.slideBackgroundElement, slide );
720
}
721
722
// Inject notes if `showNotes` is enabled
723
if( config.showNotes ) {
724
725
// Are there notes for this slide?
726
var notes = getSlideNotes( slide );
727
if( notes ) {
728
729
var notesSpacing = 8;
730
var notesLayout = typeof config.showNotes === 'string' ? config.showNotes : 'inline';
731
var notesElement = document.createElement( 'div' );
732
notesElement.classList.add( 'speaker-notes' );
733
notesElement.classList.add( 'speaker-notes-pdf' );
734
notesElement.setAttribute( 'data-layout', notesLayout );
735
notesElement.innerHTML = notes;
736
737
if( notesLayout === 'separate-page' ) {
738
page.parentNode.insertBefore( notesElement, page.nextSibling );
739
}
740
else {
741
notesElement.style.left = notesSpacing + 'px';
742
notesElement.style.bottom = notesSpacing + 'px';
743
notesElement.style.width = ( pageWidth - notesSpacing*2 ) + 'px';
744
page.appendChild( notesElement );
745
}
746
747
}
748
749
}
750
751
// Inject slide numbers if `slideNumbers` are enabled
752
if( config.slideNumber && /all|print/i.test( config.showSlideNumber ) ) {
753
var slideNumberH = parseInt( slide.getAttribute( 'data-index-h' ), 10 ) + 1,
754
slideNumberV = parseInt( slide.getAttribute( 'data-index-v' ), 10 ) + 1;
755
756
var numberElement = document.createElement( 'div' );
757
numberElement.classList.add( 'slide-number' );
758
numberElement.classList.add( 'slide-number-pdf' );
759
numberElement.innerHTML = formatSlideNumber( slideNumberH, '.', slideNumberV );
760
page.appendChild( numberElement );
761
}
762
}
763
764
} );
765
766
// Show all fragments
767
toArray( dom.wrapper.querySelectorAll( SLIDES_SELECTOR + ' .fragment' ) ).forEach( function( fragment ) {
768
fragment.classList.add( 'visible' );
769
} );
770
771
// Notify subscribers that the PDF layout is good to go
772
dispatchEvent( 'pdf-ready' );
773
774
}
775
776
/**
777
* This is an unfortunate necessity. Some actions – such as
778
* an input field being focused in an iframe or using the
779
* keyboard to expand text selection beyond the bounds of
780
* a slide – can trigger our content to be pushed out of view.
781
* This scrolling can not be prevented by hiding overflow in
782
* CSS (we already do) so we have to resort to repeatedly
783
* checking if the slides have been offset :(
784
*/
785
function setupScrollPrevention() {
786
787
setInterval( function() {
788
if( dom.wrapper.scrollTop !== 0 || dom.wrapper.scrollLeft !== 0 ) {
789
dom.wrapper.scrollTop = 0;
790
dom.wrapper.scrollLeft = 0;
791
}
792
}, 1000 );
793
794
}
795
796
/**
797
* Creates an HTML element and returns a reference to it.
798
* If the element already exists the existing instance will
799
* be returned.
800
*
801
* @param {HTMLElement} container
802
* @param {string} tagname
803
* @param {string} classname
804
* @param {string} innerHTML
805
*
806
* @return {HTMLElement}
807
*/
808
function createSingletonNode( container, tagname, classname, innerHTML ) {
809
810
// Find all nodes matching the description
811
var nodes = container.querySelectorAll( '.' + classname );
812
813
// Check all matches to find one which is a direct child of
814
// the specified container
815
for( var i = 0; i < nodes.length; i++ ) {
816
var testNode = nodes[i];
817
if( testNode.parentNode === container ) {
818
return testNode;
819
}
820
}
821
822
// If no node was found, create it now
823
var node = document.createElement( tagname );
824
node.className = classname;
825
if( typeof innerHTML === 'string' ) {
826
node.innerHTML = innerHTML;
827
}
828
container.appendChild( node );
829
830
return node;
831
832
}
833
834
/**
835
* Creates the slide background elements and appends them
836
* to the background container. One element is created per
837
* slide no matter if the given slide has visible background.
838
*/
839
function createBackgrounds() {
840
841
var printMode = isPrintingPDF();
842
843
// Clear prior backgrounds
844
dom.background.innerHTML = '';
845
dom.background.classList.add( 'no-transition' );
846
847
// Iterate over all horizontal slides
848
toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ).forEach( function( slideh ) {
849
850
var backgroundStack = createBackground( slideh, dom.background );
851
852
// Iterate over all vertical slides
853
toArray( slideh.querySelectorAll( 'section' ) ).forEach( function( slidev ) {
854
855
createBackground( slidev, backgroundStack );
856
857
backgroundStack.classList.add( 'stack' );
858
859
} );
860
861
} );
862
863
// Add parallax background if specified
864
if( config.parallaxBackgroundImage ) {
865
866
dom.background.style.backgroundImage = 'url("' + config.parallaxBackgroundImage + '")';
867
dom.background.style.backgroundSize = config.parallaxBackgroundSize;
868
869
// Make sure the below properties are set on the element - these properties are
870
// needed for proper transitions to be set on the element via CSS. To remove
871
// annoying background slide-in effect when the presentation starts, apply
872
// these properties after short time delay
873
setTimeout( function() {
874
dom.wrapper.classList.add( 'has-parallax-background' );
875
}, 1 );
876
877
}
878
else {
879
880
dom.background.style.backgroundImage = '';
881
dom.wrapper.classList.remove( 'has-parallax-background' );
882
883
}
884
885
}
886
887
/**
888
* Creates a background for the given slide.
889
*
890
* @param {HTMLElement} slide
891
* @param {HTMLElement} container The element that the background
892
* should be appended to
893
* @return {HTMLElement} New background div
894
*/
895
function createBackground( slide, container ) {
896
897
var data = {
898
background: slide.getAttribute( 'data-background' ),
899
backgroundSize: slide.getAttribute( 'data-background-size' ),
900
backgroundImage: slide.getAttribute( 'data-background-image' ),
901
backgroundVideo: slide.getAttribute( 'data-background-video' ),
902
backgroundIframe: slide.getAttribute( 'data-background-iframe' ),
903
backgroundColor: slide.getAttribute( 'data-background-color' ),
904
backgroundRepeat: slide.getAttribute( 'data-background-repeat' ),
905
backgroundPosition: slide.getAttribute( 'data-background-position' ),
906
backgroundTransition: slide.getAttribute( 'data-background-transition' )
907
};
908
909
var element = document.createElement( 'div' );
910
911
// Carry over custom classes from the slide to the background
912
element.className = 'slide-background ' + slide.className.replace( /present|past|future/, '' );
913
914
if( data.background ) {
915
// Auto-wrap image urls in url(...)
916
if( /^(http|file|\/\/)/gi.test( data.background ) || /\.(svg|png|jpg|jpeg|gif|bmp)([?#]|$)/gi.test( data.background ) ) {
917
slide.setAttribute( 'data-background-image', data.background );
918
}
919
else {
920
element.style.background = data.background;
921
}
922
}
923
924
// Create a hash for this combination of background settings.
925
// This is used to determine when two slide backgrounds are
926
// the same.
927
if( data.background || data.backgroundColor || data.backgroundImage || data.backgroundVideo || data.backgroundIframe ) {
928
element.setAttribute( 'data-background-hash', data.background +
929
data.backgroundSize +
930
data.backgroundImage +
931
data.backgroundVideo +
932
data.backgroundIframe +
933
data.backgroundColor +
934
data.backgroundRepeat +
935
data.backgroundPosition +
936
data.backgroundTransition );
937
}
938
939
// Additional and optional background properties
940
if( data.backgroundSize ) element.style.backgroundSize = data.backgroundSize;
941
if( data.backgroundSize ) element.setAttribute( 'data-background-size', data.backgroundSize );
942
if( data.backgroundColor ) element.style.backgroundColor = data.backgroundColor;
943
if( data.backgroundRepeat ) element.style.backgroundRepeat = data.backgroundRepeat;
944
if( data.backgroundPosition ) element.style.backgroundPosition = data.backgroundPosition;
945
if( data.backgroundTransition ) element.setAttribute( 'data-background-transition', data.backgroundTransition );
946
947
container.appendChild( element );
948
949
// If backgrounds are being recreated, clear old classes
950
slide.classList.remove( 'has-dark-background' );
951
slide.classList.remove( 'has-light-background' );
952
953
slide.slideBackgroundElement = element;
954
955
// If this slide has a background color, add a class that
956
// signals if it is light or dark. If the slide has no background
957
// color, no class will be set
958
var computedBackgroundStyle = window.getComputedStyle( element );
959
if( computedBackgroundStyle && computedBackgroundStyle.backgroundColor ) {
960
var rgb = colorToRgb( computedBackgroundStyle.backgroundColor );
961
962
// Ignore fully transparent backgrounds. Some browsers return
963
// rgba(0,0,0,0) when reading the computed background color of
964
// an element with no background
965
if( rgb && rgb.a !== 0 ) {
966
if( colorBrightness( computedBackgroundStyle.backgroundColor ) < 128 ) {
967
slide.classList.add( 'has-dark-background' );
968
}
969
else {
970
slide.classList.add( 'has-light-background' );
971
}
972
}
973
}
974
975
return element;
976
977
}
978
979
/**
980
* Registers a listener to postMessage events, this makes it
981
* possible to call all reveal.js API methods from another
982
* window. For example:
983
*
984
* revealWindow.postMessage( JSON.stringify({
985
* method: 'slide',
986
* args: [ 2 ]
987
* }), '*' );
988
*/
989
function setupPostMessage() {
990
991
if( config.postMessage ) {
992
window.addEventListener( 'message', function ( event ) {
993
var data = event.data;
994
995
// Make sure we're dealing with JSON
996
if( typeof data === 'string' && data.charAt( 0 ) === '{' && data.charAt( data.length - 1 ) === '}' ) {
997
data = JSON.parse( data );
998
999
// Check if the requested method can be found
1000
if( data.method && typeof Reveal[data.method] === 'function' ) {
1001
Reveal[data.method].apply( Reveal, data.args );
1002
}
1003
}
1004
}, false );
1005
}
1006
1007
}
1008
1009
/**
1010
* Applies the configuration settings from the config
1011
* object. May be called multiple times.
1012
*
1013
* @param {object} options
1014
*/
1015
function configure( options ) {
1016
1017
var oldTransition = config.transition;
1018
1019
// New config options may be passed when this method
1020
// is invoked through the API after initialization
1021
if( typeof options === 'object' ) extend( config, options );
1022
1023
// Abort if reveal.js hasn't finished loading, config
1024
// changes will be applied automatically once loading
1025
// finishes
1026
if( loaded === false ) return;
1027
1028
var numberOfSlides = dom.wrapper.querySelectorAll( SLIDES_SELECTOR ).length;
1029
1030
// Remove the previously configured transition class
1031
dom.wrapper.classList.remove( oldTransition );
1032
1033
// Force linear transition based on browser capabilities
1034
if( features.transforms3d === false ) config.transition = 'linear';
1035
1036
dom.wrapper.classList.add( config.transition );
1037
1038
dom.wrapper.setAttribute( 'data-transition-speed', config.transitionSpeed );
1039
dom.wrapper.setAttribute( 'data-background-transition', config.backgroundTransition );
1040
1041
dom.controls.style.display = config.controls ? 'block' : 'none';
1042
dom.progress.style.display = config.progress ? 'block' : 'none';
1043
1044
dom.controls.setAttribute( 'data-controls-layout', config.controlsLayout );
1045
dom.controls.setAttribute( 'data-controls-back-arrows', config.controlsBackArrows );
1046
1047
if( config.shuffle ) {
1048
shuffle();
1049
}
1050
1051
if( config.rtl ) {
1052
dom.wrapper.classList.add( 'rtl' );
1053
}
1054
else {
1055
dom.wrapper.classList.remove( 'rtl' );
1056
}
1057
1058
if( config.center ) {
1059
dom.wrapper.classList.add( 'center' );
1060
}
1061
else {
1062
dom.wrapper.classList.remove( 'center' );
1063
}
1064
1065
// Exit the paused mode if it was configured off
1066
if( config.pause === false ) {
1067
resume();
1068
}
1069
1070
if( config.showNotes ) {
1071
dom.speakerNotes.setAttribute( 'data-layout', typeof config.showNotes === 'string' ? config.showNotes : 'inline' );
1072
}
1073
1074
if( config.mouseWheel ) {
1075
document.addEventListener( 'DOMMouseScroll', onDocumentMouseScroll, false ); // FF
1076
document.addEventListener( 'mousewheel', onDocumentMouseScroll, false );
1077
}
1078
else {
1079
document.removeEventListener( 'DOMMouseScroll', onDocumentMouseScroll, false ); // FF
1080
document.removeEventListener( 'mousewheel', onDocumentMouseScroll, false );
1081
}
1082
1083
// Rolling 3D links
1084
if( config.rollingLinks ) {
1085
enableRollingLinks();
1086
}
1087
else {
1088
disableRollingLinks();
1089
}
1090
1091
// Iframe link previews
1092
if( config.previewLinks ) {
1093
enablePreviewLinks();
1094
disablePreviewLinks( '[data-preview-link=false]' );
1095
}
1096
else {
1097
disablePreviewLinks();
1098
enablePreviewLinks( '[data-preview-link]:not([data-preview-link=false])' );
1099
}
1100
1101
// Remove existing auto-slide controls
1102
if( autoSlidePlayer ) {
1103
autoSlidePlayer.destroy();
1104
autoSlidePlayer = null;
1105
}
1106
1107
// Generate auto-slide controls if needed
1108
if( numberOfSlides > 1 && config.autoSlide && config.autoSlideStoppable && features.canvas && features.requestAnimationFrame ) {
1109
autoSlidePlayer = new Playback( dom.wrapper, function() {
1110
return Math.min( Math.max( ( Date.now() - autoSlideStartTime ) / autoSlide, 0 ), 1 );
1111
} );
1112
1113
autoSlidePlayer.on( 'click', onAutoSlidePlayerClick );
1114
autoSlidePaused = false;
1115
}
1116
1117
// When fragments are turned off they should be visible
1118
if( config.fragments === false ) {
1119
toArray( dom.slides.querySelectorAll( '.fragment' ) ).forEach( function( element ) {
1120
element.classList.add( 'visible' );
1121
element.classList.remove( 'current-fragment' );
1122
} );
1123
}
1124
1125
// Slide numbers
1126
var slideNumberDisplay = 'none';
1127
if( config.slideNumber && !isPrintingPDF() ) {
1128
if( config.showSlideNumber === 'all' ) {
1129
slideNumberDisplay = 'block';
1130
}
1131
else if( config.showSlideNumber === 'speaker' && isSpeakerNotes() ) {
1132
slideNumberDisplay = 'block';
1133
}
1134
}
1135
1136
dom.slideNumber.style.display = slideNumberDisplay;
1137
1138
sync();
1139
1140
}
1141
1142
/**
1143
* Binds all event listeners.
1144
*/
1145
function addEventListeners() {
1146
1147
eventsAreBound = true;
1148
1149
window.addEventListener( 'hashchange', onWindowHashChange, false );
1150
window.addEventListener( 'resize', onWindowResize, false );
1151
1152
if( config.touch ) {
1153
dom.wrapper.addEventListener( 'touchstart', onTouchStart, false );
1154
dom.wrapper.addEventListener( 'touchmove', onTouchMove, false );
1155
dom.wrapper.addEventListener( 'touchend', onTouchEnd, false );
1156
1157
// Support pointer-style touch interaction as well
1158
if( window.navigator.pointerEnabled ) {
1159
// IE 11 uses un-prefixed version of pointer events
1160
dom.wrapper.addEventListener( 'pointerdown', onPointerDown, false );
1161
dom.wrapper.addEventListener( 'pointermove', onPointerMove, false );
1162
dom.wrapper.addEventListener( 'pointerup', onPointerUp, false );
1163
}
1164
else if( window.navigator.msPointerEnabled ) {
1165
// IE 10 uses prefixed version of pointer events
1166
dom.wrapper.addEventListener( 'MSPointerDown', onPointerDown, false );
1167
dom.wrapper.addEventListener( 'MSPointerMove', onPointerMove, false );
1168
dom.wrapper.addEventListener( 'MSPointerUp', onPointerUp, false );
1169
}
1170
}
1171
1172
if( config.keyboard ) {
1173
document.addEventListener( 'keydown', onDocumentKeyDown, false );
1174
document.addEventListener( 'keypress', onDocumentKeyPress, false );
1175
}
1176
1177
if( config.progress && dom.progress ) {
1178
dom.progress.addEventListener( 'click', onProgressClicked, false );
1179
}
1180
1181
if( config.focusBodyOnPageVisibilityChange ) {
1182
var visibilityChange;
1183
1184
if( 'hidden' in document ) {
1185
visibilityChange = 'visibilitychange';
1186
}
1187
else if( 'msHidden' in document ) {
1188
visibilityChange = 'msvisibilitychange';
1189
}
1190
else if( 'webkitHidden' in document ) {
1191
visibilityChange = 'webkitvisibilitychange';
1192
}
1193
1194
if( visibilityChange ) {
1195
document.addEventListener( visibilityChange, onPageVisibilityChange, false );
1196
}
1197
}
1198
1199
// Listen to both touch and click events, in case the device
1200
// supports both
1201
var pointerEvents = [ 'touchstart', 'click' ];
1202
1203
// Only support touch for Android, fixes double navigations in
1204
// stock browser
1205
if( UA.match( /android/gi ) ) {
1206
pointerEvents = [ 'touchstart' ];
1207
}
1208
1209
pointerEvents.forEach( function( eventName ) {
1210
dom.controlsLeft.forEach( function( el ) { el.addEventListener( eventName, onNavigateLeftClicked, false ); } );
1211
dom.controlsRight.forEach( function( el ) { el.addEventListener( eventName, onNavigateRightClicked, false ); } );
1212
dom.controlsUp.forEach( function( el ) { el.addEventListener( eventName, onNavigateUpClicked, false ); } );
1213
dom.controlsDown.forEach( function( el ) { el.addEventListener( eventName, onNavigateDownClicked, false ); } );
1214
dom.controlsPrev.forEach( function( el ) { el.addEventListener( eventName, onNavigatePrevClicked, false ); } );
1215
dom.controlsNext.forEach( function( el ) { el.addEventListener( eventName, onNavigateNextClicked, false ); } );
1216
} );
1217
1218
}
1219
1220
/**
1221
* Unbinds all event listeners.
1222
*/
1223
function removeEventListeners() {
1224
1225
eventsAreBound = false;
1226
1227
document.removeEventListener( 'keydown', onDocumentKeyDown, false );
1228
document.removeEventListener( 'keypress', onDocumentKeyPress, false );
1229
window.removeEventListener( 'hashchange', onWindowHashChange, false );
1230
window.removeEventListener( 'resize', onWindowResize, false );
1231
1232
dom.wrapper.removeEventListener( 'touchstart', onTouchStart, false );
1233
dom.wrapper.removeEventListener( 'touchmove', onTouchMove, false );
1234
dom.wrapper.removeEventListener( 'touchend', onTouchEnd, false );
1235
1236
// IE11
1237
if( window.navigator.pointerEnabled ) {
1238
dom.wrapper.removeEventListener( 'pointerdown', onPointerDown, false );
1239
dom.wrapper.removeEventListener( 'pointermove', onPointerMove, false );
1240
dom.wrapper.removeEventListener( 'pointerup', onPointerUp, false );
1241
}
1242
// IE10
1243
else if( window.navigator.msPointerEnabled ) {
1244
dom.wrapper.removeEventListener( 'MSPointerDown', onPointerDown, false );
1245
dom.wrapper.removeEventListener( 'MSPointerMove', onPointerMove, false );
1246
dom.wrapper.removeEventListener( 'MSPointerUp', onPointerUp, false );
1247
}
1248
1249
if ( config.progress && dom.progress ) {
1250
dom.progress.removeEventListener( 'click', onProgressClicked, false );
1251
}
1252
1253
[ 'touchstart', 'click' ].forEach( function( eventName ) {
1254
dom.controlsLeft.forEach( function( el ) { el.removeEventListener( eventName, onNavigateLeftClicked, false ); } );
1255
dom.controlsRight.forEach( function( el ) { el.removeEventListener( eventName, onNavigateRightClicked, false ); } );
1256
dom.controlsUp.forEach( function( el ) { el.removeEventListener( eventName, onNavigateUpClicked, false ); } );
1257
dom.controlsDown.forEach( function( el ) { el.removeEventListener( eventName, onNavigateDownClicked, false ); } );
1258
dom.controlsPrev.forEach( function( el ) { el.removeEventListener( eventName, onNavigatePrevClicked, false ); } );
1259
dom.controlsNext.forEach( function( el ) { el.removeEventListener( eventName, onNavigateNextClicked, false ); } );
1260
} );
1261
1262
}
1263
1264
/**
1265
* Extend object a with the properties of object b.
1266
* If there's a conflict, object b takes precedence.
1267
*
1268
* @param {object} a
1269
* @param {object} b
1270
*/
1271
function extend( a, b ) {
1272
1273
for( var i in b ) {
1274
a[ i ] = b[ i ];
1275
}
1276
1277
return a;
1278
1279
}
1280
1281
/**
1282
* Converts the target object to an array.
1283
*
1284
* @param {object} o
1285
* @return {object[]}
1286
*/
1287
function toArray( o ) {
1288
1289
return Array.prototype.slice.call( o );
1290
1291
}
1292
1293
/**
1294
* Utility for deserializing a value.
1295
*
1296
* @param {*} value
1297
* @return {*}
1298
*/
1299
function deserialize( value ) {
1300
1301
if( typeof value === 'string' ) {
1302
if( value === 'null' ) return null;
1303
else if( value === 'true' ) return true;
1304
else if( value === 'false' ) return false;
1305
else if( value.match( /^-?[\d\.]+$/ ) ) return parseFloat( value );
1306
}
1307
1308
return value;
1309
1310
}
1311
1312
/**
1313
* Measures the distance in pixels between point a
1314
* and point b.
1315
*
1316
* @param {object} a point with x/y properties
1317
* @param {object} b point with x/y properties
1318
*
1319
* @return {number}
1320
*/
1321
function distanceBetween( a, b ) {
1322
1323
var dx = a.x - b.x,
1324
dy = a.y - b.y;
1325
1326
return Math.sqrt( dx*dx + dy*dy );
1327
1328
}
1329
1330
/**
1331
* Applies a CSS transform to the target element.
1332
*
1333
* @param {HTMLElement} element
1334
* @param {string} transform
1335
*/
1336
function transformElement( element, transform ) {
1337
1338
element.style.WebkitTransform = transform;
1339
element.style.MozTransform = transform;
1340
element.style.msTransform = transform;
1341
element.style.transform = transform;
1342
1343
}
1344
1345
/**
1346
* Applies CSS transforms to the slides container. The container
1347
* is transformed from two separate sources: layout and the overview
1348
* mode.
1349
*
1350
* @param {object} transforms
1351
*/
1352
function transformSlides( transforms ) {
1353
1354
// Pick up new transforms from arguments
1355
if( typeof transforms.layout === 'string' ) slidesTransform.layout = transforms.layout;
1356
if( typeof transforms.overview === 'string' ) slidesTransform.overview = transforms.overview;
1357
1358
// Apply the transforms to the slides container
1359
if( slidesTransform.layout ) {
1360
transformElement( dom.slides, slidesTransform.layout + ' ' + slidesTransform.overview );
1361
}
1362
else {
1363
transformElement( dom.slides, slidesTransform.overview );
1364
}
1365
1366
}
1367
1368
/**
1369
* Injects the given CSS styles into the DOM.
1370
*
1371
* @param {string} value
1372
*/
1373
function injectStyleSheet( value ) {
1374
1375
var tag = document.createElement( 'style' );
1376
tag.type = 'text/css';
1377
if( tag.styleSheet ) {
1378
tag.styleSheet.cssText = value;
1379
}
1380
else {
1381
tag.appendChild( document.createTextNode( value ) );
1382
}
1383
document.getElementsByTagName( 'head' )[0].appendChild( tag );
1384
1385
}
1386
1387
/**
1388
* Find the closest parent that matches the given
1389
* selector.
1390
*
1391
* @param {HTMLElement} target The child element
1392
* @param {String} selector The CSS selector to match
1393
* the parents against
1394
*
1395
* @return {HTMLElement} The matched parent or null
1396
* if no matching parent was found
1397
*/
1398
function closestParent( target, selector ) {
1399
1400
var parent = target.parentNode;
1401
1402
while( parent ) {
1403
1404
// There's some overhead doing this each time, we don't
1405
// want to rewrite the element prototype but should still
1406
// be enough to feature detect once at startup...
1407
var matchesMethod = parent.matches || parent.matchesSelector || parent.msMatchesSelector;
1408
1409
// If we find a match, we're all set
1410
if( matchesMethod && matchesMethod.call( parent, selector ) ) {
1411
return parent;
1412
}
1413
1414
// Keep searching
1415
parent = parent.parentNode;
1416
1417
}
1418
1419
return null;
1420
1421
}
1422
1423
/**
1424
* Converts various color input formats to an {r:0,g:0,b:0} object.
1425
*
1426
* @param {string} color The string representation of a color
1427
* @example
1428
* colorToRgb('#000');
1429
* @example
1430
* colorToRgb('#000000');
1431
* @example
1432
* colorToRgb('rgb(0,0,0)');
1433
* @example
1434
* colorToRgb('rgba(0,0,0)');
1435
*
1436
* @return {{r: number, g: number, b: number, [a]: number}|null}
1437
*/
1438
function colorToRgb( color ) {
1439
1440
var hex3 = color.match( /^#([0-9a-f]{3})$/i );
1441
if( hex3 && hex3[1] ) {
1442
hex3 = hex3[1];
1443
return {
1444
r: parseInt( hex3.charAt( 0 ), 16 ) * 0x11,
1445
g: parseInt( hex3.charAt( 1 ), 16 ) * 0x11,
1446
b: parseInt( hex3.charAt( 2 ), 16 ) * 0x11
1447
};
1448
}
1449
1450
var hex6 = color.match( /^#([0-9a-f]{6})$/i );
1451
if( hex6 && hex6[1] ) {
1452
hex6 = hex6[1];
1453
return {
1454
r: parseInt( hex6.substr( 0, 2 ), 16 ),
1455
g: parseInt( hex6.substr( 2, 2 ), 16 ),
1456
b: parseInt( hex6.substr( 4, 2 ), 16 )
1457
};
1458
}
1459
1460
var rgb = color.match( /^rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i );
1461
if( rgb ) {
1462
return {
1463
r: parseInt( rgb[1], 10 ),
1464
g: parseInt( rgb[2], 10 ),
1465
b: parseInt( rgb[3], 10 )
1466
};
1467
}
1468
1469
var rgba = color.match( /^rgba\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\,\s*([\d]+|[\d]*.[\d]+)\s*\)$/i );
1470
if( rgba ) {
1471
return {
1472
r: parseInt( rgba[1], 10 ),
1473
g: parseInt( rgba[2], 10 ),
1474
b: parseInt( rgba[3], 10 ),
1475
a: parseFloat( rgba[4] )
1476
};
1477
}
1478
1479
return null;
1480
1481
}
1482
1483
/**
1484
* Calculates brightness on a scale of 0-255.
1485
*
1486
* @param {string} color See colorToRgb for supported formats.
1487
* @see {@link colorToRgb}
1488
*/
1489
function colorBrightness( color ) {
1490
1491
if( typeof color === 'string' ) color = colorToRgb( color );
1492
1493
if( color ) {
1494
return ( color.r * 299 + color.g * 587 + color.b * 114 ) / 1000;
1495
}
1496
1497
return null;
1498
1499
}
1500
1501
/**
1502
* Returns the remaining height within the parent of the
1503
* target element.
1504
*
1505
* remaining height = [ configured parent height ] - [ current parent height ]
1506
*
1507
* @param {HTMLElement} element
1508
* @param {number} [height]
1509
*/
1510
function getRemainingHeight( element, height ) {
1511
1512
height = height || 0;
1513
1514
if( element ) {
1515
var newHeight, oldHeight = element.style.height;
1516
1517
// Change the .stretch element height to 0 in order find the height of all
1518
// the other elements
1519
element.style.height = '0px';
1520
newHeight = height - element.parentNode.offsetHeight;
1521
1522
// Restore the old height, just in case
1523
element.style.height = oldHeight + 'px';
1524
1525
return newHeight;
1526
}
1527
1528
return height;
1529
1530
}
1531
1532
/**
1533
* Checks if this instance is being used to print a PDF.
1534
*/
1535
function isPrintingPDF() {
1536
1537
return ( /print-pdf/gi ).test( window.location.search );
1538
1539
}
1540
1541
/**
1542
* Hides the address bar if we're on a mobile device.
1543
*/
1544
function hideAddressBar() {
1545
1546
if( config.hideAddressBar && isMobileDevice ) {
1547
// Events that should trigger the address bar to hide
1548
window.addEventListener( 'load', removeAddressBar, false );
1549
window.addEventListener( 'orientationchange', removeAddressBar, false );
1550
}
1551
1552
}
1553
1554
/**
1555
* Causes the address bar to hide on mobile devices,
1556
* more vertical space ftw.
1557
*/
1558
function removeAddressBar() {
1559
1560
setTimeout( function() {
1561
window.scrollTo( 0, 1 );
1562
}, 10 );
1563
1564
}
1565
1566
/**
1567
* Dispatches an event of the specified type from the
1568
* reveal DOM element.
1569
*/
1570
function dispatchEvent( type, args ) {
1571
1572
var event = document.createEvent( 'HTMLEvents', 1, 2 );
1573
event.initEvent( type, true, true );
1574
extend( event, args );
1575
dom.wrapper.dispatchEvent( event );
1576
1577
// If we're in an iframe, post each reveal.js event to the
1578
// parent window. Used by the notes plugin
1579
if( config.postMessageEvents && window.parent !== window.self ) {
1580
window.parent.postMessage( JSON.stringify({ namespace: 'reveal', eventName: type, state: getState() }), '*' );
1581
}
1582
1583
}
1584
1585
/**
1586
* Wrap all links in 3D goodness.
1587
*/
1588
function enableRollingLinks() {
1589
1590
if( features.transforms3d && !( 'msPerspective' in document.body.style ) ) {
1591
var anchors = dom.wrapper.querySelectorAll( SLIDES_SELECTOR + ' a' );
1592
1593
for( var i = 0, len = anchors.length; i < len; i++ ) {
1594
var anchor = anchors[i];
1595
1596
if( anchor.textContent && !anchor.querySelector( '*' ) && ( !anchor.className || !anchor.classList.contains( anchor, 'roll' ) ) ) {
1597
var span = document.createElement('span');
1598
span.setAttribute('data-title', anchor.text);
1599
span.innerHTML = anchor.innerHTML;
1600
1601
anchor.classList.add( 'roll' );
1602
anchor.innerHTML = '';
1603
anchor.appendChild(span);
1604
}
1605
}
1606
}
1607
1608
}
1609
1610
/**
1611
* Unwrap all 3D links.
1612
*/
1613
function disableRollingLinks() {
1614
1615
var anchors = dom.wrapper.querySelectorAll( SLIDES_SELECTOR + ' a.roll' );
1616
1617
for( var i = 0, len = anchors.length; i < len; i++ ) {
1618
var anchor = anchors[i];
1619
var span = anchor.querySelector( 'span' );
1620
1621
if( span ) {
1622
anchor.classList.remove( 'roll' );
1623
anchor.innerHTML = span.innerHTML;
1624
}
1625
}
1626
1627
}
1628
1629
/**
1630
* Bind preview frame links.
1631
*
1632
* @param {string} [selector=a] - selector for anchors
1633
*/
1634
function enablePreviewLinks( selector ) {
1635
1636
var anchors = toArray( document.querySelectorAll( selector ? selector : 'a' ) );
1637
1638
anchors.forEach( function( element ) {
1639
if( /^(http|www)/gi.test( element.getAttribute( 'href' ) ) ) {
1640
element.addEventListener( 'click', onPreviewLinkClicked, false );
1641
}
1642
} );
1643
1644
}
1645
1646
/**
1647
* Unbind preview frame links.
1648
*/
1649
function disablePreviewLinks( selector ) {
1650
1651
var anchors = toArray( document.querySelectorAll( selector ? selector : 'a' ) );
1652
1653
anchors.forEach( function( element ) {
1654
if( /^(http|www)/gi.test( element.getAttribute( 'href' ) ) ) {
1655
element.removeEventListener( 'click', onPreviewLinkClicked, false );
1656
}
1657
} );
1658
1659
}
1660
1661
/**
1662
* Opens a preview window for the target URL.
1663
*
1664
* @param {string} url - url for preview iframe src
1665
*/
1666
function showPreview( url ) {
1667
1668
closeOverlay();
1669
1670
dom.overlay = document.createElement( 'div' );
1671
dom.overlay.classList.add( 'overlay' );
1672
dom.overlay.classList.add( 'overlay-preview' );
1673
dom.wrapper.appendChild( dom.overlay );
1674
1675
dom.overlay.innerHTML = [
1676
'<header>',
1677
'<a class="close" href="#"><span class="icon"></span></a>',
1678
'<a class="external" href="'+ url +'" target="_blank"><span class="icon"></span></a>',
1679
'</header>',
1680
'<div class="spinner"></div>',
1681
'<div class="viewport">',
1682
'<iframe src="'+ url +'"></iframe>',
1683
'<small class="viewport-inner">',
1684
'<span class="x-frame-error">Unable to load iframe. This is likely due to the site\'s policy (x-frame-options).</span>',
1685
'</small>',
1686
'</div>'
1687
].join('');
1688
1689
dom.overlay.querySelector( 'iframe' ).addEventListener( 'load', function( event ) {
1690
dom.overlay.classList.add( 'loaded' );
1691
}, false );
1692
1693
dom.overlay.querySelector( '.close' ).addEventListener( 'click', function( event ) {
1694
closeOverlay();
1695
event.preventDefault();
1696
}, false );
1697
1698
dom.overlay.querySelector( '.external' ).addEventListener( 'click', function( event ) {
1699
closeOverlay();
1700
}, false );
1701
1702
setTimeout( function() {
1703
dom.overlay.classList.add( 'visible' );
1704
}, 1 );
1705
1706
}
1707
1708
/**
1709
* Open or close help overlay window.
1710
*
1711
* @param {Boolean} [override] Flag which overrides the
1712
* toggle logic and forcibly sets the desired state. True means
1713
* help is open, false means it's closed.
1714
*/
1715
function toggleHelp( override ){
1716
1717
if( typeof override === 'boolean' ) {
1718
override ? showHelp() : closeOverlay();
1719
}
1720
else {
1721
if( dom.overlay ) {
1722
closeOverlay();
1723
}
1724
else {
1725
showHelp();
1726
}
1727
}
1728
}
1729
1730
/**
1731
* Opens an overlay window with help material.
1732
*/
1733
function showHelp() {
1734
1735
if( config.help ) {
1736
1737
closeOverlay();
1738
1739
dom.overlay = document.createElement( 'div' );
1740
dom.overlay.classList.add( 'overlay' );
1741
dom.overlay.classList.add( 'overlay-help' );
1742
dom.wrapper.appendChild( dom.overlay );
1743
1744
var html = '<p class="title">Keyboard Shortcuts</p><br/>';
1745
1746
html += '<table><th>KEY</th><th>ACTION</th>';
1747
for( var key in keyboardShortcuts ) {
1748
html += '<tr><td>' + key + '</td><td>' + keyboardShortcuts[ key ] + '</td></tr>';
1749
}
1750
1751
html += '</table>';
1752
1753
dom.overlay.innerHTML = [
1754
'<header>',
1755
'<a class="close" href="#"><span class="icon"></span></a>',
1756
'</header>',
1757
'<div class="viewport">',
1758
'<div class="viewport-inner">'+ html +'</div>',
1759
'</div>'
1760
].join('');
1761
1762
dom.overlay.querySelector( '.close' ).addEventListener( 'click', function( event ) {
1763
closeOverlay();
1764
event.preventDefault();
1765
}, false );
1766
1767
setTimeout( function() {
1768
dom.overlay.classList.add( 'visible' );
1769
}, 1 );
1770
1771
}
1772
1773
}
1774
1775
/**
1776
* Closes any currently open overlay.
1777
*/
1778
function closeOverlay() {
1779
1780
if( dom.overlay ) {
1781
dom.overlay.parentNode.removeChild( dom.overlay );
1782
dom.overlay = null;
1783
}
1784
1785
}
1786
1787
/**
1788
* Applies JavaScript-controlled layout rules to the
1789
* presentation.
1790
*/
1791
function layout() {
1792
1793
if( dom.wrapper && !isPrintingPDF() ) {
1794
1795
var size = getComputedSlideSize();
1796
1797
// Layout the contents of the slides
1798
layoutSlideContents( config.width, config.height );
1799
1800
dom.slides.style.width = size.width + 'px';
1801
dom.slides.style.height = size.height + 'px';
1802
1803
// Determine scale of content to fit within available space
1804
scale = Math.min( size.presentationWidth / size.width, size.presentationHeight / size.height );
1805
1806
// Respect max/min scale settings
1807
scale = Math.max( scale, config.minScale );
1808
scale = Math.min( scale, config.maxScale );
1809
1810
// Don't apply any scaling styles if scale is 1
1811
if( scale === 1 ) {
1812
dom.slides.style.zoom = '';
1813
dom.slides.style.left = '';
1814
dom.slides.style.top = '';
1815
dom.slides.style.bottom = '';
1816
dom.slides.style.right = '';
1817
transformSlides( { layout: '' } );
1818
}
1819
else {
1820
// Prefer zoom for scaling up so that content remains crisp.
1821
// Don't use zoom to scale down since that can lead to shifts
1822
// in text layout/line breaks.
1823
if( scale > 1 && features.zoom ) {
1824
dom.slides.style.zoom = scale;
1825
dom.slides.style.left = '';
1826
dom.slides.style.top = '';
1827
dom.slides.style.bottom = '';
1828
dom.slides.style.right = '';
1829
transformSlides( { layout: '' } );
1830
}
1831
// Apply scale transform as a fallback
1832
else {
1833
dom.slides.style.zoom = '';
1834
dom.slides.style.left = '50%';
1835
dom.slides.style.top = '50%';
1836
dom.slides.style.bottom = 'auto';
1837
dom.slides.style.right = 'auto';
1838
transformSlides( { layout: 'translate(-50%, -50%) scale('+ scale +')' } );
1839
}
1840
}
1841
1842
// Select all slides, vertical and horizontal
1843
var slides = toArray( dom.wrapper.querySelectorAll( SLIDES_SELECTOR ) );
1844
1845
for( var i = 0, len = slides.length; i < len; i++ ) {
1846
var slide = slides[ i ];
1847
1848
// Don't bother updating invisible slides
1849
if( slide.style.display === 'none' ) {
1850
continue;
1851
}
1852
1853
if( config.center || slide.classList.contains( 'center' ) ) {
1854
// Vertical stacks are not centred since their section
1855
// children will be
1856
if( slide.classList.contains( 'stack' ) ) {
1857
slide.style.top = 0;
1858
}
1859
else {
1860
slide.style.top = Math.max( ( size.height - slide.scrollHeight ) / 2, 0 ) + 'px';
1861
}
1862
}
1863
else {
1864
slide.style.top = '';
1865
}
1866
1867
}
1868
1869
updateProgress();
1870
updateParallax();
1871
1872
if( isOverview() ) {
1873
updateOverview();
1874
}
1875
1876
}
1877
1878
}
1879
1880
/**
1881
* Applies layout logic to the contents of all slides in
1882
* the presentation.
1883
*
1884
* @param {string|number} width
1885
* @param {string|number} height
1886
*/
1887
function layoutSlideContents( width, height ) {
1888
1889
// Handle sizing of elements with the 'stretch' class
1890
toArray( dom.slides.querySelectorAll( 'section > .stretch' ) ).forEach( function( element ) {
1891
1892
// Determine how much vertical space we can use
1893
var remainingHeight = getRemainingHeight( element, height );
1894
1895
// Consider the aspect ratio of media elements
1896
if( /(img|video)/gi.test( element.nodeName ) ) {
1897
var nw = element.naturalWidth || element.videoWidth,
1898
nh = element.naturalHeight || element.videoHeight;
1899
1900
var es = Math.min( width / nw, remainingHeight / nh );
1901
1902
element.style.width = ( nw * es ) + 'px';
1903
element.style.height = ( nh * es ) + 'px';
1904
1905
}
1906
else {
1907
element.style.width = width + 'px';
1908
element.style.height = remainingHeight + 'px';
1909
}
1910
1911
} );
1912
1913
}
1914
1915
/**
1916
* Calculates the computed pixel size of our slides. These
1917
* values are based on the width and height configuration
1918
* options.
1919
*
1920
* @param {number} [presentationWidth=dom.wrapper.offsetWidth]
1921
* @param {number} [presentationHeight=dom.wrapper.offsetHeight]
1922
*/
1923
function getComputedSlideSize( presentationWidth, presentationHeight ) {
1924
1925
var size = {
1926
// Slide size
1927
width: config.width,
1928
height: config.height,
1929
1930
// Presentation size
1931
presentationWidth: presentationWidth || dom.wrapper.offsetWidth,
1932
presentationHeight: presentationHeight || dom.wrapper.offsetHeight
1933
};
1934
1935
// Reduce available space by margin
1936
size.presentationWidth -= ( size.presentationWidth * config.margin );
1937
size.presentationHeight -= ( size.presentationHeight * config.margin );
1938
1939
// Slide width may be a percentage of available width
1940
if( typeof size.width === 'string' && /%$/.test( size.width ) ) {
1941
size.width = parseInt( size.width, 10 ) / 100 * size.presentationWidth;
1942
}
1943
1944
// Slide height may be a percentage of available height
1945
if( typeof size.height === 'string' && /%$/.test( size.height ) ) {
1946
size.height = parseInt( size.height, 10 ) / 100 * size.presentationHeight;
1947
}
1948
1949
return size;
1950
1951
}
1952
1953
/**
1954
* Stores the vertical index of a stack so that the same
1955
* vertical slide can be selected when navigating to and
1956
* from the stack.
1957
*
1958
* @param {HTMLElement} stack The vertical stack element
1959
* @param {string|number} [v=0] Index to memorize
1960
*/
1961
function setPreviousVerticalIndex( stack, v ) {
1962
1963
if( typeof stack === 'object' && typeof stack.setAttribute === 'function' ) {
1964
stack.setAttribute( 'data-previous-indexv', v || 0 );
1965
}
1966
1967
}
1968
1969
/**
1970
* Retrieves the vertical index which was stored using
1971
* #setPreviousVerticalIndex() or 0 if no previous index
1972
* exists.
1973
*
1974
* @param {HTMLElement} stack The vertical stack element
1975
*/
1976
function getPreviousVerticalIndex( stack ) {
1977
1978
if( typeof stack === 'object' && typeof stack.setAttribute === 'function' && stack.classList.contains( 'stack' ) ) {
1979
// Prefer manually defined start-indexv
1980
var attributeName = stack.hasAttribute( 'data-start-indexv' ) ? 'data-start-indexv' : 'data-previous-indexv';
1981
1982
return parseInt( stack.getAttribute( attributeName ) || 0, 10 );
1983
}
1984
1985
return 0;
1986
1987
}
1988
1989
/**
1990
* Displays the overview of slides (quick nav) by scaling
1991
* down and arranging all slide elements.
1992
*/
1993
function activateOverview() {
1994
1995
// Only proceed if enabled in config
1996
if( config.overview && !isOverview() ) {
1997
1998
overview = true;
1999
2000
dom.wrapper.classList.add( 'overview' );
2001
dom.wrapper.classList.remove( 'overview-deactivating' );
2002
2003
if( features.overviewTransitions ) {
2004
setTimeout( function() {
2005
dom.wrapper.classList.add( 'overview-animated' );
2006
}, 1 );
2007
}
2008
2009
// Don't auto-slide while in overview mode
2010
cancelAutoSlide();
2011
2012
// Move the backgrounds element into the slide container to
2013
// that the same scaling is applied
2014
dom.slides.appendChild( dom.background );
2015
2016
// Clicking on an overview slide navigates to it
2017
toArray( dom.wrapper.querySelectorAll( SLIDES_SELECTOR ) ).forEach( function( slide ) {
2018
if( !slide.classList.contains( 'stack' ) ) {
2019
slide.addEventListener( 'click', onOverviewSlideClicked, true );
2020
}
2021
} );
2022
2023
// Calculate slide sizes
2024
var margin = 70;
2025
var slideSize = getComputedSlideSize();
2026
overviewSlideWidth = slideSize.width + margin;
2027
overviewSlideHeight = slideSize.height + margin;
2028
2029
// Reverse in RTL mode
2030
if( config.rtl ) {
2031
overviewSlideWidth = -overviewSlideWidth;
2032
}
2033
2034
updateSlidesVisibility();
2035
layoutOverview();
2036
updateOverview();
2037
2038
layout();
2039
2040
// Notify observers of the overview showing
2041
dispatchEvent( 'overviewshown', {
2042
'indexh': indexh,
2043
'indexv': indexv,
2044
'currentSlide': currentSlide
2045
} );
2046
2047
}
2048
2049
}
2050
2051
/**
2052
* Uses CSS transforms to position all slides in a grid for
2053
* display inside of the overview mode.
2054
*/
2055
function layoutOverview() {
2056
2057
// Layout slides
2058
toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ).forEach( function( hslide, h ) {
2059
hslide.setAttribute( 'data-index-h', h );
2060
transformElement( hslide, 'translate3d(' + ( h * overviewSlideWidth ) + 'px, 0, 0)' );
2061
2062
if( hslide.classList.contains( 'stack' ) ) {
2063
2064
toArray( hslide.querySelectorAll( 'section' ) ).forEach( function( vslide, v ) {
2065
vslide.setAttribute( 'data-index-h', h );
2066
vslide.setAttribute( 'data-index-v', v );
2067
2068
transformElement( vslide, 'translate3d(0, ' + ( v * overviewSlideHeight ) + 'px, 0)' );
2069
} );
2070
2071
}
2072
} );
2073
2074
// Layout slide backgrounds
2075
toArray( dom.background.childNodes ).forEach( function( hbackground, h ) {
2076
transformElement( hbackground, 'translate3d(' + ( h * overviewSlideWidth ) + 'px, 0, 0)' );
2077
2078
toArray( hbackground.querySelectorAll( '.slide-background' ) ).forEach( function( vbackground, v ) {
2079
transformElement( vbackground, 'translate3d(0, ' + ( v * overviewSlideHeight ) + 'px, 0)' );
2080
} );
2081
} );
2082
2083
}
2084
2085
/**
2086
* Moves the overview viewport to the current slides.
2087
* Called each time the current slide changes.
2088
*/
2089
function updateOverview() {
2090
2091
var vmin = Math.min( window.innerWidth, window.innerHeight );
2092
var scale = Math.max( vmin / 5, 150 ) / vmin;
2093
2094
transformSlides( {
2095
overview: [
2096
'scale('+ scale +')',
2097
'translateX('+ ( -indexh * overviewSlideWidth ) +'px)',
2098
'translateY('+ ( -indexv * overviewSlideHeight ) +'px)'
2099
].join( ' ' )
2100
} );
2101
2102
}
2103
2104
/**
2105
* Exits the slide overview and enters the currently
2106
* active slide.
2107
*/
2108
function deactivateOverview() {
2109
2110
// Only proceed if enabled in config
2111
if( config.overview ) {
2112
2113
overview = false;
2114
2115
dom.wrapper.classList.remove( 'overview' );
2116
dom.wrapper.classList.remove( 'overview-animated' );
2117
2118
// Temporarily add a class so that transitions can do different things
2119
// depending on whether they are exiting/entering overview, or just
2120
// moving from slide to slide
2121
dom.wrapper.classList.add( 'overview-deactivating' );
2122
2123
setTimeout( function () {
2124
dom.wrapper.classList.remove( 'overview-deactivating' );
2125
}, 1 );
2126
2127
// Move the background element back out
2128
dom.wrapper.appendChild( dom.background );
2129
2130
// Clean up changes made to slides
2131
toArray( dom.wrapper.querySelectorAll( SLIDES_SELECTOR ) ).forEach( function( slide ) {
2132
transformElement( slide, '' );
2133
2134
slide.removeEventListener( 'click', onOverviewSlideClicked, true );
2135
} );
2136
2137
// Clean up changes made to backgrounds
2138
toArray( dom.background.querySelectorAll( '.slide-background' ) ).forEach( function( background ) {
2139
transformElement( background, '' );
2140
} );
2141
2142
transformSlides( { overview: '' } );
2143
2144
slide( indexh, indexv );
2145
2146
layout();
2147
2148
cueAutoSlide();
2149
2150
// Notify observers of the overview hiding
2151
dispatchEvent( 'overviewhidden', {
2152
'indexh': indexh,
2153
'indexv': indexv,
2154
'currentSlide': currentSlide
2155
} );
2156
2157
}
2158
}
2159
2160
/**
2161
* Toggles the slide overview mode on and off.
2162
*
2163
* @param {Boolean} [override] Flag which overrides the
2164
* toggle logic and forcibly sets the desired state. True means
2165
* overview is open, false means it's closed.
2166
*/
2167
function toggleOverview( override ) {
2168
2169
if( typeof override === 'boolean' ) {
2170
override ? activateOverview() : deactivateOverview();
2171
}
2172
else {
2173
isOverview() ? deactivateOverview() : activateOverview();
2174
}
2175
2176
}
2177
2178
/**
2179
* Checks if the overview is currently active.
2180
*
2181
* @return {Boolean} true if the overview is active,
2182
* false otherwise
2183
*/
2184
function isOverview() {
2185
2186
return overview;
2187
2188
}
2189
2190
/**
2191
* Checks if the current or specified slide is vertical
2192
* (nested within another slide).
2193
*
2194
* @param {HTMLElement} [slide=currentSlide] The slide to check
2195
* orientation of
2196
* @return {Boolean}
2197
*/
2198
function isVerticalSlide( slide ) {
2199
2200
// Prefer slide argument, otherwise use current slide
2201
slide = slide ? slide : currentSlide;
2202
2203
return slide && slide.parentNode && !!slide.parentNode.nodeName.match( /section/i );
2204
2205
}
2206
2207
/**
2208
* Handling the fullscreen functionality via the fullscreen API
2209
*
2210
* @see http://fullscreen.spec.whatwg.org/
2211
* @see https://developer.mozilla.org/en-US/docs/DOM/Using_fullscreen_mode
2212
*/
2213
function enterFullscreen() {
2214
2215
var element = document.documentElement;
2216
2217
// Check which implementation is available
2218
var requestMethod = element.requestFullscreen ||
2219
element.webkitRequestFullscreen ||
2220
element.webkitRequestFullScreen ||
2221
element.mozRequestFullScreen ||
2222
element.msRequestFullscreen;
2223
2224
if( requestMethod ) {
2225
requestMethod.apply( element );
2226
}
2227
2228
}
2229
2230
/**
2231
* Enters the paused mode which fades everything on screen to
2232
* black.
2233
*/
2234
function pause() {
2235
2236
if( config.pause ) {
2237
var wasPaused = dom.wrapper.classList.contains( 'paused' );
2238
2239
cancelAutoSlide();
2240
dom.wrapper.classList.add( 'paused' );
2241
2242
if( wasPaused === false ) {
2243
dispatchEvent( 'paused' );
2244
}
2245
}
2246
2247
}
2248
2249
/**
2250
* Exits from the paused mode.
2251
*/
2252
function resume() {
2253
2254
var wasPaused = dom.wrapper.classList.contains( 'paused' );
2255
dom.wrapper.classList.remove( 'paused' );
2256
2257
cueAutoSlide();
2258
2259
if( wasPaused ) {
2260
dispatchEvent( 'resumed' );
2261
}
2262
2263
}
2264
2265
/**
2266
* Toggles the paused mode on and off.
2267
*/
2268
function togglePause( override ) {
2269
2270
if( typeof override === 'boolean' ) {
2271
override ? pause() : resume();
2272
}
2273
else {
2274
isPaused() ? resume() : pause();
2275
}
2276
2277
}
2278
2279
/**
2280
* Checks if we are currently in the paused mode.
2281
*
2282
* @return {Boolean}
2283
*/
2284
function isPaused() {
2285
2286
return dom.wrapper.classList.contains( 'paused' );
2287
2288
}
2289
2290
/**
2291
* Toggles the auto slide mode on and off.
2292
*
2293
* @param {Boolean} [override] Flag which sets the desired state.
2294
* True means autoplay starts, false means it stops.
2295
*/
2296
2297
function toggleAutoSlide( override ) {
2298
2299
if( typeof override === 'boolean' ) {
2300
override ? resumeAutoSlide() : pauseAutoSlide();
2301
}
2302
2303
else {
2304
autoSlidePaused ? resumeAutoSlide() : pauseAutoSlide();
2305
}
2306
2307
}
2308
2309
/**
2310
* Checks if the auto slide mode is currently on.
2311
*
2312
* @return {Boolean}
2313
*/
2314
function isAutoSliding() {
2315
2316
return !!( autoSlide && !autoSlidePaused );
2317
2318
}
2319
2320
/**
2321
* Steps from the current point in the presentation to the
2322
* slide which matches the specified horizontal and vertical
2323
* indices.
2324
*
2325
* @param {number} [h=indexh] Horizontal index of the target slide
2326
* @param {number} [v=indexv] Vertical index of the target slide
2327
* @param {number} [f] Index of a fragment within the
2328
* target slide to activate
2329
* @param {number} [o] Origin for use in multimaster environments
2330
*/
2331
function slide( h, v, f, o ) {
2332
2333
// Remember where we were at before
2334
previousSlide = currentSlide;
2335
2336
// Query all horizontal slides in the deck
2337
var horizontalSlides = dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
2338
2339
// Abort if there are no slides
2340
if( horizontalSlides.length === 0 ) return;
2341
2342
// If no vertical index is specified and the upcoming slide is a
2343
// stack, resume at its previous vertical index
2344
if( v === undefined && !isOverview() ) {
2345
v = getPreviousVerticalIndex( horizontalSlides[ h ] );
2346
}
2347
2348
// If we were on a vertical stack, remember what vertical index
2349
// it was on so we can resume at the same position when returning
2350
if( previousSlide && previousSlide.parentNode && previousSlide.parentNode.classList.contains( 'stack' ) ) {
2351
setPreviousVerticalIndex( previousSlide.parentNode, indexv );
2352
}
2353
2354
// Remember the state before this slide
2355
var stateBefore = state.concat();
2356
2357
// Reset the state array
2358
state.length = 0;
2359
2360
var indexhBefore = indexh || 0,
2361
indexvBefore = indexv || 0;
2362
2363
// Activate and transition to the new slide
2364
indexh = updateSlides( HORIZONTAL_SLIDES_SELECTOR, h === undefined ? indexh : h );
2365
indexv = updateSlides( VERTICAL_SLIDES_SELECTOR, v === undefined ? indexv : v );
2366
2367
// Update the visibility of slides now that the indices have changed
2368
updateSlidesVisibility();
2369
2370
layout();
2371
2372
// Apply the new state
2373
stateLoop: for( var i = 0, len = state.length; i < len; i++ ) {
2374
// Check if this state existed on the previous slide. If it
2375
// did, we will avoid adding it repeatedly
2376
for( var j = 0; j < stateBefore.length; j++ ) {
2377
if( stateBefore[j] === state[i] ) {
2378
stateBefore.splice( j, 1 );
2379
continue stateLoop;
2380
}
2381
}
2382
2383
document.documentElement.classList.add( state[i] );
2384
2385
// Dispatch custom event matching the state's name
2386
dispatchEvent( state[i] );
2387
}
2388
2389
// Clean up the remains of the previous state
2390
while( stateBefore.length ) {
2391
document.documentElement.classList.remove( stateBefore.pop() );
2392
}
2393
2394
// Update the overview if it's currently active
2395
if( isOverview() ) {
2396
updateOverview();
2397
}
2398
2399
// Find the current horizontal slide and any possible vertical slides
2400
// within it
2401
var currentHorizontalSlide = horizontalSlides[ indexh ],
2402
currentVerticalSlides = currentHorizontalSlide.querySelectorAll( 'section' );
2403
2404
// Store references to the previous and current slides
2405
currentSlide = currentVerticalSlides[ indexv ] || currentHorizontalSlide;
2406
2407
// Show fragment, if specified
2408
if( typeof f !== 'undefined' ) {
2409
navigateFragment( f );
2410
}
2411
2412
// Dispatch an event if the slide changed
2413
var slideChanged = ( indexh !== indexhBefore || indexv !== indexvBefore );
2414
if( slideChanged ) {
2415
dispatchEvent( 'slidechanged', {
2416
'indexh': indexh,
2417
'indexv': indexv,
2418
'previousSlide': previousSlide,
2419
'currentSlide': currentSlide,
2420
'origin': o
2421
} );
2422
}
2423
else {
2424
// Ensure that the previous slide is never the same as the current
2425
previousSlide = null;
2426
}
2427
2428
// Solves an edge case where the previous slide maintains the
2429
// 'present' class when navigating between adjacent vertical
2430
// stacks
2431
if( previousSlide ) {
2432
previousSlide.classList.remove( 'present' );
2433
previousSlide.setAttribute( 'aria-hidden', 'true' );
2434
2435
// Reset all slides upon navigate to home
2436
// Issue: #285
2437
if ( dom.wrapper.querySelector( HOME_SLIDE_SELECTOR ).classList.contains( 'present' ) ) {
2438
// Launch async task
2439
setTimeout( function () {
2440
var slides = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.stack') ), i;
2441
for( i in slides ) {
2442
if( slides[i] ) {
2443
// Reset stack
2444
setPreviousVerticalIndex( slides[i], 0 );
2445
}
2446
}
2447
}, 0 );
2448
}
2449
}
2450
2451
// Handle embedded content
2452
if( slideChanged || !previousSlide ) {
2453
stopEmbeddedContent( previousSlide );
2454
startEmbeddedContent( currentSlide );
2455
}
2456
2457
// Announce the current slide contents, for screen readers
2458
dom.statusDiv.textContent = getStatusText( currentSlide );
2459
2460
updateControls();
2461
updateProgress();
2462
updateBackground();
2463
updateParallax();
2464
updateSlideNumber();
2465
updateNotes();
2466
2467
// Update the URL hash
2468
writeURL();
2469
2470
cueAutoSlide();
2471
2472
}
2473
2474
/**
2475
* Syncs the presentation with the current DOM. Useful
2476
* when new slides or control elements are added or when
2477
* the configuration has changed.
2478
*/
2479
function sync() {
2480
2481
// Subscribe to input
2482
removeEventListeners();
2483
addEventListeners();
2484
2485
// Force a layout to make sure the current config is accounted for
2486
layout();
2487
2488
// Reflect the current autoSlide value
2489
autoSlide = config.autoSlide;
2490
2491
// Start auto-sliding if it's enabled
2492
cueAutoSlide();
2493
2494
// Re-create the slide backgrounds
2495
createBackgrounds();
2496
2497
// Write the current hash to the URL
2498
writeURL();
2499
2500
sortAllFragments();
2501
2502
updateControls();
2503
updateProgress();
2504
updateSlideNumber();
2505
updateSlidesVisibility();
2506
updateBackground( true );
2507
updateNotesVisibility();
2508
updateNotes();
2509
2510
formatEmbeddedContent();
2511
2512
// Start or stop embedded content depending on global config
2513
if( config.autoPlayMedia === false ) {
2514
stopEmbeddedContent( currentSlide, { unloadIframes: false } );
2515
}
2516
else {
2517
startEmbeddedContent( currentSlide );
2518
}
2519
2520
if( isOverview() ) {
2521
layoutOverview();
2522
}
2523
2524
}
2525
2526
/**
2527
* Resets all vertical slides so that only the first
2528
* is visible.
2529
*/
2530
function resetVerticalSlides() {
2531
2532
var horizontalSlides = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
2533
horizontalSlides.forEach( function( horizontalSlide ) {
2534
2535
var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
2536
verticalSlides.forEach( function( verticalSlide, y ) {
2537
2538
if( y > 0 ) {
2539
verticalSlide.classList.remove( 'present' );
2540
verticalSlide.classList.remove( 'past' );
2541
verticalSlide.classList.add( 'future' );
2542
verticalSlide.setAttribute( 'aria-hidden', 'true' );
2543
}
2544
2545
} );
2546
2547
} );
2548
2549
}
2550
2551
/**
2552
* Sorts and formats all of fragments in the
2553
* presentation.
2554
*/
2555
function sortAllFragments() {
2556
2557
var horizontalSlides = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
2558
horizontalSlides.forEach( function( horizontalSlide ) {
2559
2560
var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
2561
verticalSlides.forEach( function( verticalSlide, y ) {
2562
2563
sortFragments( verticalSlide.querySelectorAll( '.fragment' ) );
2564
2565
} );
2566
2567
if( verticalSlides.length === 0 ) sortFragments( horizontalSlide.querySelectorAll( '.fragment' ) );
2568
2569
} );
2570
2571
}
2572
2573
/**
2574
* Randomly shuffles all slides in the deck.
2575
*/
2576
function shuffle() {
2577
2578
var slides = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
2579
2580
slides.forEach( function( slide ) {
2581
2582
// Insert this slide next to another random slide. This may
2583
// cause the slide to insert before itself but that's fine.
2584
dom.slides.insertBefore( slide, slides[ Math.floor( Math.random() * slides.length ) ] );
2585
2586
} );
2587
2588
}
2589
2590
/**
2591
* Updates one dimension of slides by showing the slide
2592
* with the specified index.
2593
*
2594
* @param {string} selector A CSS selector that will fetch
2595
* the group of slides we are working with
2596
* @param {number} index The index of the slide that should be
2597
* shown
2598
*
2599
* @return {number} The index of the slide that is now shown,
2600
* might differ from the passed in index if it was out of
2601
* bounds.
2602
*/
2603
function updateSlides( selector, index ) {
2604
2605
// Select all slides and convert the NodeList result to
2606
// an array
2607
var slides = toArray( dom.wrapper.querySelectorAll( selector ) ),
2608
slidesLength = slides.length;
2609
2610
var printMode = isPrintingPDF();
2611
2612
if( slidesLength ) {
2613
2614
// Should the index loop?
2615
if( config.loop ) {
2616
index %= slidesLength;
2617
2618
if( index < 0 ) {
2619
index = slidesLength + index;
2620
}
2621
}
2622
2623
// Enforce max and minimum index bounds
2624
index = Math.max( Math.min( index, slidesLength - 1 ), 0 );
2625
2626
for( var i = 0; i < slidesLength; i++ ) {
2627
var element = slides[i];
2628
2629
var reverse = config.rtl && !isVerticalSlide( element );
2630
2631
element.classList.remove( 'past' );
2632
element.classList.remove( 'present' );
2633
element.classList.remove( 'future' );
2634
2635
// http://www.w3.org/html/wg/drafts/html/master/editing.html#the-hidden-attribute
2636
element.setAttribute( 'hidden', '' );
2637
element.setAttribute( 'aria-hidden', 'true' );
2638
2639
// If this element contains vertical slides
2640
if( element.querySelector( 'section' ) ) {
2641
element.classList.add( 'stack' );
2642
}
2643
2644
// If we're printing static slides, all slides are "present"
2645
if( printMode ) {
2646
element.classList.add( 'present' );
2647
continue;
2648
}
2649
2650
if( i < index ) {
2651
// Any element previous to index is given the 'past' class
2652
element.classList.add( reverse ? 'future' : 'past' );
2653
2654
if( config.fragments ) {
2655
var pastFragments = toArray( element.querySelectorAll( '.fragment' ) );
2656
2657
// Show all fragments on prior slides
2658
while( pastFragments.length ) {
2659
var pastFragment = pastFragments.pop();
2660
pastFragment.classList.add( 'visible' );
2661
pastFragment.classList.remove( 'current-fragment' );
2662
}
2663
}
2664
}
2665
else if( i > index ) {
2666
// Any element subsequent to index is given the 'future' class
2667
element.classList.add( reverse ? 'past' : 'future' );
2668
2669
if( config.fragments ) {
2670
var futureFragments = toArray( element.querySelectorAll( '.fragment.visible' ) );
2671
2672
// No fragments in future slides should be visible ahead of time
2673
while( futureFragments.length ) {
2674
var futureFragment = futureFragments.pop();
2675
futureFragment.classList.remove( 'visible' );
2676
futureFragment.classList.remove( 'current-fragment' );
2677
}
2678
}
2679
}
2680
}
2681
2682
// Mark the current slide as present
2683
slides[index].classList.add( 'present' );
2684
slides[index].removeAttribute( 'hidden' );
2685
slides[index].removeAttribute( 'aria-hidden' );
2686
2687
// If this slide has a state associated with it, add it
2688
// onto the current state of the deck
2689
var slideState = slides[index].getAttribute( 'data-state' );
2690
if( slideState ) {
2691
state = state.concat( slideState.split( ' ' ) );
2692
}
2693
2694
}
2695
else {
2696
// Since there are no slides we can't be anywhere beyond the
2697
// zeroth index
2698
index = 0;
2699
}
2700
2701
return index;
2702
2703
}
2704
2705
/**
2706
* Optimization method; hide all slides that are far away
2707
* from the present slide.
2708
*/
2709
function updateSlidesVisibility() {
2710
2711
// Select all slides and convert the NodeList result to
2712
// an array
2713
var horizontalSlides = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ),
2714
horizontalSlidesLength = horizontalSlides.length,
2715
distanceX,
2716
distanceY;
2717
2718
if( horizontalSlidesLength && typeof indexh !== 'undefined' ) {
2719
2720
// The number of steps away from the present slide that will
2721
// be visible
2722
var viewDistance = isOverview() ? 10 : config.viewDistance;
2723
2724
// Limit view distance on weaker devices
2725
if( isMobileDevice ) {
2726
viewDistance = isOverview() ? 6 : 2;
2727
}
2728
2729
// All slides need to be visible when exporting to PDF
2730
if( isPrintingPDF() ) {
2731
viewDistance = Number.MAX_VALUE;
2732
}
2733
2734
for( var x = 0; x < horizontalSlidesLength; x++ ) {
2735
var horizontalSlide = horizontalSlides[x];
2736
2737
var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) ),
2738
verticalSlidesLength = verticalSlides.length;
2739
2740
// Determine how far away this slide is from the present
2741
distanceX = Math.abs( ( indexh || 0 ) - x ) || 0;
2742
2743
// If the presentation is looped, distance should measure
2744
// 1 between the first and last slides
2745
if( config.loop ) {
2746
distanceX = Math.abs( ( ( indexh || 0 ) - x ) % ( horizontalSlidesLength - viewDistance ) ) || 0;
2747
}
2748
2749
// Show the horizontal slide if it's within the view distance
2750
if( distanceX < viewDistance ) {
2751
loadSlide( horizontalSlide );
2752
}
2753
else {
2754
unloadSlide( horizontalSlide );
2755
}
2756
2757
if( verticalSlidesLength ) {
2758
2759
var oy = getPreviousVerticalIndex( horizontalSlide );
2760
2761
for( var y = 0; y < verticalSlidesLength; y++ ) {
2762
var verticalSlide = verticalSlides[y];
2763
2764
distanceY = x === ( indexh || 0 ) ? Math.abs( ( indexv || 0 ) - y ) : Math.abs( y - oy );
2765
2766
if( distanceX + distanceY < viewDistance ) {
2767
loadSlide( verticalSlide );
2768
}
2769
else {
2770
unloadSlide( verticalSlide );
2771
}
2772
}
2773
2774
}
2775
}
2776
2777
// Flag if there are ANY vertical slides, anywhere in the deck
2778
if( dom.wrapper.querySelectorAll( '.slides>section>section' ).length ) {
2779
dom.wrapper.classList.add( 'has-vertical-slides' );
2780
}
2781
else {
2782
dom.wrapper.classList.remove( 'has-vertical-slides' );
2783
}
2784
2785
// Flag if there are ANY horizontal slides, anywhere in the deck
2786
if( dom.wrapper.querySelectorAll( '.slides>section' ).length > 1 ) {
2787
dom.wrapper.classList.add( 'has-horizontal-slides' );
2788
}
2789
else {
2790
dom.wrapper.classList.remove( 'has-horizontal-slides' );
2791
}
2792
2793
}
2794
2795
}
2796
2797
/**
2798
* Pick up notes from the current slide and display them
2799
* to the viewer.
2800
*
2801
* @see {@link config.showNotes}
2802
*/
2803
function updateNotes() {
2804
2805
if( config.showNotes && dom.speakerNotes && currentSlide && !isPrintingPDF() ) {
2806
2807
dom.speakerNotes.innerHTML = getSlideNotes() || '<span class="notes-placeholder">No notes on this slide.</span>';
2808
2809
}
2810
2811
}
2812
2813
/**
2814
* Updates the visibility of the speaker notes sidebar that
2815
* is used to share annotated slides. The notes sidebar is
2816
* only visible if showNotes is true and there are notes on
2817
* one or more slides in the deck.
2818
*/
2819
function updateNotesVisibility() {
2820
2821
if( config.showNotes && hasNotes() ) {
2822
dom.wrapper.classList.add( 'show-notes' );
2823
}
2824
else {
2825
dom.wrapper.classList.remove( 'show-notes' );
2826
}
2827
2828
}
2829
2830
/**
2831
* Checks if there are speaker notes for ANY slide in the
2832
* presentation.
2833
*/
2834
function hasNotes() {
2835
2836
return dom.slides.querySelectorAll( '[data-notes], aside.notes' ).length > 0;
2837
2838
}
2839
2840
/**
2841
* Updates the progress bar to reflect the current slide.
2842
*/
2843
function updateProgress() {
2844
2845
// Update progress if enabled
2846
if( config.progress && dom.progressbar ) {
2847
2848
dom.progressbar.style.width = getProgress() * dom.wrapper.offsetWidth + 'px';
2849
2850
}
2851
2852
}
2853
2854
/**
2855
* Updates the slide number div to reflect the current slide.
2856
*
2857
* The following slide number formats are available:
2858
* "h.v": horizontal . vertical slide number (default)
2859
* "h/v": horizontal / vertical slide number
2860
* "c": flattened slide number
2861
* "c/t": flattened slide number / total slides
2862
*/
2863
function updateSlideNumber() {
2864
2865
// Update slide number if enabled
2866
if( config.slideNumber && dom.slideNumber ) {
2867
2868
var value = [];
2869
var format = 'h.v';
2870
2871
// Check if a custom number format is available
2872
if( typeof config.slideNumber === 'string' ) {
2873
format = config.slideNumber;
2874
}
2875
2876
switch( format ) {
2877
case 'c':
2878
value.push( getSlidePastCount() + 1 );
2879
break;
2880
case 'c/t':
2881
value.push( getSlidePastCount() + 1, '/', getTotalSlides() );
2882
break;
2883
case 'h/v':
2884
value.push( indexh + 1 );
2885
if( isVerticalSlide() ) value.push( '/', indexv + 1 );
2886
break;
2887
default:
2888
value.push( indexh + 1 );
2889
if( isVerticalSlide() ) value.push( '.', indexv + 1 );
2890
}
2891
2892
dom.slideNumber.innerHTML = formatSlideNumber( value[0], value[1], value[2] );
2893
}
2894
2895
}
2896
2897
/**
2898
* Applies HTML formatting to a slide number before it's
2899
* written to the DOM.
2900
*
2901
* @param {number} a Current slide
2902
* @param {string} delimiter Character to separate slide numbers
2903
* @param {(number|*)} b Total slides
2904
* @return {string} HTML string fragment
2905
*/
2906
function formatSlideNumber( a, delimiter, b ) {
2907
2908
if( typeof b === 'number' && !isNaN( b ) ) {
2909
return '<span class="slide-number-a">'+ a +'</span>' +
2910
'<span class="slide-number-delimiter">'+ delimiter +'</span>' +
2911
'<span class="slide-number-b">'+ b +'</span>';
2912
}
2913
else {
2914
return '<span class="slide-number-a">'+ a +'</span>';
2915
}
2916
2917
}
2918
2919
/**
2920
* Updates the state of all control/navigation arrows.
2921
*/
2922
function updateControls() {
2923
2924
var routes = availableRoutes();
2925
var fragments = availableFragments();
2926
2927
// Remove the 'enabled' class from all directions
2928
dom.controlsLeft.concat( dom.controlsRight )
2929
.concat( dom.controlsUp )
2930
.concat( dom.controlsDown )
2931
.concat( dom.controlsPrev )
2932
.concat( dom.controlsNext ).forEach( function( node ) {
2933
node.classList.remove( 'enabled' );
2934
node.classList.remove( 'fragmented' );
2935
2936
// Set 'disabled' attribute on all directions
2937
node.setAttribute( 'disabled', 'disabled' );
2938
} );
2939
2940
// Add the 'enabled' class to the available routes; remove 'disabled' attribute to enable buttons
2941
if( routes.left ) dom.controlsLeft.forEach( function( el ) { el.classList.add( 'enabled' ); el.removeAttribute( 'disabled' ); } );
2942
if( routes.right ) dom.controlsRight.forEach( function( el ) { el.classList.add( 'enabled' ); el.removeAttribute( 'disabled' ); } );
2943
if( routes.up ) dom.controlsUp.forEach( function( el ) { el.classList.add( 'enabled' ); el.removeAttribute( 'disabled' ); } );
2944
if( routes.down ) dom.controlsDown.forEach( function( el ) { el.classList.add( 'enabled' ); el.removeAttribute( 'disabled' ); } );
2945
2946
// Prev/next buttons
2947
if( routes.left || routes.up ) dom.controlsPrev.forEach( function( el ) { el.classList.add( 'enabled' ); el.removeAttribute( 'disabled' ); } );
2948
if( routes.right || routes.down ) dom.controlsNext.forEach( function( el ) { el.classList.add( 'enabled' ); el.removeAttribute( 'disabled' ); } );
2949
2950
// Highlight fragment directions
2951
if( currentSlide ) {
2952
2953
// Always apply fragment decorator to prev/next buttons
2954
if( fragments.prev ) dom.controlsPrev.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); el.removeAttribute( 'disabled' ); } );
2955
if( fragments.next ) dom.controlsNext.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); el.removeAttribute( 'disabled' ); } );
2956
2957
// Apply fragment decorators to directional buttons based on
2958
// what slide axis they are in
2959
if( isVerticalSlide( currentSlide ) ) {
2960
if( fragments.prev ) dom.controlsUp.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); el.removeAttribute( 'disabled' ); } );
2961
if( fragments.next ) dom.controlsDown.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); el.removeAttribute( 'disabled' ); } );
2962
}
2963
else {
2964
if( fragments.prev ) dom.controlsLeft.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); el.removeAttribute( 'disabled' ); } );
2965
if( fragments.next ) dom.controlsRight.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); el.removeAttribute( 'disabled' ); } );
2966
}
2967
2968
}
2969
2970
if( config.controlsTutorial ) {
2971
2972
// Highlight control arrows with an animation to ensure
2973
// that the viewer knows how to navigate
2974
if( !hasNavigatedDown && routes.down ) {
2975
dom.controlsDownArrow.classList.add( 'highlight' );
2976
}
2977
else {
2978
dom.controlsDownArrow.classList.remove( 'highlight' );
2979
2980
if( !hasNavigatedRight && routes.right && indexv === 0 ) {
2981
dom.controlsRightArrow.classList.add( 'highlight' );
2982
}
2983
else {
2984
dom.controlsRightArrow.classList.remove( 'highlight' );
2985
}
2986
}
2987
2988
}
2989
2990
}
2991
2992
/**
2993
* Updates the background elements to reflect the current
2994
* slide.
2995
*
2996
* @param {boolean} includeAll If true, the backgrounds of
2997
* all vertical slides (not just the present) will be updated.
2998
*/
2999
function updateBackground( includeAll ) {
3000
3001
var currentBackground = null;
3002
3003
// Reverse past/future classes when in RTL mode
3004
var horizontalPast = config.rtl ? 'future' : 'past',
3005
horizontalFuture = config.rtl ? 'past' : 'future';
3006
3007
// Update the classes of all backgrounds to match the
3008
// states of their slides (past/present/future)
3009
toArray( dom.background.childNodes ).forEach( function( backgroundh, h ) {
3010
3011
backgroundh.classList.remove( 'past' );
3012
backgroundh.classList.remove( 'present' );
3013
backgroundh.classList.remove( 'future' );
3014
3015
if( h < indexh ) {
3016
backgroundh.classList.add( horizontalPast );
3017
}
3018
else if ( h > indexh ) {
3019
backgroundh.classList.add( horizontalFuture );
3020
}
3021
else {
3022
backgroundh.classList.add( 'present' );
3023
3024
// Store a reference to the current background element
3025
currentBackground = backgroundh;
3026
}
3027
3028
if( includeAll || h === indexh ) {
3029
toArray( backgroundh.querySelectorAll( '.slide-background' ) ).forEach( function( backgroundv, v ) {
3030
3031
backgroundv.classList.remove( 'past' );
3032
backgroundv.classList.remove( 'present' );
3033
backgroundv.classList.remove( 'future' );
3034
3035
if( v < indexv ) {
3036
backgroundv.classList.add( 'past' );
3037
}
3038
else if ( v > indexv ) {
3039
backgroundv.classList.add( 'future' );
3040
}
3041
else {
3042
backgroundv.classList.add( 'present' );
3043
3044
// Only if this is the present horizontal and vertical slide
3045
if( h === indexh ) currentBackground = backgroundv;
3046
}
3047
3048
} );
3049
}
3050
3051
} );
3052
3053
// Stop content inside of previous backgrounds
3054
if( previousBackground ) {
3055
3056
stopEmbeddedContent( previousBackground );
3057
3058
}
3059
3060
// Start content in the current background
3061
if( currentBackground ) {
3062
3063
startEmbeddedContent( currentBackground );
3064
3065
var backgroundImageURL = currentBackground.style.backgroundImage || '';
3066
3067
// Restart GIFs (doesn't work in Firefox)
3068
if( /\.gif/i.test( backgroundImageURL ) ) {
3069
currentBackground.style.backgroundImage = '';
3070
window.getComputedStyle( currentBackground ).opacity;
3071
currentBackground.style.backgroundImage = backgroundImageURL;
3072
}
3073
3074
// Don't transition between identical backgrounds. This
3075
// prevents unwanted flicker.
3076
var previousBackgroundHash = previousBackground ? previousBackground.getAttribute( 'data-background-hash' ) : null;
3077
var currentBackgroundHash = currentBackground.getAttribute( 'data-background-hash' );
3078
if( currentBackgroundHash && currentBackgroundHash === previousBackgroundHash && currentBackground !== previousBackground ) {
3079
dom.background.classList.add( 'no-transition' );
3080
}
3081
3082
previousBackground = currentBackground;
3083
3084
}
3085
3086
// If there's a background brightness flag for this slide,
3087
// bubble it to the .reveal container
3088
if( currentSlide ) {
3089
[ 'has-light-background', 'has-dark-background' ].forEach( function( classToBubble ) {
3090
if( currentSlide.classList.contains( classToBubble ) ) {
3091
dom.wrapper.classList.add( classToBubble );
3092
}
3093
else {
3094
dom.wrapper.classList.remove( classToBubble );
3095
}
3096
} );
3097
}
3098
3099
// Allow the first background to apply without transition
3100
setTimeout( function() {
3101
dom.background.classList.remove( 'no-transition' );
3102
}, 1 );
3103
3104
}
3105
3106
/**
3107
* Updates the position of the parallax background based
3108
* on the current slide index.
3109
*/
3110
function updateParallax() {
3111
3112
if( config.parallaxBackgroundImage ) {
3113
3114
var horizontalSlides = dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ),
3115
verticalSlides = dom.wrapper.querySelectorAll( VERTICAL_SLIDES_SELECTOR );
3116
3117
var backgroundSize = dom.background.style.backgroundSize.split( ' ' ),
3118
backgroundWidth, backgroundHeight;
3119
3120
if( backgroundSize.length === 1 ) {
3121
backgroundWidth = backgroundHeight = parseInt( backgroundSize[0], 10 );
3122
}
3123
else {
3124
backgroundWidth = parseInt( backgroundSize[0], 10 );
3125
backgroundHeight = parseInt( backgroundSize[1], 10 );
3126
}
3127
3128
var slideWidth = dom.background.offsetWidth,
3129
horizontalSlideCount = horizontalSlides.length,
3130
horizontalOffsetMultiplier,
3131
horizontalOffset;
3132
3133
if( typeof config.parallaxBackgroundHorizontal === 'number' ) {
3134
horizontalOffsetMultiplier = config.parallaxBackgroundHorizontal;
3135
}
3136
else {
3137
horizontalOffsetMultiplier = horizontalSlideCount > 1 ? ( backgroundWidth - slideWidth ) / ( horizontalSlideCount-1 ) : 0;
3138
}
3139
3140
horizontalOffset = horizontalOffsetMultiplier * indexh * -1;
3141
3142
var slideHeight = dom.background.offsetHeight,
3143
verticalSlideCount = verticalSlides.length,
3144
verticalOffsetMultiplier,
3145
verticalOffset;
3146
3147
if( typeof config.parallaxBackgroundVertical === 'number' ) {
3148
verticalOffsetMultiplier = config.parallaxBackgroundVertical;
3149
}
3150
else {
3151
verticalOffsetMultiplier = ( backgroundHeight - slideHeight ) / ( verticalSlideCount-1 );
3152
}
3153
3154
verticalOffset = verticalSlideCount > 0 ? verticalOffsetMultiplier * indexv : 0;
3155
3156
dom.background.style.backgroundPosition = horizontalOffset + 'px ' + -verticalOffset + 'px';
3157
3158
}
3159
3160
}
3161
3162
/**
3163
* Called when the given slide is within the configured view
3164
* distance. Shows the slide element and loads any content
3165
* that is set to load lazily (data-src).
3166
*
3167
* @param {HTMLElement} slide Slide to show
3168
*/
3169
function loadSlide( slide, options ) {
3170
3171
options = options || {};
3172
3173
// Show the slide element
3174
slide.style.display = config.display;
3175
3176
// Media elements with data-src attributes
3177
toArray( slide.querySelectorAll( 'img[data-src], video[data-src], audio[data-src]' ) ).forEach( function( element ) {
3178
element.setAttribute( 'src', element.getAttribute( 'data-src' ) );
3179
element.setAttribute( 'data-lazy-loaded', '' );
3180
element.removeAttribute( 'data-src' );
3181
} );
3182
3183
// Media elements with <source> children
3184
toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( media ) {
3185
var sources = 0;
3186
3187
toArray( media.querySelectorAll( 'source[data-src]' ) ).forEach( function( source ) {
3188
source.setAttribute( 'src', source.getAttribute( 'data-src' ) );
3189
source.removeAttribute( 'data-src' );
3190
source.setAttribute( 'data-lazy-loaded', '' );
3191
sources += 1;
3192
} );
3193
3194
// If we rewrote sources for this video/audio element, we need
3195
// to manually tell it to load from its new origin
3196
if( sources > 0 ) {
3197
media.load();
3198
}
3199
} );
3200
3201
3202
// Show the corresponding background element
3203
var indices = getIndices( slide );
3204
var background = getSlideBackground( indices.h, indices.v );
3205
if( background ) {
3206
background.style.display = 'block';
3207
3208
// If the background contains media, load it
3209
if( background.hasAttribute( 'data-loaded' ) === false ) {
3210
background.setAttribute( 'data-loaded', 'true' );
3211
3212
var backgroundImage = slide.getAttribute( 'data-background-image' ),
3213
backgroundVideo = slide.getAttribute( 'data-background-video' ),
3214
backgroundVideoLoop = slide.hasAttribute( 'data-background-video-loop' ),
3215
backgroundVideoMuted = slide.hasAttribute( 'data-background-video-muted' ),
3216
backgroundIframe = slide.getAttribute( 'data-background-iframe' );
3217
3218
// Images
3219
if( backgroundImage ) {
3220
background.style.backgroundImage = 'url('+ backgroundImage +')';
3221
}
3222
// Videos
3223
else if ( backgroundVideo && !isSpeakerNotes() ) {
3224
var video = document.createElement( 'video' );
3225
3226
if( backgroundVideoLoop ) {
3227
video.setAttribute( 'loop', '' );
3228
}
3229
3230
if( backgroundVideoMuted ) {
3231
video.muted = true;
3232
}
3233
3234
// Inline video playback works (at least in Mobile Safari) as
3235
// long as the video is muted and the `playsinline` attribute is
3236
// present
3237
if( isMobileDevice ) {
3238
video.muted = true;
3239
video.autoplay = true;
3240
video.setAttribute( 'playsinline', '' );
3241
}
3242
3243
// Support comma separated lists of video sources
3244
backgroundVideo.split( ',' ).forEach( function( source ) {
3245
video.innerHTML += '<source src="'+ source +'">';
3246
} );
3247
3248
background.appendChild( video );
3249
}
3250
// Iframes
3251
else if( backgroundIframe && options.excludeIframes !== true ) {
3252
var iframe = document.createElement( 'iframe' );
3253
iframe.setAttribute( 'allowfullscreen', '' );
3254
iframe.setAttribute( 'mozallowfullscreen', '' );
3255
iframe.setAttribute( 'webkitallowfullscreen', '' );
3256
3257
// Only load autoplaying content when the slide is shown to
3258
// avoid having it play in the background
3259
if( /autoplay=(1|true|yes)/gi.test( backgroundIframe ) ) {
3260
iframe.setAttribute( 'data-src', backgroundIframe );
3261
}
3262
else {
3263
iframe.setAttribute( 'src', backgroundIframe );
3264
}
3265
3266
iframe.style.width = '100%';
3267
iframe.style.height = '100%';
3268
iframe.style.maxHeight = '100%';
3269
iframe.style.maxWidth = '100%';
3270
3271
background.appendChild( iframe );
3272
}
3273
}
3274
3275
}
3276
3277
}
3278
3279
/**
3280
* Unloads and hides the given slide. This is called when the
3281
* slide is moved outside of the configured view distance.
3282
*
3283
* @param {HTMLElement} slide
3284
*/
3285
function unloadSlide( slide ) {
3286
3287
// Hide the slide element
3288
slide.style.display = 'none';
3289
3290
// Hide the corresponding background element
3291
var indices = getIndices( slide );
3292
var background = getSlideBackground( indices.h, indices.v );
3293
if( background ) {
3294
background.style.display = 'none';
3295
}
3296
3297
// Reset lazy-loaded media elements with src attributes
3298
toArray( slide.querySelectorAll( 'video[data-lazy-loaded][src], audio[data-lazy-loaded][src]' ) ).forEach( function( element ) {
3299
element.setAttribute( 'data-src', element.getAttribute( 'src' ) );
3300
element.removeAttribute( 'src' );
3301
} );
3302
3303
// Reset lazy-loaded media elements with <source> children
3304
toArray( slide.querySelectorAll( 'video[data-lazy-loaded] source[src], audio source[src]' ) ).forEach( function( source ) {
3305
source.setAttribute( 'data-src', source.getAttribute( 'src' ) );
3306
source.removeAttribute( 'src' );
3307
} );
3308
3309
}
3310
3311
/**
3312
* Determine what available routes there are for navigation.
3313
*
3314
* @return {{left: boolean, right: boolean, up: boolean, down: boolean}}
3315
*/
3316
function availableRoutes() {
3317
3318
var horizontalSlides = dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ),
3319
verticalSlides = dom.wrapper.querySelectorAll( VERTICAL_SLIDES_SELECTOR );
3320
3321
var routes = {
3322
left: indexh > 0 || config.loop,
3323
right: indexh < horizontalSlides.length - 1 || config.loop,
3324
up: indexv > 0,
3325
down: indexv < verticalSlides.length - 1
3326
};
3327
3328
// reverse horizontal controls for rtl
3329
if( config.rtl ) {
3330
var left = routes.left;
3331
routes.left = routes.right;
3332
routes.right = left;
3333
}
3334
3335
return routes;
3336
3337
}
3338
3339
/**
3340
* Returns an object describing the available fragment
3341
* directions.
3342
*
3343
* @return {{prev: boolean, next: boolean}}
3344
*/
3345
function availableFragments() {
3346
3347
if( currentSlide && config.fragments ) {
3348
var fragments = currentSlide.querySelectorAll( '.fragment' );
3349
var hiddenFragments = currentSlide.querySelectorAll( '.fragment:not(.visible)' );
3350
3351
return {
3352
prev: fragments.length - hiddenFragments.length > 0,
3353
next: !!hiddenFragments.length
3354
};
3355
}
3356
else {
3357
return { prev: false, next: false };
3358
}
3359
3360
}
3361
3362
/**
3363
* Enforces origin-specific format rules for embedded media.
3364
*/
3365
function formatEmbeddedContent() {
3366
3367
var _appendParamToIframeSource = function( sourceAttribute, sourceURL, param ) {
3368
toArray( dom.slides.querySelectorAll( 'iframe['+ sourceAttribute +'*="'+ sourceURL +'"]' ) ).forEach( function( el ) {
3369
var src = el.getAttribute( sourceAttribute );
3370
if( src && src.indexOf( param ) === -1 ) {
3371
el.setAttribute( sourceAttribute, src + ( !/\?/.test( src ) ? '?' : '&' ) + param );
3372
}
3373
});
3374
};
3375
3376
// YouTube frames must include "?enablejsapi=1"
3377
_appendParamToIframeSource( 'src', 'youtube.com/embed/', 'enablejsapi=1' );
3378
_appendParamToIframeSource( 'data-src', 'youtube.com/embed/', 'enablejsapi=1' );
3379
3380
// Vimeo frames must include "?api=1"
3381
_appendParamToIframeSource( 'src', 'player.vimeo.com/', 'api=1' );
3382
_appendParamToIframeSource( 'data-src', 'player.vimeo.com/', 'api=1' );
3383
3384
// Always show media controls on mobile devices
3385
if( isMobileDevice ) {
3386
toArray( dom.slides.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
3387
el.controls = true;
3388
} );
3389
}
3390
3391
}
3392
3393
/**
3394
* Start playback of any embedded content inside of
3395
* the given element.
3396
*
3397
* @param {HTMLElement} element
3398
*/
3399
function startEmbeddedContent( element ) {
3400
3401
if( element && !isSpeakerNotes() ) {
3402
3403
// Restart GIFs
3404
toArray( element.querySelectorAll( 'img[src$=".gif"]' ) ).forEach( function( el ) {
3405
// Setting the same unchanged source like this was confirmed
3406
// to work in Chrome, FF & Safari
3407
el.setAttribute( 'src', el.getAttribute( 'src' ) );
3408
} );
3409
3410
// HTML5 media elements
3411
toArray( element.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
3412
if( closestParent( el, '.fragment' ) && !closestParent( el, '.fragment.visible' ) ) {
3413
return;
3414
}
3415
3416
// Prefer an explicit global autoplay setting
3417
var autoplay = config.autoPlayMedia;
3418
3419
// If no global setting is available, fall back on the element's
3420
// own autoplay setting
3421
if( typeof autoplay !== 'boolean' ) {
3422
autoplay = el.hasAttribute( 'data-autoplay' ) || !!closestParent( el, '.slide-background' );
3423
}
3424
3425
if( autoplay && typeof el.play === 'function' ) {
3426
3427
if( el.readyState > 1 ) {
3428
startEmbeddedMedia( { target: el } );
3429
}
3430
else {
3431
el.removeEventListener( 'loadeddata', startEmbeddedMedia ); // remove first to avoid dupes
3432
el.addEventListener( 'loadeddata', startEmbeddedMedia );
3433
}
3434
3435
}
3436
} );
3437
3438
// Normal iframes
3439
toArray( element.querySelectorAll( 'iframe[src]' ) ).forEach( function( el ) {
3440
if( closestParent( el, '.fragment' ) && !closestParent( el, '.fragment.visible' ) ) {
3441
return;
3442
}
3443
3444
startEmbeddedIframe( { target: el } );
3445
} );
3446
3447
// Lazy loading iframes
3448
toArray( element.querySelectorAll( 'iframe[data-src]' ) ).forEach( function( el ) {
3449
if( closestParent( el, '.fragment' ) && !closestParent( el, '.fragment.visible' ) ) {
3450
return;
3451
}
3452
3453
if( el.getAttribute( 'src' ) !== el.getAttribute( 'data-src' ) ) {
3454
el.removeEventListener( 'load', startEmbeddedIframe ); // remove first to avoid dupes
3455
el.addEventListener( 'load', startEmbeddedIframe );
3456
el.setAttribute( 'src', el.getAttribute( 'data-src' ) );
3457
}
3458
} );
3459
3460
}
3461
3462
}
3463
3464
/**
3465
* Starts playing an embedded video/audio element after
3466
* it has finished loading.
3467
*
3468
* @param {object} event
3469
*/
3470
function startEmbeddedMedia( event ) {
3471
3472
var isAttachedToDOM = !!closestParent( event.target, 'html' ),
3473
isVisible = !!closestParent( event.target, '.present' );
3474
3475
if( isAttachedToDOM && isVisible ) {
3476
event.target.currentTime = 0;
3477
event.target.play();
3478
}
3479
3480
event.target.removeEventListener( 'loadeddata', startEmbeddedMedia );
3481
3482
}
3483
3484
/**
3485
* "Starts" the content of an embedded iframe using the
3486
* postMessage API.
3487
*
3488
* @param {object} event
3489
*/
3490
function startEmbeddedIframe( event ) {
3491
3492
var iframe = event.target;
3493
3494
if( iframe && iframe.contentWindow ) {
3495
3496
var isAttachedToDOM = !!closestParent( event.target, 'html' ),
3497
isVisible = !!closestParent( event.target, '.present' );
3498
3499
if( isAttachedToDOM && isVisible ) {
3500
3501
// Prefer an explicit global autoplay setting
3502
var autoplay = config.autoPlayMedia;
3503
3504
// If no global setting is available, fall back on the element's
3505
// own autoplay setting
3506
if( typeof autoplay !== 'boolean' ) {
3507
autoplay = iframe.hasAttribute( 'data-autoplay' ) || !!closestParent( iframe, '.slide-background' );
3508
}
3509
3510
// YouTube postMessage API
3511
if( /youtube\.com\/embed\//.test( iframe.getAttribute( 'src' ) ) && autoplay ) {
3512
iframe.contentWindow.postMessage( '{"event":"command","func":"playVideo","args":""}', '*' );
3513
}
3514
// Vimeo postMessage API
3515
else if( /player\.vimeo\.com\//.test( iframe.getAttribute( 'src' ) ) && autoplay ) {
3516
iframe.contentWindow.postMessage( '{"method":"play"}', '*' );
3517
}
3518
// Generic postMessage API
3519
else {
3520
iframe.contentWindow.postMessage( 'slide:start', '*' );
3521
}
3522
3523
}
3524
3525
}
3526
3527
}
3528
3529
/**
3530
* Stop playback of any embedded content inside of
3531
* the targeted slide.
3532
*
3533
* @param {HTMLElement} element
3534
*/
3535
function stopEmbeddedContent( element, options ) {
3536
3537
options = extend( {
3538
// Defaults
3539
unloadIframes: true
3540
}, options || {} );
3541
3542
if( element && element.parentNode ) {
3543
// HTML5 media elements
3544
toArray( element.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
3545
if( !el.hasAttribute( 'data-ignore' ) && typeof el.pause === 'function' ) {
3546
el.setAttribute('data-paused-by-reveal', '');
3547
el.pause();
3548
}
3549
} );
3550
3551
// Generic postMessage API for non-lazy loaded iframes
3552
toArray( element.querySelectorAll( 'iframe' ) ).forEach( function( el ) {
3553
if( el.contentWindow ) el.contentWindow.postMessage( 'slide:stop', '*' );
3554
el.removeEventListener( 'load', startEmbeddedIframe );
3555
});
3556
3557
// YouTube postMessage API
3558
toArray( element.querySelectorAll( 'iframe[src*="youtube.com/embed/"]' ) ).forEach( function( el ) {
3559
if( !el.hasAttribute( 'data-ignore' ) && el.contentWindow && typeof el.contentWindow.postMessage === 'function' ) {
3560
el.contentWindow.postMessage( '{"event":"command","func":"pauseVideo","args":""}', '*' );
3561
}
3562
});
3563
3564
// Vimeo postMessage API
3565
toArray( element.querySelectorAll( 'iframe[src*="player.vimeo.com/"]' ) ).forEach( function( el ) {
3566
if( !el.hasAttribute( 'data-ignore' ) && el.contentWindow && typeof el.contentWindow.postMessage === 'function' ) {
3567
el.contentWindow.postMessage( '{"method":"pause"}', '*' );
3568
}
3569
});
3570
3571
if( options.unloadIframes === true ) {
3572
// Unload lazy-loaded iframes
3573
toArray( element.querySelectorAll( 'iframe[data-src]' ) ).forEach( function( el ) {
3574
// Only removing the src doesn't actually unload the frame
3575
// in all browsers (Firefox) so we set it to blank first
3576
el.setAttribute( 'src', 'about:blank' );
3577
el.removeAttribute( 'src' );
3578
} );
3579
}
3580
}
3581
3582
}
3583
3584
/**
3585
* Returns the number of past slides. This can be used as a global
3586
* flattened index for slides.
3587
*
3588
* @return {number} Past slide count
3589
*/
3590
function getSlidePastCount() {
3591
3592
var horizontalSlides = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
3593
3594
// The number of past slides
3595
var pastCount = 0;
3596
3597
// Step through all slides and count the past ones
3598
mainLoop: for( var i = 0; i < horizontalSlides.length; i++ ) {
3599
3600
var horizontalSlide = horizontalSlides[i];
3601
var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
3602
3603
for( var j = 0; j < verticalSlides.length; j++ ) {
3604
3605
// Stop as soon as we arrive at the present
3606
if( verticalSlides[j].classList.contains( 'present' ) ) {
3607
break mainLoop;
3608
}
3609
3610
pastCount++;
3611
3612
}
3613
3614
// Stop as soon as we arrive at the present
3615
if( horizontalSlide.classList.contains( 'present' ) ) {
3616
break;
3617
}
3618
3619
// Don't count the wrapping section for vertical slides
3620
if( horizontalSlide.classList.contains( 'stack' ) === false ) {
3621
pastCount++;
3622
}
3623
3624
}
3625
3626
return pastCount;
3627
3628
}
3629
3630
/**
3631
* Returns a value ranging from 0-1 that represents
3632
* how far into the presentation we have navigated.
3633
*
3634
* @return {number}
3635
*/
3636
function getProgress() {
3637
3638
// The number of past and total slides
3639
var totalCount = getTotalSlides();
3640
var pastCount = getSlidePastCount();
3641
3642
if( currentSlide ) {
3643
3644
var allFragments = currentSlide.querySelectorAll( '.fragment' );
3645
3646
// If there are fragments in the current slide those should be
3647
// accounted for in the progress.
3648
if( allFragments.length > 0 ) {
3649
var visibleFragments = currentSlide.querySelectorAll( '.fragment.visible' );
3650
3651
// This value represents how big a portion of the slide progress
3652
// that is made up by its fragments (0-1)
3653
var fragmentWeight = 0.9;
3654
3655
// Add fragment progress to the past slide count
3656
pastCount += ( visibleFragments.length / allFragments.length ) * fragmentWeight;
3657
}
3658
3659
}
3660
3661
return pastCount / ( totalCount - 1 );
3662
3663
}
3664
3665
/**
3666
* Checks if this presentation is running inside of the
3667
* speaker notes window.
3668
*
3669
* @return {boolean}
3670
*/
3671
function isSpeakerNotes() {
3672
3673
return !!window.location.search.match( /receiver/gi );
3674
3675
}
3676
3677
/**
3678
* Reads the current URL (hash) and navigates accordingly.
3679
*/
3680
function readURL() {
3681
3682
var hash = window.location.hash;
3683
3684
// Attempt to parse the hash as either an index or name
3685
var bits = hash.slice( 2 ).split( '/' ),
3686
name = hash.replace( /#|\//gi, '' );
3687
3688
// If the first bit is invalid and there is a name we can
3689
// assume that this is a named link
3690
if( isNaN( parseInt( bits[0], 10 ) ) && name.length ) {
3691
var element;
3692
3693
// Ensure the named link is a valid HTML ID attribute
3694
if( /^[a-zA-Z][\w:.-]*$/.test( name ) ) {
3695
// Find the slide with the specified ID
3696
element = document.getElementById( name );
3697
}
3698
3699
if( element ) {
3700
// Find the position of the named slide and navigate to it
3701
var indices = Reveal.getIndices( element );
3702
slide( indices.h, indices.v );
3703
}
3704
// If the slide doesn't exist, navigate to the current slide
3705
else {
3706
slide( indexh || 0, indexv || 0 );
3707
}
3708
}
3709
else {
3710
// Read the index components of the hash
3711
var h = parseInt( bits[0], 10 ) || 0,
3712
v = parseInt( bits[1], 10 ) || 0;
3713
3714
if( h !== indexh || v !== indexv ) {
3715
slide( h, v );
3716
}
3717
}
3718
3719
}
3720
3721
/**
3722
* Updates the page URL (hash) to reflect the current
3723
* state.
3724
*
3725
* @param {number} delay The time in ms to wait before
3726
* writing the hash
3727
*/
3728
function writeURL( delay ) {
3729
3730
if( config.history ) {
3731
3732
// Make sure there's never more than one timeout running
3733
clearTimeout( writeURLTimeout );
3734
3735
// If a delay is specified, timeout this call
3736
if( typeof delay === 'number' ) {
3737
writeURLTimeout = setTimeout( writeURL, delay );
3738
}
3739
else if( currentSlide ) {
3740
var url = '/';
3741
3742
// Attempt to create a named link based on the slide's ID
3743
var id = currentSlide.getAttribute( 'id' );
3744
if( id ) {
3745
id = id.replace( /[^a-zA-Z0-9\-\_\:\.]/g, '' );
3746
}
3747
3748
// If the current slide has an ID, use that as a named link
3749
if( typeof id === 'string' && id.length ) {
3750
url = '/' + id;
3751
}
3752
// Otherwise use the /h/v index
3753
else {
3754
if( indexh > 0 || indexv > 0 ) url += indexh;
3755
if( indexv > 0 ) url += '/' + indexv;
3756
}
3757
3758
window.location.hash = url;
3759
}
3760
}
3761
3762
}
3763
/**
3764
* Retrieves the h/v location and fragment of the current,
3765
* or specified, slide.
3766
*
3767
* @param {HTMLElement} [slide] If specified, the returned
3768
* index will be for this slide rather than the currently
3769
* active one
3770
*
3771
* @return {{h: number, v: number, f: number}}
3772
*/
3773
function getIndices( slide ) {
3774
3775
// By default, return the current indices
3776
var h = indexh,
3777
v = indexv,
3778
f;
3779
3780
// If a slide is specified, return the indices of that slide
3781
if( slide ) {
3782
var isVertical = isVerticalSlide( slide );
3783
var slideh = isVertical ? slide.parentNode : slide;
3784
3785
// Select all horizontal slides
3786
var horizontalSlides = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
3787
3788
// Now that we know which the horizontal slide is, get its index
3789
h = Math.max( horizontalSlides.indexOf( slideh ), 0 );
3790
3791
// Assume we're not vertical
3792
v = undefined;
3793
3794
// If this is a vertical slide, grab the vertical index
3795
if( isVertical ) {
3796
v = Math.max( toArray( slide.parentNode.querySelectorAll( 'section' ) ).indexOf( slide ), 0 );
3797
}
3798
}
3799
3800
if( !slide && currentSlide ) {
3801
var hasFragments = currentSlide.querySelectorAll( '.fragment' ).length > 0;
3802
if( hasFragments ) {
3803
var currentFragment = currentSlide.querySelector( '.current-fragment' );
3804
if( currentFragment && currentFragment.hasAttribute( 'data-fragment-index' ) ) {
3805
f = parseInt( currentFragment.getAttribute( 'data-fragment-index' ), 10 );
3806
}
3807
else {
3808
f = currentSlide.querySelectorAll( '.fragment.visible' ).length - 1;
3809
}
3810
}
3811
}
3812
3813
return { h: h, v: v, f: f };
3814
3815
}
3816
3817
/**
3818
* Retrieves all slides in this presentation.
3819
*/
3820
function getSlides() {
3821
3822
return toArray( dom.wrapper.querySelectorAll( SLIDES_SELECTOR + ':not(.stack)' ));
3823
3824
}
3825
3826
/**
3827
* Retrieves the total number of slides in this presentation.
3828
*
3829
* @return {number}
3830
*/
3831
function getTotalSlides() {
3832
3833
return getSlides().length;
3834
3835
}
3836
3837
/**
3838
* Returns the slide element matching the specified index.
3839
*
3840
* @return {HTMLElement}
3841
*/
3842
function getSlide( x, y ) {
3843
3844
var horizontalSlide = dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR )[ x ];
3845
var verticalSlides = horizontalSlide && horizontalSlide.querySelectorAll( 'section' );
3846
3847
if( verticalSlides && verticalSlides.length && typeof y === 'number' ) {
3848
return verticalSlides ? verticalSlides[ y ] : undefined;
3849
}
3850
3851
return horizontalSlide;
3852
3853
}
3854
3855
/**
3856
* Returns the background element for the given slide.
3857
* All slides, even the ones with no background properties
3858
* defined, have a background element so as long as the
3859
* index is valid an element will be returned.
3860
*
3861
* @param {number} x Horizontal background index
3862
* @param {number} y Vertical background index
3863
* @return {(HTMLElement[]|*)}
3864
*/
3865
function getSlideBackground( x, y ) {
3866
3867
var slide = getSlide( x, y );
3868
if( slide ) {
3869
return slide.slideBackgroundElement;
3870
}
3871
3872
return undefined;
3873
3874
}
3875
3876
/**
3877
* Retrieves the speaker notes from a slide. Notes can be
3878
* defined in two ways:
3879
* 1. As a data-notes attribute on the slide <section>
3880
* 2. As an <aside class="notes"> inside of the slide
3881
*
3882
* @param {HTMLElement} [slide=currentSlide]
3883
* @return {(string|null)}
3884
*/
3885
function getSlideNotes( slide ) {
3886
3887
// Default to the current slide
3888
slide = slide || currentSlide;
3889
3890
// Notes can be specified via the data-notes attribute...
3891
if( slide.hasAttribute( 'data-notes' ) ) {
3892
return slide.getAttribute( 'data-notes' );
3893
}
3894
3895
// ... or using an <aside class="notes"> element
3896
var notesElement = slide.querySelector( 'aside.notes' );
3897
if( notesElement ) {
3898
return notesElement.innerHTML;
3899
}
3900
3901
return null;
3902
3903
}
3904
3905
/**
3906
* Retrieves the current state of the presentation as
3907
* an object. This state can then be restored at any
3908
* time.
3909
*
3910
* @return {{indexh: number, indexv: number, indexf: number, paused: boolean, overview: boolean}}
3911
*/
3912
function getState() {
3913
3914
var indices = getIndices();
3915
3916
return {
3917
indexh: indices.h,
3918
indexv: indices.v,
3919
indexf: indices.f,
3920
paused: isPaused(),
3921
overview: isOverview()
3922
};
3923
3924
}
3925
3926
/**
3927
* Restores the presentation to the given state.
3928
*
3929
* @param {object} state As generated by getState()
3930
* @see {@link getState} generates the parameter `state`
3931
*/
3932
function setState( state ) {
3933
3934
if( typeof state === 'object' ) {
3935
slide( deserialize( state.indexh ), deserialize( state.indexv ), deserialize( state.indexf ) );
3936
3937
var pausedFlag = deserialize( state.paused ),
3938
overviewFlag = deserialize( state.overview );
3939
3940
if( typeof pausedFlag === 'boolean' && pausedFlag !== isPaused() ) {
3941
togglePause( pausedFlag );
3942
}
3943
3944
if( typeof overviewFlag === 'boolean' && overviewFlag !== isOverview() ) {
3945
toggleOverview( overviewFlag );
3946
}
3947
}
3948
3949
}
3950
3951
/**
3952
* Return a sorted fragments list, ordered by an increasing
3953
* "data-fragment-index" attribute.
3954
*
3955
* Fragments will be revealed in the order that they are returned by
3956
* this function, so you can use the index attributes to control the
3957
* order of fragment appearance.
3958
*
3959
* To maintain a sensible default fragment order, fragments are presumed
3960
* to be passed in document order. This function adds a "fragment-index"
3961
* attribute to each node if such an attribute is not already present,
3962
* and sets that attribute to an integer value which is the position of
3963
* the fragment within the fragments list.
3964
*
3965
* @param {object[]|*} fragments
3966
* @return {object[]} sorted Sorted array of fragments
3967
*/
3968
function sortFragments( fragments ) {
3969
3970
fragments = toArray( fragments );
3971
3972
var ordered = [],
3973
unordered = [],
3974
sorted = [];
3975
3976
// Group ordered and unordered elements
3977
fragments.forEach( function( fragment, i ) {
3978
if( fragment.hasAttribute( 'data-fragment-index' ) ) {
3979
var index = parseInt( fragment.getAttribute( 'data-fragment-index' ), 10 );
3980
3981
if( !ordered[index] ) {
3982
ordered[index] = [];
3983
}
3984
3985
ordered[index].push( fragment );
3986
}
3987
else {
3988
unordered.push( [ fragment ] );
3989
}
3990
} );
3991
3992
// Append fragments without explicit indices in their
3993
// DOM order
3994
ordered = ordered.concat( unordered );
3995
3996
// Manually count the index up per group to ensure there
3997
// are no gaps
3998
var index = 0;
3999
4000
// Push all fragments in their sorted order to an array,
4001
// this flattens the groups
4002
ordered.forEach( function( group ) {
4003
group.forEach( function( fragment ) {
4004
sorted.push( fragment );
4005
fragment.setAttribute( 'data-fragment-index', index );
4006
} );
4007
4008
index ++;
4009
} );
4010
4011
return sorted;
4012
4013
}
4014
4015
/**
4016
* Navigate to the specified slide fragment.
4017
*
4018
* @param {?number} index The index of the fragment that
4019
* should be shown, -1 means all are invisible
4020
* @param {number} offset Integer offset to apply to the
4021
* fragment index
4022
*
4023
* @return {boolean} true if a change was made in any
4024
* fragments visibility as part of this call
4025
*/
4026
function navigateFragment( index, offset ) {
4027
4028
if( currentSlide && config.fragments ) {
4029
4030
var fragments = sortFragments( currentSlide.querySelectorAll( '.fragment' ) );
4031
if( fragments.length ) {
4032
4033
// If no index is specified, find the current
4034
if( typeof index !== 'number' ) {
4035
var lastVisibleFragment = sortFragments( currentSlide.querySelectorAll( '.fragment.visible' ) ).pop();
4036
4037
if( lastVisibleFragment ) {
4038
index = parseInt( lastVisibleFragment.getAttribute( 'data-fragment-index' ) || 0, 10 );
4039
}
4040
else {
4041
index = -1;
4042
}
4043
}
4044
4045
// If an offset is specified, apply it to the index
4046
if( typeof offset === 'number' ) {
4047
index += offset;
4048
}
4049
4050
var fragmentsShown = [],
4051
fragmentsHidden = [];
4052
4053
toArray( fragments ).forEach( function( element, i ) {
4054
4055
if( element.hasAttribute( 'data-fragment-index' ) ) {
4056
i = parseInt( element.getAttribute( 'data-fragment-index' ), 10 );
4057
}
4058
4059
// Visible fragments
4060
if( i <= index ) {
4061
if( !element.classList.contains( 'visible' ) ) fragmentsShown.push( element );
4062
element.classList.add( 'visible' );
4063
element.classList.remove( 'current-fragment' );
4064
4065
// Announce the fragments one by one to the Screen Reader
4066
dom.statusDiv.textContent = getStatusText( element );
4067
4068
if( i === index ) {
4069
element.classList.add( 'current-fragment' );
4070
startEmbeddedContent( element );
4071
}
4072
}
4073
// Hidden fragments
4074
else {
4075
if( element.classList.contains( 'visible' ) ) fragmentsHidden.push( element );
4076
element.classList.remove( 'visible' );
4077
element.classList.remove( 'current-fragment' );
4078
}
4079
4080
} );
4081
4082
if( fragmentsHidden.length ) {
4083
dispatchEvent( 'fragmenthidden', { fragment: fragmentsHidden[0], fragments: fragmentsHidden } );
4084
}
4085
4086
if( fragmentsShown.length ) {
4087
dispatchEvent( 'fragmentshown', { fragment: fragmentsShown[0], fragments: fragmentsShown } );
4088
}
4089
4090
updateControls();
4091
updateProgress();
4092
4093
return !!( fragmentsShown.length || fragmentsHidden.length );
4094
4095
}
4096
4097
}
4098
4099
return false;
4100
4101
}
4102
4103
/**
4104
* Navigate to the next slide fragment.
4105
*
4106
* @return {boolean} true if there was a next fragment,
4107
* false otherwise
4108
*/
4109
function nextFragment() {
4110
4111
return navigateFragment( null, 1 );
4112
4113
}
4114
4115
/**
4116
* Navigate to the previous slide fragment.
4117
*
4118
* @return {boolean} true if there was a previous fragment,
4119
* false otherwise
4120
*/
4121
function previousFragment() {
4122
4123
return navigateFragment( null, -1 );
4124
4125
}
4126
4127
/**
4128
* Cues a new automated slide if enabled in the config.
4129
*/
4130
function cueAutoSlide() {
4131
4132
cancelAutoSlide();
4133
4134
if( currentSlide && config.autoSlide !== false ) {
4135
4136
var fragment = currentSlide.querySelector( '.current-fragment' );
4137
4138
// When the slide first appears there is no "current" fragment so
4139
// we look for a data-autoslide timing on the first fragment
4140
if( !fragment ) fragment = currentSlide.querySelector( '.fragment' );
4141
4142
var fragmentAutoSlide = fragment ? fragment.getAttribute( 'data-autoslide' ) : null;
4143
var parentAutoSlide = currentSlide.parentNode ? currentSlide.parentNode.getAttribute( 'data-autoslide' ) : null;
4144
var slideAutoSlide = currentSlide.getAttribute( 'data-autoslide' );
4145
4146
// Pick value in the following priority order:
4147
// 1. Current fragment's data-autoslide
4148
// 2. Current slide's data-autoslide
4149
// 3. Parent slide's data-autoslide
4150
// 4. Global autoSlide setting
4151
if( fragmentAutoSlide ) {
4152
autoSlide = parseInt( fragmentAutoSlide, 10 );
4153
}
4154
else if( slideAutoSlide ) {
4155
autoSlide = parseInt( slideAutoSlide, 10 );
4156
}
4157
else if( parentAutoSlide ) {
4158
autoSlide = parseInt( parentAutoSlide, 10 );
4159
}
4160
else {
4161
autoSlide = config.autoSlide;
4162
}
4163
4164
// If there are media elements with data-autoplay,
4165
// automatically set the autoSlide duration to the
4166
// length of that media. Not applicable if the slide
4167
// is divided up into fragments.
4168
// playbackRate is accounted for in the duration.
4169
if( currentSlide.querySelectorAll( '.fragment' ).length === 0 ) {
4170
toArray( currentSlide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
4171
if( el.hasAttribute( 'data-autoplay' ) ) {
4172
if( autoSlide && (el.duration * 1000 / el.playbackRate ) > autoSlide ) {
4173
autoSlide = ( el.duration * 1000 / el.playbackRate ) + 1000;
4174
}
4175
}
4176
} );
4177
}
4178
4179
// Cue the next auto-slide if:
4180
// - There is an autoSlide value
4181
// - Auto-sliding isn't paused by the user
4182
// - The presentation isn't paused
4183
// - The overview isn't active
4184
// - The presentation isn't over
4185
if( autoSlide && !autoSlidePaused && !isPaused() && !isOverview() && ( !Reveal.isLastSlide() || availableFragments().next || config.loop === true ) ) {
4186
autoSlideTimeout = setTimeout( function() {
4187
typeof config.autoSlideMethod === 'function' ? config.autoSlideMethod() : navigateNext();
4188
cueAutoSlide();
4189
}, autoSlide );
4190
autoSlideStartTime = Date.now();
4191
}
4192
4193
if( autoSlidePlayer ) {
4194
autoSlidePlayer.setPlaying( autoSlideTimeout !== -1 );
4195
}
4196
4197
}
4198
4199
}
4200
4201
/**
4202
* Cancels any ongoing request to auto-slide.
4203
*/
4204
function cancelAutoSlide() {
4205
4206
clearTimeout( autoSlideTimeout );
4207
autoSlideTimeout = -1;
4208
4209
}
4210
4211
function pauseAutoSlide() {
4212
4213
if( autoSlide && !autoSlidePaused ) {
4214
autoSlidePaused = true;
4215
dispatchEvent( 'autoslidepaused' );
4216
clearTimeout( autoSlideTimeout );
4217
4218
if( autoSlidePlayer ) {
4219
autoSlidePlayer.setPlaying( false );
4220
}
4221
}
4222
4223
}
4224
4225
function resumeAutoSlide() {
4226
4227
if( autoSlide && autoSlidePaused ) {
4228
autoSlidePaused = false;
4229
dispatchEvent( 'autoslideresumed' );
4230
cueAutoSlide();
4231
}
4232
4233
}
4234
4235
function navigateLeft() {
4236
4237
// Reverse for RTL
4238
if( config.rtl ) {
4239
if( ( isOverview() || nextFragment() === false ) && availableRoutes().left ) {
4240
slide( indexh + 1 );
4241
}
4242
}
4243
// Normal navigation
4244
else if( ( isOverview() || previousFragment() === false ) && availableRoutes().left ) {
4245
slide( indexh - 1 );
4246
}
4247
4248
}
4249
4250
function navigateRight() {
4251
4252
hasNavigatedRight = true;
4253
4254
// Reverse for RTL
4255
if( config.rtl ) {
4256
if( ( isOverview() || previousFragment() === false ) && availableRoutes().right ) {
4257
slide( indexh - 1 );
4258
}
4259
}
4260
// Normal navigation
4261
else if( ( isOverview() || nextFragment() === false ) && availableRoutes().right ) {
4262
slide( indexh + 1 );
4263
}
4264
4265
}
4266
4267
function navigateUp() {
4268
4269
// Prioritize hiding fragments
4270
if( ( isOverview() || previousFragment() === false ) && availableRoutes().up ) {
4271
slide( indexh, indexv - 1 );
4272
}
4273
4274
}
4275
4276
function navigateDown() {
4277
4278
hasNavigatedDown = true;
4279
4280
// Prioritize revealing fragments
4281
if( ( isOverview() || nextFragment() === false ) && availableRoutes().down ) {
4282
slide( indexh, indexv + 1 );
4283
}
4284
4285
}
4286
4287
/**
4288
* Navigates backwards, prioritized in the following order:
4289
* 1) Previous fragment
4290
* 2) Previous vertical slide
4291
* 3) Previous horizontal slide
4292
*/
4293
function navigatePrev() {
4294
4295
// Prioritize revealing fragments
4296
if( previousFragment() === false ) {
4297
if( availableRoutes().up ) {
4298
navigateUp();
4299
}
4300
else {
4301
// Fetch the previous horizontal slide, if there is one
4302
var previousSlide;
4303
4304
if( config.rtl ) {
4305
previousSlide = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.future' ) ).pop();
4306
}
4307
else {
4308
previousSlide = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.past' ) ).pop();
4309
}
4310
4311
if( previousSlide ) {
4312
var v = ( previousSlide.querySelectorAll( 'section' ).length - 1 ) || undefined;
4313
var h = indexh - 1;
4314
slide( h, v );
4315
}
4316
}
4317
}
4318
4319
}
4320
4321
/**
4322
* The reverse of #navigatePrev().
4323
*/
4324
function navigateNext() {
4325
4326
hasNavigatedRight = true;
4327
hasNavigatedDown = true;
4328
4329
// Prioritize revealing fragments
4330
if( nextFragment() === false ) {
4331
if( availableRoutes().down ) {
4332
navigateDown();
4333
}
4334
else if( config.rtl ) {
4335
navigateLeft();
4336
}
4337
else {
4338
navigateRight();
4339
}
4340
}
4341
4342
}
4343
4344
/**
4345
* Checks if the target element prevents the triggering of
4346
* swipe navigation.
4347
*/
4348
function isSwipePrevented( target ) {
4349
4350
while( target && typeof target.hasAttribute === 'function' ) {
4351
if( target.hasAttribute( 'data-prevent-swipe' ) ) return true;
4352
target = target.parentNode;
4353
}
4354
4355
return false;
4356
4357
}
4358
4359
4360
// --------------------------------------------------------------------//
4361
// ----------------------------- EVENTS -------------------------------//
4362
// --------------------------------------------------------------------//
4363
4364
/**
4365
* Called by all event handlers that are based on user
4366
* input.
4367
*
4368
* @param {object} [event]
4369
*/
4370
function onUserInput( event ) {
4371
4372
if( config.autoSlideStoppable ) {
4373
pauseAutoSlide();
4374
}
4375
4376
}
4377
4378
/**
4379
* Handler for the document level 'keypress' event.
4380
*
4381
* @param {object} event
4382
*/
4383
function onDocumentKeyPress( event ) {
4384
4385
// Check if the pressed key is question mark
4386
if( event.shiftKey && event.charCode === 63 ) {
4387
toggleHelp();
4388
}
4389
4390
}
4391
4392
/**
4393
* Handler for the document level 'keydown' event.
4394
*
4395
* @param {object} event
4396
*/
4397
function onDocumentKeyDown( event ) {
4398
4399
// If there's a condition specified and it returns false,
4400
// ignore this event
4401
if( typeof config.keyboardCondition === 'function' && config.keyboardCondition() === false ) {
4402
return true;
4403
}
4404
4405
// Remember if auto-sliding was paused so we can toggle it
4406
var autoSlideWasPaused = autoSlidePaused;
4407
4408
onUserInput( event );
4409
4410
// Check if there's a focused element that could be using
4411
// the keyboard
4412
var activeElementIsCE = document.activeElement && document.activeElement.contentEditable !== 'inherit';
4413
var activeElementIsInput = document.activeElement && document.activeElement.tagName && /input|textarea/i.test( document.activeElement.tagName );
4414
var activeElementIsNotes = document.activeElement && document.activeElement.className && /speaker-notes/i.test( document.activeElement.className);
4415
4416
// Disregard the event if there's a focused element or a
4417
// keyboard modifier key is present
4418
if( activeElementIsCE || activeElementIsInput || activeElementIsNotes || (event.shiftKey && event.keyCode !== 32) || event.altKey || event.ctrlKey || event.metaKey ) return;
4419
4420
// While paused only allow resume keyboard events; 'b', 'v', '.'
4421
var resumeKeyCodes = [66,86,190,191];
4422
var key;
4423
4424
// Custom key bindings for togglePause should be able to resume
4425
if( typeof config.keyboard === 'object' ) {
4426
for( key in config.keyboard ) {
4427
if( config.keyboard[key] === 'togglePause' ) {
4428
resumeKeyCodes.push( parseInt( key, 10 ) );
4429
}
4430
}
4431
}
4432
4433
if( isPaused() && resumeKeyCodes.indexOf( event.keyCode ) === -1 ) {
4434
return false;
4435
}
4436
4437
var triggered = false;
4438
4439
// 1. User defined key bindings
4440
if( typeof config.keyboard === 'object' ) {
4441
4442
for( key in config.keyboard ) {
4443
4444
// Check if this binding matches the pressed key
4445
if( parseInt( key, 10 ) === event.keyCode ) {
4446
4447
var value = config.keyboard[ key ];
4448
4449
// Callback function
4450
if( typeof value === 'function' ) {
4451
value.apply( null, [ event ] );
4452
}
4453
// String shortcuts to reveal.js API
4454
else if( typeof value === 'string' && typeof Reveal[ value ] === 'function' ) {
4455
Reveal[ value ].call();
4456
}
4457
4458
triggered = true;
4459
4460
}
4461
4462
}
4463
4464
}
4465
4466
// 2. System defined key bindings
4467
if( triggered === false ) {
4468
4469
// Assume true and try to prove false
4470
triggered = true;
4471
4472
switch( event.keyCode ) {
4473
// p, page up
4474
case 80: case 33: navigatePrev(); break;
4475
// n, page down
4476
case 78: case 34: navigateNext(); break;
4477
// h, left
4478
case 72: case 37: navigateLeft(); break;
4479
// l, right
4480
case 76: case 39: navigateRight(); break;
4481
// k, up
4482
case 75: case 38: navigateUp(); break;
4483
// j, down
4484
case 74: case 40: navigateDown(); break;
4485
// home
4486
case 36: slide( 0 ); break;
4487
// end
4488
case 35: slide( Number.MAX_VALUE ); break;
4489
// space
4490
case 32: isOverview() ? deactivateOverview() : event.shiftKey ? navigatePrev() : navigateNext(); break;
4491
// return
4492
case 13: isOverview() ? deactivateOverview() : triggered = false; break;
4493
// two-spot, semicolon, b, v, period, Logitech presenter tools "black screen" button
4494
case 58: case 59: case 66: case 86: case 190: case 191: togglePause(); break;
4495
// f
4496
case 70: enterFullscreen(); break;
4497
// a
4498
case 65: if ( config.autoSlideStoppable ) toggleAutoSlide( autoSlideWasPaused ); break;
4499
default:
4500
triggered = false;
4501
}
4502
4503
}
4504
4505
// If the input resulted in a triggered action we should prevent
4506
// the browsers default behavior
4507
if( triggered ) {
4508
event.preventDefault && event.preventDefault();
4509
}
4510
// ESC or O key
4511
else if ( ( event.keyCode === 27 || event.keyCode === 79 ) && features.transforms3d ) {
4512
if( dom.overlay ) {
4513
closeOverlay();
4514
}
4515
else {
4516
toggleOverview();
4517
}
4518
4519
event.preventDefault && event.preventDefault();
4520
}
4521
4522
// If auto-sliding is enabled we need to cue up
4523
// another timeout
4524
cueAutoSlide();
4525
4526
}
4527
4528
/**
4529
* Handler for the 'touchstart' event, enables support for
4530
* swipe and pinch gestures.
4531
*
4532
* @param {object} event
4533
*/
4534
function onTouchStart( event ) {
4535
4536
if( isSwipePrevented( event.target ) ) return true;
4537
4538
touch.startX = event.touches[0].clientX;
4539
touch.startY = event.touches[0].clientY;
4540
touch.startCount = event.touches.length;
4541
4542
// If there's two touches we need to memorize the distance
4543
// between those two points to detect pinching
4544
if( event.touches.length === 2 && config.overview ) {
4545
touch.startSpan = distanceBetween( {
4546
x: event.touches[1].clientX,
4547
y: event.touches[1].clientY
4548
}, {
4549
x: touch.startX,
4550
y: touch.startY
4551
} );
4552
}
4553
4554
}
4555
4556
/**
4557
* Handler for the 'touchmove' event.
4558
*
4559
* @param {object} event
4560
*/
4561
function onTouchMove( event ) {
4562
4563
if( isSwipePrevented( event.target ) ) return true;
4564
4565
// Each touch should only trigger one action
4566
if( !touch.captured ) {
4567
onUserInput( event );
4568
4569
var currentX = event.touches[0].clientX;
4570
var currentY = event.touches[0].clientY;
4571
4572
// If the touch started with two points and still has
4573
// two active touches; test for the pinch gesture
4574
if( event.touches.length === 2 && touch.startCount === 2 && config.overview ) {
4575
4576
// The current distance in pixels between the two touch points
4577
var currentSpan = distanceBetween( {
4578
x: event.touches[1].clientX,
4579
y: event.touches[1].clientY
4580
}, {
4581
x: touch.startX,
4582
y: touch.startY
4583
} );
4584
4585
// If the span is larger than the desire amount we've got
4586
// ourselves a pinch
4587
if( Math.abs( touch.startSpan - currentSpan ) > touch.threshold ) {
4588
touch.captured = true;
4589
4590
if( currentSpan < touch.startSpan ) {
4591
activateOverview();
4592
}
4593
else {
4594
deactivateOverview();
4595
}
4596
}
4597
4598
event.preventDefault();
4599
4600
}
4601
// There was only one touch point, look for a swipe
4602
else if( event.touches.length === 1 && touch.startCount !== 2 ) {
4603
4604
var deltaX = currentX - touch.startX,
4605
deltaY = currentY - touch.startY;
4606
4607
if( deltaX > touch.threshold && Math.abs( deltaX ) > Math.abs( deltaY ) ) {
4608
touch.captured = true;
4609
navigateLeft();
4610
}
4611
else if( deltaX < -touch.threshold && Math.abs( deltaX ) > Math.abs( deltaY ) ) {
4612
touch.captured = true;
4613
navigateRight();
4614
}
4615
else if( deltaY > touch.threshold ) {
4616
touch.captured = true;
4617
navigateUp();
4618
}
4619
else if( deltaY < -touch.threshold ) {
4620
touch.captured = true;
4621
navigateDown();
4622
}
4623
4624
// If we're embedded, only block touch events if they have
4625
// triggered an action
4626
if( config.embedded ) {
4627
if( touch.captured || isVerticalSlide( currentSlide ) ) {
4628
event.preventDefault();
4629
}
4630
}
4631
// Not embedded? Block them all to avoid needless tossing
4632
// around of the viewport in iOS
4633
else {
4634
event.preventDefault();
4635
}
4636
4637
}
4638
}
4639
// There's a bug with swiping on some Android devices unless
4640
// the default action is always prevented
4641
else if( UA.match( /android/gi ) ) {
4642
event.preventDefault();
4643
}
4644
4645
}
4646
4647
/**
4648
* Handler for the 'touchend' event.
4649
*
4650
* @param {object} event
4651
*/
4652
function onTouchEnd( event ) {
4653
4654
touch.captured = false;
4655
4656
}
4657
4658
/**
4659
* Convert pointer down to touch start.
4660
*
4661
* @param {object} event
4662
*/
4663
function onPointerDown( event ) {
4664
4665
if( event.pointerType === event.MSPOINTER_TYPE_TOUCH || event.pointerType === "touch" ) {
4666
event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
4667
onTouchStart( event );
4668
}
4669
4670
}
4671
4672
/**
4673
* Convert pointer move to touch move.
4674
*
4675
* @param {object} event
4676
*/
4677
function onPointerMove( event ) {
4678
4679
if( event.pointerType === event.MSPOINTER_TYPE_TOUCH || event.pointerType === "touch" ) {
4680
event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
4681
onTouchMove( event );
4682
}
4683
4684
}
4685
4686
/**
4687
* Convert pointer up to touch end.
4688
*
4689
* @param {object} event
4690
*/
4691
function onPointerUp( event ) {
4692
4693
if( event.pointerType === event.MSPOINTER_TYPE_TOUCH || event.pointerType === "touch" ) {
4694
event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
4695
onTouchEnd( event );
4696
}
4697
4698
}
4699
4700
/**
4701
* Handles mouse wheel scrolling, throttled to avoid skipping
4702
* multiple slides.
4703
*
4704
* @param {object} event
4705
*/
4706
function onDocumentMouseScroll( event ) {
4707
4708
if( Date.now() - lastMouseWheelStep > 600 ) {
4709
4710
lastMouseWheelStep = Date.now();
4711
4712
var delta = event.detail || -event.wheelDelta;
4713
if( delta > 0 ) {
4714
navigateNext();
4715
}
4716
else if( delta < 0 ) {
4717
navigatePrev();
4718
}
4719
4720
}
4721
4722
}
4723
4724
/**
4725
* Clicking on the progress bar results in a navigation to the
4726
* closest approximate horizontal slide using this equation:
4727
*
4728
* ( clickX / presentationWidth ) * numberOfSlides
4729
*
4730
* @param {object} event
4731
*/
4732
function onProgressClicked( event ) {
4733
4734
onUserInput( event );
4735
4736
event.preventDefault();
4737
4738
var slidesTotal = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ).length;
4739
var slideIndex = Math.floor( ( event.clientX / dom.wrapper.offsetWidth ) * slidesTotal );
4740
4741
if( config.rtl ) {
4742
slideIndex = slidesTotal - slideIndex;
4743
}
4744
4745
slide( slideIndex );
4746
4747
}
4748
4749
/**
4750
* Event handler for navigation control buttons.
4751
*/
4752
function onNavigateLeftClicked( event ) { event.preventDefault(); onUserInput(); navigateLeft(); }
4753
function onNavigateRightClicked( event ) { event.preventDefault(); onUserInput(); navigateRight(); }
4754
function onNavigateUpClicked( event ) { event.preventDefault(); onUserInput(); navigateUp(); }
4755
function onNavigateDownClicked( event ) { event.preventDefault(); onUserInput(); navigateDown(); }
4756
function onNavigatePrevClicked( event ) { event.preventDefault(); onUserInput(); navigatePrev(); }
4757
function onNavigateNextClicked( event ) { event.preventDefault(); onUserInput(); navigateNext(); }
4758
4759
/**
4760
* Handler for the window level 'hashchange' event.
4761
*
4762
* @param {object} [event]
4763
*/
4764
function onWindowHashChange( event ) {
4765
4766
readURL();
4767
4768
}
4769
4770
/**
4771
* Handler for the window level 'resize' event.
4772
*
4773
* @param {object} [event]
4774
*/
4775
function onWindowResize( event ) {
4776
4777
layout();
4778
4779
}
4780
4781
/**
4782
* Handle for the window level 'visibilitychange' event.
4783
*
4784
* @param {object} [event]
4785
*/
4786
function onPageVisibilityChange( event ) {
4787
4788
var isHidden = document.webkitHidden ||
4789
document.msHidden ||
4790
document.hidden;
4791
4792
// If, after clicking a link or similar and we're coming back,
4793
// focus the document.body to ensure we can use keyboard shortcuts
4794
if( isHidden === false && document.activeElement !== document.body ) {
4795
// Not all elements support .blur() - SVGs among them.
4796
if( typeof document.activeElement.blur === 'function' ) {
4797
document.activeElement.blur();
4798
}
4799
document.body.focus();
4800
}
4801
4802
}
4803
4804
/**
4805
* Invoked when a slide is and we're in the overview.
4806
*
4807
* @param {object} event
4808
*/
4809
function onOverviewSlideClicked( event ) {
4810
4811
// TODO There's a bug here where the event listeners are not
4812
// removed after deactivating the overview.
4813
if( eventsAreBound && isOverview() ) {
4814
event.preventDefault();
4815
4816
var element = event.target;
4817
4818
while( element && !element.nodeName.match( /section/gi ) ) {
4819
element = element.parentNode;
4820
}
4821
4822
if( element && !element.classList.contains( 'disabled' ) ) {
4823
4824
deactivateOverview();
4825
4826
if( element.nodeName.match( /section/gi ) ) {
4827
var h = parseInt( element.getAttribute( 'data-index-h' ), 10 ),
4828
v = parseInt( element.getAttribute( 'data-index-v' ), 10 );
4829
4830
slide( h, v );
4831
}
4832
4833
}
4834
}
4835
4836
}
4837
4838
/**
4839
* Handles clicks on links that are set to preview in the
4840
* iframe overlay.
4841
*
4842
* @param {object} event
4843
*/
4844
function onPreviewLinkClicked( event ) {
4845
4846
if( event.currentTarget && event.currentTarget.hasAttribute( 'href' ) ) {
4847
var url = event.currentTarget.getAttribute( 'href' );
4848
if( url ) {
4849
showPreview( url );
4850
event.preventDefault();
4851
}
4852
}
4853
4854
}
4855
4856
/**
4857
* Handles click on the auto-sliding controls element.
4858
*
4859
* @param {object} [event]
4860
*/
4861
function onAutoSlidePlayerClick( event ) {
4862
4863
// Replay
4864
if( Reveal.isLastSlide() && config.loop === false ) {
4865
slide( 0, 0 );
4866
resumeAutoSlide();
4867
}
4868
// Resume
4869
else if( autoSlidePaused ) {
4870
resumeAutoSlide();
4871
}
4872
// Pause
4873
else {
4874
pauseAutoSlide();
4875
}
4876
4877
}
4878
4879
4880
// --------------------------------------------------------------------//
4881
// ------------------------ PLAYBACK COMPONENT ------------------------//
4882
// --------------------------------------------------------------------//
4883
4884
4885
/**
4886
* Constructor for the playback component, which displays
4887
* play/pause/progress controls.
4888
*
4889
* @param {HTMLElement} container The component will append
4890
* itself to this
4891
* @param {function} progressCheck A method which will be
4892
* called frequently to get the current progress on a range
4893
* of 0-1
4894
*/
4895
function Playback( container, progressCheck ) {
4896
4897
// Cosmetics
4898
this.diameter = 100;
4899
this.diameter2 = this.diameter/2;
4900
this.thickness = 6;
4901
4902
// Flags if we are currently playing
4903
this.playing = false;
4904
4905
// Current progress on a 0-1 range
4906
this.progress = 0;
4907
4908
// Used to loop the animation smoothly
4909
this.progressOffset = 1;
4910
4911
this.container = container;
4912
this.progressCheck = progressCheck;
4913
4914
this.canvas = document.createElement( 'canvas' );
4915
this.canvas.className = 'playback';
4916
this.canvas.width = this.diameter;
4917
this.canvas.height = this.diameter;
4918
this.canvas.style.width = this.diameter2 + 'px';
4919
this.canvas.style.height = this.diameter2 + 'px';
4920
this.context = this.canvas.getContext( '2d' );
4921
4922
this.container.appendChild( this.canvas );
4923
4924
this.render();
4925
4926
}
4927
4928
/**
4929
* @param value
4930
*/
4931
Playback.prototype.setPlaying = function( value ) {
4932
4933
var wasPlaying = this.playing;
4934
4935
this.playing = value;
4936
4937
// Start repainting if we weren't already
4938
if( !wasPlaying && this.playing ) {
4939
this.animate();
4940
}
4941
else {
4942
this.render();
4943
}
4944
4945
};
4946
4947
Playback.prototype.animate = function() {
4948
4949
var progressBefore = this.progress;
4950
4951
this.progress = this.progressCheck();
4952
4953
// When we loop, offset the progress so that it eases
4954
// smoothly rather than immediately resetting
4955
if( progressBefore > 0.8 && this.progress < 0.2 ) {
4956
this.progressOffset = this.progress;
4957
}
4958
4959
this.render();
4960
4961
if( this.playing ) {
4962
features.requestAnimationFrameMethod.call( window, this.animate.bind( this ) );
4963
}
4964
4965
};
4966
4967
/**
4968
* Renders the current progress and playback state.
4969
*/
4970
Playback.prototype.render = function() {
4971
4972
var progress = this.playing ? this.progress : 0,
4973
radius = ( this.diameter2 ) - this.thickness,
4974
x = this.diameter2,
4975
y = this.diameter2,
4976
iconSize = 28;
4977
4978
// Ease towards 1
4979
this.progressOffset += ( 1 - this.progressOffset ) * 0.1;
4980
4981
var endAngle = ( - Math.PI / 2 ) + ( progress * ( Math.PI * 2 ) );
4982
var startAngle = ( - Math.PI / 2 ) + ( this.progressOffset * ( Math.PI * 2 ) );
4983
4984
this.context.save();
4985
this.context.clearRect( 0, 0, this.diameter, this.diameter );
4986
4987
// Solid background color
4988
this.context.beginPath();
4989
this.context.arc( x, y, radius + 4, 0, Math.PI * 2, false );
4990
this.context.fillStyle = 'rgba( 0, 0, 0, 0.4 )';
4991
this.context.fill();
4992
4993
// Draw progress track
4994
this.context.beginPath();
4995
this.context.arc( x, y, radius, 0, Math.PI * 2, false );
4996
this.context.lineWidth = this.thickness;
4997
this.context.strokeStyle = 'rgba( 255, 255, 255, 0.2 )';
4998
this.context.stroke();
4999
5000
if( this.playing ) {
5001
// Draw progress on top of track
5002
this.context.beginPath();
5003
this.context.arc( x, y, radius, startAngle, endAngle, false );
5004
this.context.lineWidth = this.thickness;
5005
this.context.strokeStyle = '#fff';
5006
this.context.stroke();
5007
}
5008
5009
this.context.translate( x - ( iconSize / 2 ), y - ( iconSize / 2 ) );
5010
5011
// Draw play/pause icons
5012
if( this.playing ) {
5013
this.context.fillStyle = '#fff';
5014
this.context.fillRect( 0, 0, iconSize / 2 - 4, iconSize );
5015
this.context.fillRect( iconSize / 2 + 4, 0, iconSize / 2 - 4, iconSize );
5016
}
5017
else {
5018
this.context.beginPath();
5019
this.context.translate( 4, 0 );
5020
this.context.moveTo( 0, 0 );
5021
this.context.lineTo( iconSize - 4, iconSize / 2 );
5022
this.context.lineTo( 0, iconSize );
5023
this.context.fillStyle = '#fff';
5024
this.context.fill();
5025
}
5026
5027
this.context.restore();
5028
5029
};
5030
5031
Playback.prototype.on = function( type, listener ) {
5032
this.canvas.addEventListener( type, listener, false );
5033
};
5034
5035
Playback.prototype.off = function( type, listener ) {
5036
this.canvas.removeEventListener( type, listener, false );
5037
};
5038
5039
Playback.prototype.destroy = function() {
5040
5041
this.playing = false;
5042
5043
if( this.canvas.parentNode ) {
5044
this.container.removeChild( this.canvas );
5045
}
5046
5047
};
5048
5049
5050
// --------------------------------------------------------------------//
5051
// ------------------------------- API --------------------------------//
5052
// --------------------------------------------------------------------//
5053
5054
5055
Reveal = {
5056
VERSION: VERSION,
5057
5058
initialize: initialize,
5059
configure: configure,
5060
sync: sync,
5061
5062
// Navigation methods
5063
slide: slide,
5064
left: navigateLeft,
5065
right: navigateRight,
5066
up: navigateUp,
5067
down: navigateDown,
5068
prev: navigatePrev,
5069
next: navigateNext,
5070
5071
// Fragment methods
5072
navigateFragment: navigateFragment,
5073
prevFragment: previousFragment,
5074
nextFragment: nextFragment,
5075
5076
// Deprecated aliases
5077
navigateTo: slide,
5078
navigateLeft: navigateLeft,
5079
navigateRight: navigateRight,
5080
navigateUp: navigateUp,
5081
navigateDown: navigateDown,
5082
navigatePrev: navigatePrev,
5083
navigateNext: navigateNext,
5084
5085
// Forces an update in slide layout
5086
layout: layout,
5087
5088
// Randomizes the order of slides
5089
shuffle: shuffle,
5090
5091
// Returns an object with the available routes as booleans (left/right/top/bottom)
5092
availableRoutes: availableRoutes,
5093
5094
// Returns an object with the available fragments as booleans (prev/next)
5095
availableFragments: availableFragments,
5096
5097
// Toggles a help overlay with keyboard shortcuts
5098
toggleHelp: toggleHelp,
5099
5100
// Toggles the overview mode on/off
5101
toggleOverview: toggleOverview,
5102
5103
// Toggles the "black screen" mode on/off
5104
togglePause: togglePause,
5105
5106
// Toggles the auto slide mode on/off
5107
toggleAutoSlide: toggleAutoSlide,
5108
5109
// State checks
5110
isOverview: isOverview,
5111
isPaused: isPaused,
5112
isAutoSliding: isAutoSliding,
5113
isSpeakerNotes: isSpeakerNotes,
5114
5115
// Slide preloading
5116
loadSlide: loadSlide,
5117
unloadSlide: unloadSlide,
5118
5119
// Adds or removes all internal event listeners (such as keyboard)
5120
addEventListeners: addEventListeners,
5121
removeEventListeners: removeEventListeners,
5122
5123
// Facility for persisting and restoring the presentation state
5124
getState: getState,
5125
setState: setState,
5126
5127
// Presentation progress
5128
getSlidePastCount: getSlidePastCount,
5129
5130
// Presentation progress on range of 0-1
5131
getProgress: getProgress,
5132
5133
// Returns the indices of the current, or specified, slide
5134
getIndices: getIndices,
5135
5136
// Returns an Array of all slides
5137
getSlides: getSlides,
5138
5139
// Returns the total number of slides
5140
getTotalSlides: getTotalSlides,
5141
5142
// Returns the slide element at the specified index
5143
getSlide: getSlide,
5144
5145
// Returns the slide background element at the specified index
5146
getSlideBackground: getSlideBackground,
5147
5148
// Returns the speaker notes string for a slide, or null
5149
getSlideNotes: getSlideNotes,
5150
5151
// Returns the previous slide element, may be null
5152
getPreviousSlide: function() {
5153
return previousSlide;
5154
},
5155
5156
// Returns the current slide element
5157
getCurrentSlide: function() {
5158
return currentSlide;
5159
},
5160
5161
// Returns the current scale of the presentation content
5162
getScale: function() {
5163
return scale;
5164
},
5165
5166
// Returns the current configuration object
5167
getConfig: function() {
5168
return config;
5169
},
5170
5171
// Helper method, retrieves query string as a key/value hash
5172
getQueryHash: function() {
5173
var query = {};
5174
5175
location.search.replace( /[A-Z0-9]+?=([\w\.%-]*)/gi, function(a) {
5176
query[ a.split( '=' ).shift() ] = a.split( '=' ).pop();
5177
} );
5178
5179
// Basic deserialization
5180
for( var i in query ) {
5181
var value = query[ i ];
5182
5183
query[ i ] = deserialize( unescape( value ) );
5184
}
5185
5186
return query;
5187
},
5188
5189
// Returns true if we're currently on the first slide
5190
isFirstSlide: function() {
5191
return ( indexh === 0 && indexv === 0 );
5192
},
5193
5194
// Returns true if we're currently on the last slide
5195
isLastSlide: function() {
5196
if( currentSlide ) {
5197
// Does this slide has next a sibling?
5198
if( currentSlide.nextElementSibling ) return false;
5199
5200
// If it's vertical, does its parent have a next sibling?
5201
if( isVerticalSlide( currentSlide ) && currentSlide.parentNode.nextElementSibling ) return false;
5202
5203
return true;
5204
}
5205
5206
return false;
5207
},
5208
5209
// Checks if reveal.js has been loaded and is ready for use
5210
isReady: function() {
5211
return loaded;
5212
},
5213
5214
// Forward event binding to the reveal DOM element
5215
addEventListener: function( type, listener, useCapture ) {
5216
if( 'addEventListener' in window ) {
5217
( dom.wrapper || document.querySelector( '.reveal' ) ).addEventListener( type, listener, useCapture );
5218
}
5219
},
5220
removeEventListener: function( type, listener, useCapture ) {
5221
if( 'addEventListener' in window ) {
5222
( dom.wrapper || document.querySelector( '.reveal' ) ).removeEventListener( type, listener, useCapture );
5223
}
5224
},
5225
5226
// Programatically triggers a keyboard event
5227
triggerKey: function( keyCode ) {
5228
onDocumentKeyDown( { keyCode: keyCode } );
5229
},
5230
5231
// Registers a new shortcut to include in the help overlay
5232
registerKeyboardShortcut: function( key, value ) {
5233
keyboardShortcuts[key] = value;
5234
}
5235
};
5236
5237
return Reveal;
5238
5239
}));
5240
5241