Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 1 | import SlideContent from './controllers/slidecontent.js' |
| 2 | import SlideNumber from './controllers/slidenumber.js' |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 3 | import JumpToSlide from './controllers/jumptoslide.js' |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 4 | import Backgrounds from './controllers/backgrounds.js' |
| 5 | import AutoAnimate from './controllers/autoanimate.js' |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 6 | import ScrollView from './controllers/scrollview.js' |
| 7 | import PrintView from './controllers/printview.js' |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 8 | import Fragments from './controllers/fragments.js' |
| 9 | import Overview from './controllers/overview.js' |
| 10 | import Keyboard from './controllers/keyboard.js' |
| 11 | import Location from './controllers/location.js' |
| 12 | import Controls from './controllers/controls.js' |
| 13 | import Progress from './controllers/progress.js' |
| 14 | import Pointer from './controllers/pointer.js' |
| 15 | import Plugins from './controllers/plugins.js' |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 16 | import Touch from './controllers/touch.js' |
| 17 | import Focus from './controllers/focus.js' |
| 18 | import Notes from './controllers/notes.js' |
| 19 | import Playback from './components/playback.js' |
| 20 | import defaultConfig from './config.js' |
| 21 | import * as Util from './utils/util.js' |
| 22 | import * as Device from './utils/device.js' |
| 23 | import { |
| 24 | SLIDES_SELECTOR, |
| 25 | HORIZONTAL_SLIDES_SELECTOR, |
| 26 | VERTICAL_SLIDES_SELECTOR, |
| 27 | POST_MESSAGE_METHOD_BLACKLIST |
| 28 | } from './utils/constants.js' |
| 29 | |
| 30 | // The reveal.js version |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 31 | export const VERSION = '5.1.0'; |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * reveal.js |
| 35 | * https://revealjs.com |
| 36 | * MIT licensed |
| 37 | * |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 38 | * Copyright (C) 2011-2022 Hakim El Hattab, https://hakim.se |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 39 | */ |
| 40 | export default function( revealElement, options ) { |
| 41 | |
| 42 | // Support initialization with no args, one arg |
| 43 | // [options] or two args [revealElement, options] |
| 44 | if( arguments.length < 2 ) { |
| 45 | options = arguments[0]; |
| 46 | revealElement = document.querySelector( '.reveal' ); |
| 47 | } |
| 48 | |
| 49 | const Reveal = {}; |
| 50 | |
| 51 | // Configuration defaults, can be overridden at initialization time |
| 52 | let config = {}, |
| 53 | |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 54 | // Flags if initialize() has been invoked for this reveal instance |
| 55 | initialized = false, |
| 56 | |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 57 | // Flags if reveal.js is loaded (has dispatched the 'ready' event) |
| 58 | ready = false, |
| 59 | |
| 60 | // The horizontal and vertical index of the currently active slide |
| 61 | indexh, |
| 62 | indexv, |
| 63 | |
| 64 | // The previous and current slide HTML elements |
| 65 | previousSlide, |
| 66 | currentSlide, |
| 67 | |
| 68 | // Remember which directions that the user has navigated towards |
| 69 | navigationHistory = { |
| 70 | hasNavigatedHorizontally: false, |
| 71 | hasNavigatedVertically: false |
| 72 | }, |
| 73 | |
| 74 | // Slides may have a data-state attribute which we pick up and apply |
| 75 | // as a class to the body. This list contains the combined state of |
| 76 | // all current slides. |
| 77 | state = [], |
| 78 | |
| 79 | // The current scale of the presentation (see width/height config) |
| 80 | scale = 1, |
| 81 | |
| 82 | // CSS transform that is currently applied to the slides container, |
| 83 | // split into two groups |
| 84 | slidesTransform = { layout: '', overview: '' }, |
| 85 | |
| 86 | // Cached references to DOM elements |
| 87 | dom = {}, |
| 88 | |
| 89 | // Flags if the interaction event listeners are bound |
| 90 | eventsAreBound = false, |
| 91 | |
| 92 | // The current slide transition state; idle or running |
| 93 | transition = 'idle', |
| 94 | |
| 95 | // The current auto-slide duration |
| 96 | autoSlide = 0, |
| 97 | |
| 98 | // Auto slide properties |
| 99 | autoSlidePlayer, |
| 100 | autoSlideTimeout = 0, |
| 101 | autoSlideStartTime = -1, |
| 102 | autoSlidePaused = false, |
| 103 | |
| 104 | // Controllers for different aspects of our presentation. They're |
| 105 | // all given direct references to this Reveal instance since there |
| 106 | // may be multiple presentations running in parallel. |
| 107 | slideContent = new SlideContent( Reveal ), |
| 108 | slideNumber = new SlideNumber( Reveal ), |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 109 | jumpToSlide = new JumpToSlide( Reveal ), |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 110 | autoAnimate = new AutoAnimate( Reveal ), |
| 111 | backgrounds = new Backgrounds( Reveal ), |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 112 | scrollView = new ScrollView( Reveal ), |
| 113 | printView = new PrintView( Reveal ), |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 114 | fragments = new Fragments( Reveal ), |
| 115 | overview = new Overview( Reveal ), |
| 116 | keyboard = new Keyboard( Reveal ), |
| 117 | location = new Location( Reveal ), |
| 118 | controls = new Controls( Reveal ), |
| 119 | progress = new Progress( Reveal ), |
| 120 | pointer = new Pointer( Reveal ), |
| 121 | plugins = new Plugins( Reveal ), |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 122 | focus = new Focus( Reveal ), |
| 123 | touch = new Touch( Reveal ), |
| 124 | notes = new Notes( Reveal ); |
| 125 | |
| 126 | /** |
| 127 | * Starts up the presentation. |
| 128 | */ |
| 129 | function initialize( initOptions ) { |
| 130 | |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 131 | if( !revealElement ) throw 'Unable to find presentation root (<div class="reveal">).'; |
| 132 | |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 133 | initialized = true; |
| 134 | |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 135 | // Cache references to key DOM elements |
| 136 | dom.wrapper = revealElement; |
| 137 | dom.slides = revealElement.querySelector( '.slides' ); |
| 138 | |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 139 | if( !dom.slides ) throw 'Unable to find slides container (<div class="slides">).'; |
| 140 | |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 141 | // Compose our config object in order of increasing precedence: |
| 142 | // 1. Default reveal.js options |
| 143 | // 2. Options provided via Reveal.configure() prior to |
| 144 | // initialization |
| 145 | // 3. Options passed to the Reveal constructor |
| 146 | // 4. Options passed to Reveal.initialize |
| 147 | // 5. Query params |
| 148 | config = { ...defaultConfig, ...config, ...options, ...initOptions, ...Util.getQueryHash() }; |
| 149 | |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 150 | // Legacy support for the ?print-pdf query |
| 151 | if( /print-pdf/gi.test( window.location.search ) ) { |
| 152 | config.view = 'print'; |
| 153 | } |
| 154 | |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 155 | setViewport(); |
| 156 | |
| 157 | // Force a layout when the whole page, incl fonts, has loaded |
| 158 | window.addEventListener( 'load', layout, false ); |
| 159 | |
| 160 | // Register plugins and load dependencies, then move on to #start() |
| 161 | plugins.load( config.plugins, config.dependencies ).then( start ); |
| 162 | |
| 163 | return new Promise( resolve => Reveal.on( 'ready', resolve ) ); |
| 164 | |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Encase the presentation in a reveal.js viewport. The |
| 169 | * extent of the viewport differs based on configuration. |
| 170 | */ |
| 171 | function setViewport() { |
| 172 | |
| 173 | // Embedded decks use the reveal element as their viewport |
| 174 | if( config.embedded === true ) { |
| 175 | dom.viewport = Util.closest( revealElement, '.reveal-viewport' ) || revealElement; |
| 176 | } |
| 177 | // Full-page decks use the body as their viewport |
| 178 | else { |
| 179 | dom.viewport = document.body; |
| 180 | document.documentElement.classList.add( 'reveal-full-page' ); |
| 181 | } |
| 182 | |
| 183 | dom.viewport.classList.add( 'reveal-viewport' ); |
| 184 | |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Starts up reveal.js by binding input events and navigating |
| 189 | * to the current URL deeplink if there is one. |
| 190 | */ |
| 191 | function start() { |
| 192 | |
| 193 | ready = true; |
| 194 | |
| 195 | // Remove slides hidden with data-visibility |
| 196 | removeHiddenSlides(); |
| 197 | |
| 198 | // Make sure we've got all the DOM elements we need |
| 199 | setupDOM(); |
| 200 | |
| 201 | // Listen to messages posted to this window |
| 202 | setupPostMessage(); |
| 203 | |
| 204 | // Prevent the slides from being scrolled out of view |
| 205 | setupScrollPrevention(); |
| 206 | |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 207 | // Adds bindings for fullscreen mode |
| 208 | setupFullscreen(); |
| 209 | |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 210 | // Resets all vertical slides so that only the first is visible |
| 211 | resetVerticalSlides(); |
| 212 | |
| 213 | // Updates the presentation to match the current configuration values |
| 214 | configure(); |
| 215 | |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 216 | // Create slide backgrounds |
| 217 | backgrounds.update( true ); |
| 218 | |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 219 | // Activate the print/scroll view if configured |
| 220 | activateInitialView(); |
| 221 | |
| 222 | // Read the initial hash |
| 223 | location.readURL(); |
| 224 | |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 225 | // Notify listeners that the presentation is ready but use a 1ms |
| 226 | // timeout to ensure it's not fired synchronously after #initialize() |
| 227 | setTimeout( () => { |
| 228 | // Enable transitions now that we're loaded |
| 229 | dom.slides.classList.remove( 'no-transition' ); |
| 230 | |
| 231 | dom.wrapper.classList.add( 'ready' ); |
| 232 | |
| 233 | dispatchEvent({ |
| 234 | type: 'ready', |
| 235 | data: { |
| 236 | indexh, |
| 237 | indexv, |
| 238 | currentSlide |
| 239 | } |
| 240 | }); |
| 241 | }, 1 ); |
| 242 | |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 243 | } |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 244 | |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 245 | /** |
| 246 | * Activates the correct reveal.js view based on our config. |
| 247 | * This is only invoked once during initialization. |
| 248 | */ |
| 249 | function activateInitialView() { |
| 250 | |
| 251 | const activatePrintView = config.view === 'print'; |
| 252 | const activateScrollView = config.view === 'scroll' || config.view === 'reader'; |
| 253 | |
| 254 | if( activatePrintView || activateScrollView ) { |
| 255 | |
| 256 | if( activatePrintView ) { |
| 257 | removeEventListeners(); |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 258 | } |
| 259 | else { |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 260 | touch.unbind(); |
| 261 | } |
| 262 | |
| 263 | // Avoid content flickering during layout |
| 264 | dom.viewport.classList.add( 'loading-scroll-mode' ); |
| 265 | |
| 266 | if( activatePrintView ) { |
| 267 | // The document needs to have loaded for the PDF layout |
| 268 | // measurements to be accurate |
| 269 | if( document.readyState === 'complete' ) { |
| 270 | printView.activate(); |
| 271 | } |
| 272 | else { |
| 273 | window.addEventListener( 'load', () => printView.activate() ); |
| 274 | } |
| 275 | } |
| 276 | else { |
| 277 | scrollView.activate(); |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 278 | } |
| 279 | } |
| 280 | |
| 281 | } |
| 282 | |
| 283 | /** |
| 284 | * Removes all slides with data-visibility="hidden". This |
| 285 | * is done right before the rest of the presentation is |
| 286 | * initialized. |
| 287 | * |
| 288 | * If you want to show all hidden slides, initialize |
| 289 | * reveal.js with showHiddenSlides set to true. |
| 290 | */ |
| 291 | function removeHiddenSlides() { |
| 292 | |
| 293 | if( !config.showHiddenSlides ) { |
| 294 | Util.queryAll( dom.wrapper, 'section[data-visibility="hidden"]' ).forEach( slide => { |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 295 | const parent = slide.parentNode; |
| 296 | |
| 297 | // If this slide is part of a stack and that stack will be |
| 298 | // empty after removing the hidden slide, remove the entire |
| 299 | // stack |
| 300 | if( parent.childElementCount === 1 && /section/i.test( parent.nodeName ) ) { |
| 301 | parent.remove(); |
| 302 | } |
| 303 | else { |
| 304 | slide.remove(); |
| 305 | } |
| 306 | |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 307 | } ); |
| 308 | } |
| 309 | |
| 310 | } |
| 311 | |
| 312 | /** |
| 313 | * Finds and stores references to DOM elements which are |
| 314 | * required by the presentation. If a required element is |
| 315 | * not found, it is created. |
| 316 | */ |
| 317 | function setupDOM() { |
| 318 | |
| 319 | // Prevent transitions while we're loading |
| 320 | dom.slides.classList.add( 'no-transition' ); |
| 321 | |
| 322 | if( Device.isMobile ) { |
| 323 | dom.wrapper.classList.add( 'no-hover' ); |
| 324 | } |
| 325 | else { |
| 326 | dom.wrapper.classList.remove( 'no-hover' ); |
| 327 | } |
| 328 | |
| 329 | backgrounds.render(); |
| 330 | slideNumber.render(); |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 331 | jumpToSlide.render(); |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 332 | controls.render(); |
| 333 | progress.render(); |
| 334 | notes.render(); |
| 335 | |
| 336 | // Overlay graphic which is displayed during the paused mode |
| 337 | dom.pauseOverlay = Util.createSingletonNode( dom.wrapper, 'div', 'pause-overlay', config.controls ? '<button class="resume-button">Resume presentation</button>' : null ); |
| 338 | |
| 339 | dom.statusElement = createStatusElement(); |
| 340 | |
| 341 | dom.wrapper.setAttribute( 'role', 'application' ); |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * Creates a hidden div with role aria-live to announce the |
| 346 | * current slide content. Hide the div off-screen to make it |
| 347 | * available only to Assistive Technologies. |
| 348 | * |
| 349 | * @return {HTMLElement} |
| 350 | */ |
| 351 | function createStatusElement() { |
| 352 | |
| 353 | let statusElement = dom.wrapper.querySelector( '.aria-status' ); |
| 354 | if( !statusElement ) { |
| 355 | statusElement = document.createElement( 'div' ); |
| 356 | statusElement.style.position = 'absolute'; |
| 357 | statusElement.style.height = '1px'; |
| 358 | statusElement.style.width = '1px'; |
| 359 | statusElement.style.overflow = 'hidden'; |
| 360 | statusElement.style.clip = 'rect( 1px, 1px, 1px, 1px )'; |
| 361 | statusElement.classList.add( 'aria-status' ); |
| 362 | statusElement.setAttribute( 'aria-live', 'polite' ); |
| 363 | statusElement.setAttribute( 'aria-atomic','true' ); |
| 364 | dom.wrapper.appendChild( statusElement ); |
| 365 | } |
| 366 | return statusElement; |
| 367 | |
| 368 | } |
| 369 | |
| 370 | /** |
| 371 | * Announces the given text to screen readers. |
| 372 | */ |
| 373 | function announceStatus( value ) { |
| 374 | |
| 375 | dom.statusElement.textContent = value; |
| 376 | |
| 377 | } |
| 378 | |
| 379 | /** |
| 380 | * Converts the given HTML element into a string of text |
| 381 | * that can be announced to a screen reader. Hidden |
| 382 | * elements are excluded. |
| 383 | */ |
| 384 | function getStatusText( node ) { |
| 385 | |
| 386 | let text = ''; |
| 387 | |
| 388 | // Text node |
| 389 | if( node.nodeType === 3 ) { |
| 390 | text += node.textContent; |
| 391 | } |
| 392 | // Element node |
| 393 | else if( node.nodeType === 1 ) { |
| 394 | |
| 395 | let isAriaHidden = node.getAttribute( 'aria-hidden' ); |
| 396 | let isDisplayHidden = window.getComputedStyle( node )['display'] === 'none'; |
| 397 | if( isAriaHidden !== 'true' && !isDisplayHidden ) { |
| 398 | |
| 399 | Array.from( node.childNodes ).forEach( child => { |
| 400 | text += getStatusText( child ); |
| 401 | } ); |
| 402 | |
| 403 | } |
| 404 | |
| 405 | } |
| 406 | |
| 407 | text = text.trim(); |
| 408 | |
| 409 | return text === '' ? '' : text + ' '; |
| 410 | |
| 411 | } |
| 412 | |
| 413 | /** |
| 414 | * This is an unfortunate necessity. Some actions – such as |
| 415 | * an input field being focused in an iframe or using the |
| 416 | * keyboard to expand text selection beyond the bounds of |
| 417 | * a slide – can trigger our content to be pushed out of view. |
| 418 | * This scrolling can not be prevented by hiding overflow in |
| 419 | * CSS (we already do) so we have to resort to repeatedly |
| 420 | * checking if the slides have been offset :( |
| 421 | */ |
| 422 | function setupScrollPrevention() { |
| 423 | |
| 424 | setInterval( () => { |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 425 | if( !scrollView.isActive() && dom.wrapper.scrollTop !== 0 || dom.wrapper.scrollLeft !== 0 ) { |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 426 | dom.wrapper.scrollTop = 0; |
| 427 | dom.wrapper.scrollLeft = 0; |
| 428 | } |
| 429 | }, 1000 ); |
| 430 | |
| 431 | } |
| 432 | |
| 433 | /** |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 434 | * After entering fullscreen we need to force a layout to |
| 435 | * get our presentations to scale correctly. This behavior |
| 436 | * is inconsistent across browsers but a force layout seems |
| 437 | * to normalize it. |
| 438 | */ |
| 439 | function setupFullscreen() { |
| 440 | |
| 441 | document.addEventListener( 'fullscreenchange', onFullscreenChange ); |
| 442 | document.addEventListener( 'webkitfullscreenchange', onFullscreenChange ); |
| 443 | |
| 444 | } |
| 445 | |
| 446 | /** |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 447 | * Registers a listener to postMessage events, this makes it |
| 448 | * possible to call all reveal.js API methods from another |
| 449 | * window. For example: |
| 450 | * |
| 451 | * revealWindow.postMessage( JSON.stringify({ |
| 452 | * method: 'slide', |
| 453 | * args: [ 2 ] |
| 454 | * }), '*' ); |
| 455 | */ |
| 456 | function setupPostMessage() { |
| 457 | |
| 458 | if( config.postMessage ) { |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 459 | window.addEventListener( 'message', onPostMessage, false ); |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | } |
| 463 | |
| 464 | /** |
| 465 | * Applies the configuration settings from the config |
| 466 | * object. May be called multiple times. |
| 467 | * |
| 468 | * @param {object} options |
| 469 | */ |
| 470 | function configure( options ) { |
| 471 | |
| 472 | const oldConfig = { ...config } |
| 473 | |
| 474 | // New config options may be passed when this method |
| 475 | // is invoked through the API after initialization |
| 476 | if( typeof options === 'object' ) Util.extend( config, options ); |
| 477 | |
| 478 | // Abort if reveal.js hasn't finished loading, config |
| 479 | // changes will be applied automatically once ready |
| 480 | if( Reveal.isReady() === false ) return; |
| 481 | |
| 482 | const numberOfSlides = dom.wrapper.querySelectorAll( SLIDES_SELECTOR ).length; |
| 483 | |
| 484 | // The transition is added as a class on the .reveal element |
| 485 | dom.wrapper.classList.remove( oldConfig.transition ); |
| 486 | dom.wrapper.classList.add( config.transition ); |
| 487 | |
| 488 | dom.wrapper.setAttribute( 'data-transition-speed', config.transitionSpeed ); |
| 489 | dom.wrapper.setAttribute( 'data-background-transition', config.backgroundTransition ); |
| 490 | |
| 491 | // Expose our configured slide dimensions as custom props |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 492 | dom.viewport.style.setProperty( '--slide-width', typeof config.width === 'string' ? config.width : config.width + 'px' ); |
| 493 | dom.viewport.style.setProperty( '--slide-height', typeof config.height === 'string' ? config.height : config.height + 'px' ); |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 494 | |
| 495 | if( config.shuffle ) { |
| 496 | shuffle(); |
| 497 | } |
| 498 | |
| 499 | Util.toggleClass( dom.wrapper, 'embedded', config.embedded ); |
| 500 | Util.toggleClass( dom.wrapper, 'rtl', config.rtl ); |
| 501 | Util.toggleClass( dom.wrapper, 'center', config.center ); |
| 502 | |
| 503 | // Exit the paused mode if it was configured off |
| 504 | if( config.pause === false ) { |
| 505 | resume(); |
| 506 | } |
| 507 | |
| 508 | // Iframe link previews |
| 509 | if( config.previewLinks ) { |
| 510 | enablePreviewLinks(); |
| 511 | disablePreviewLinks( '[data-preview-link=false]' ); |
| 512 | } |
| 513 | else { |
| 514 | disablePreviewLinks(); |
| 515 | enablePreviewLinks( '[data-preview-link]:not([data-preview-link=false])' ); |
| 516 | } |
| 517 | |
| 518 | // Reset all changes made by auto-animations |
| 519 | autoAnimate.reset(); |
| 520 | |
| 521 | // Remove existing auto-slide controls |
| 522 | if( autoSlidePlayer ) { |
| 523 | autoSlidePlayer.destroy(); |
| 524 | autoSlidePlayer = null; |
| 525 | } |
| 526 | |
| 527 | // Generate auto-slide controls if needed |
| 528 | if( numberOfSlides > 1 && config.autoSlide && config.autoSlideStoppable ) { |
| 529 | autoSlidePlayer = new Playback( dom.wrapper, () => { |
| 530 | return Math.min( Math.max( ( Date.now() - autoSlideStartTime ) / autoSlide, 0 ), 1 ); |
| 531 | } ); |
| 532 | |
| 533 | autoSlidePlayer.on( 'click', onAutoSlidePlayerClick ); |
| 534 | autoSlidePaused = false; |
| 535 | } |
| 536 | |
| 537 | // Add the navigation mode to the DOM so we can adjust styling |
| 538 | if( config.navigationMode !== 'default' ) { |
| 539 | dom.wrapper.setAttribute( 'data-navigation-mode', config.navigationMode ); |
| 540 | } |
| 541 | else { |
| 542 | dom.wrapper.removeAttribute( 'data-navigation-mode' ); |
| 543 | } |
| 544 | |
| 545 | notes.configure( config, oldConfig ); |
| 546 | focus.configure( config, oldConfig ); |
| 547 | pointer.configure( config, oldConfig ); |
| 548 | controls.configure( config, oldConfig ); |
| 549 | progress.configure( config, oldConfig ); |
| 550 | keyboard.configure( config, oldConfig ); |
| 551 | fragments.configure( config, oldConfig ); |
| 552 | slideNumber.configure( config, oldConfig ); |
| 553 | |
| 554 | sync(); |
| 555 | |
| 556 | } |
| 557 | |
| 558 | /** |
| 559 | * Binds all event listeners. |
| 560 | */ |
| 561 | function addEventListeners() { |
| 562 | |
| 563 | eventsAreBound = true; |
| 564 | |
| 565 | window.addEventListener( 'resize', onWindowResize, false ); |
| 566 | |
| 567 | if( config.touch ) touch.bind(); |
| 568 | if( config.keyboard ) keyboard.bind(); |
| 569 | if( config.progress ) progress.bind(); |
| 570 | if( config.respondToHashChanges ) location.bind(); |
| 571 | controls.bind(); |
| 572 | focus.bind(); |
| 573 | |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 574 | dom.slides.addEventListener( 'click', onSlidesClicked, false ); |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 575 | dom.slides.addEventListener( 'transitionend', onTransitionEnd, false ); |
| 576 | dom.pauseOverlay.addEventListener( 'click', resume, false ); |
| 577 | |
| 578 | if( config.focusBodyOnPageVisibilityChange ) { |
| 579 | document.addEventListener( 'visibilitychange', onPageVisibilityChange, false ); |
| 580 | } |
| 581 | |
| 582 | } |
| 583 | |
| 584 | /** |
| 585 | * Unbinds all event listeners. |
| 586 | */ |
| 587 | function removeEventListeners() { |
| 588 | |
| 589 | eventsAreBound = false; |
| 590 | |
| 591 | touch.unbind(); |
| 592 | focus.unbind(); |
| 593 | keyboard.unbind(); |
| 594 | controls.unbind(); |
| 595 | progress.unbind(); |
| 596 | location.unbind(); |
| 597 | |
| 598 | window.removeEventListener( 'resize', onWindowResize, false ); |
| 599 | |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 600 | dom.slides.removeEventListener( 'click', onSlidesClicked, false ); |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 601 | dom.slides.removeEventListener( 'transitionend', onTransitionEnd, false ); |
| 602 | dom.pauseOverlay.removeEventListener( 'click', resume, false ); |
| 603 | |
| 604 | } |
| 605 | |
| 606 | /** |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 607 | * Uninitializes reveal.js by undoing changes made to the |
| 608 | * DOM and removing all event listeners. |
| 609 | */ |
| 610 | function destroy() { |
| 611 | |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 612 | // There's nothing to destroy if this instance hasn't been |
| 613 | // initialized yet |
| 614 | if( initialized === false ) return; |
| 615 | |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 616 | removeEventListeners(); |
| 617 | cancelAutoSlide(); |
| 618 | disablePreviewLinks(); |
| 619 | |
| 620 | // Destroy controllers |
| 621 | notes.destroy(); |
| 622 | focus.destroy(); |
| 623 | plugins.destroy(); |
| 624 | pointer.destroy(); |
| 625 | controls.destroy(); |
| 626 | progress.destroy(); |
| 627 | backgrounds.destroy(); |
| 628 | slideNumber.destroy(); |
| 629 | jumpToSlide.destroy(); |
| 630 | |
| 631 | // Remove event listeners |
| 632 | document.removeEventListener( 'fullscreenchange', onFullscreenChange ); |
| 633 | document.removeEventListener( 'webkitfullscreenchange', onFullscreenChange ); |
| 634 | document.removeEventListener( 'visibilitychange', onPageVisibilityChange, false ); |
| 635 | window.removeEventListener( 'message', onPostMessage, false ); |
| 636 | window.removeEventListener( 'load', layout, false ); |
| 637 | |
| 638 | // Undo DOM changes |
| 639 | if( dom.pauseOverlay ) dom.pauseOverlay.remove(); |
| 640 | if( dom.statusElement ) dom.statusElement.remove(); |
| 641 | |
| 642 | document.documentElement.classList.remove( 'reveal-full-page' ); |
| 643 | |
| 644 | dom.wrapper.classList.remove( 'ready', 'center', 'has-horizontal-slides', 'has-vertical-slides' ); |
| 645 | dom.wrapper.removeAttribute( 'data-transition-speed' ); |
| 646 | dom.wrapper.removeAttribute( 'data-background-transition' ); |
| 647 | |
| 648 | dom.viewport.classList.remove( 'reveal-viewport' ); |
| 649 | dom.viewport.style.removeProperty( '--slide-width' ); |
| 650 | dom.viewport.style.removeProperty( '--slide-height' ); |
| 651 | |
| 652 | dom.slides.style.removeProperty( 'width' ); |
| 653 | dom.slides.style.removeProperty( 'height' ); |
| 654 | dom.slides.style.removeProperty( 'zoom' ); |
| 655 | dom.slides.style.removeProperty( 'left' ); |
| 656 | dom.slides.style.removeProperty( 'top' ); |
| 657 | dom.slides.style.removeProperty( 'bottom' ); |
| 658 | dom.slides.style.removeProperty( 'right' ); |
| 659 | dom.slides.style.removeProperty( 'transform' ); |
| 660 | |
| 661 | Array.from( dom.wrapper.querySelectorAll( SLIDES_SELECTOR ) ).forEach( slide => { |
| 662 | slide.style.removeProperty( 'display' ); |
| 663 | slide.style.removeProperty( 'top' ); |
| 664 | slide.removeAttribute( 'hidden' ); |
| 665 | slide.removeAttribute( 'aria-hidden' ); |
| 666 | } ); |
| 667 | |
| 668 | } |
| 669 | |
| 670 | /** |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 671 | * Adds a listener to one of our custom reveal.js events, |
| 672 | * like slidechanged. |
| 673 | */ |
| 674 | function on( type, listener, useCapture ) { |
| 675 | |
| 676 | revealElement.addEventListener( type, listener, useCapture ); |
| 677 | |
| 678 | } |
| 679 | |
| 680 | /** |
| 681 | * Unsubscribes from a reveal.js event. |
| 682 | */ |
| 683 | function off( type, listener, useCapture ) { |
| 684 | |
| 685 | revealElement.removeEventListener( type, listener, useCapture ); |
| 686 | |
| 687 | } |
| 688 | |
| 689 | /** |
| 690 | * Applies CSS transforms to the slides container. The container |
| 691 | * is transformed from two separate sources: layout and the overview |
| 692 | * mode. |
| 693 | * |
| 694 | * @param {object} transforms |
| 695 | */ |
| 696 | function transformSlides( transforms ) { |
| 697 | |
| 698 | // Pick up new transforms from arguments |
| 699 | if( typeof transforms.layout === 'string' ) slidesTransform.layout = transforms.layout; |
| 700 | if( typeof transforms.overview === 'string' ) slidesTransform.overview = transforms.overview; |
| 701 | |
| 702 | // Apply the transforms to the slides container |
| 703 | if( slidesTransform.layout ) { |
| 704 | Util.transformElement( dom.slides, slidesTransform.layout + ' ' + slidesTransform.overview ); |
| 705 | } |
| 706 | else { |
| 707 | Util.transformElement( dom.slides, slidesTransform.overview ); |
| 708 | } |
| 709 | |
| 710 | } |
| 711 | |
| 712 | /** |
| 713 | * Dispatches an event of the specified type from the |
| 714 | * reveal DOM element. |
| 715 | */ |
| 716 | function dispatchEvent({ target=dom.wrapper, type, data, bubbles=true }) { |
| 717 | |
| 718 | let event = document.createEvent( 'HTMLEvents', 1, 2 ); |
| 719 | event.initEvent( type, bubbles, true ); |
| 720 | Util.extend( event, data ); |
| 721 | target.dispatchEvent( event ); |
| 722 | |
| 723 | if( target === dom.wrapper ) { |
| 724 | // If we're in an iframe, post each reveal.js event to the |
| 725 | // parent window. Used by the notes plugin |
| 726 | dispatchPostMessage( type ); |
| 727 | } |
| 728 | |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 729 | return event; |
| 730 | |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | /** |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 734 | * Dispatches a slidechanged event. |
| 735 | * |
| 736 | * @param {string} origin Used to identify multiplex clients |
| 737 | */ |
| 738 | function dispatchSlideChanged( origin ) { |
| 739 | |
| 740 | dispatchEvent({ |
| 741 | type: 'slidechanged', |
| 742 | data: { |
| 743 | indexh, |
| 744 | indexv, |
| 745 | previousSlide, |
| 746 | currentSlide, |
| 747 | origin |
| 748 | } |
| 749 | }); |
| 750 | |
| 751 | } |
| 752 | |
| 753 | /** |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 754 | * Dispatched a postMessage of the given type from our window. |
| 755 | */ |
| 756 | function dispatchPostMessage( type, data ) { |
| 757 | |
| 758 | if( config.postMessageEvents && window.parent !== window.self ) { |
| 759 | let message = { |
| 760 | namespace: 'reveal', |
| 761 | eventName: type, |
| 762 | state: getState() |
| 763 | }; |
| 764 | |
| 765 | Util.extend( message, data ); |
| 766 | |
| 767 | window.parent.postMessage( JSON.stringify( message ), '*' ); |
| 768 | } |
| 769 | |
| 770 | } |
| 771 | |
| 772 | /** |
| 773 | * Bind preview frame links. |
| 774 | * |
| 775 | * @param {string} [selector=a] - selector for anchors |
| 776 | */ |
| 777 | function enablePreviewLinks( selector = 'a' ) { |
| 778 | |
| 779 | Array.from( dom.wrapper.querySelectorAll( selector ) ).forEach( element => { |
| 780 | if( /^(http|www)/gi.test( element.getAttribute( 'href' ) ) ) { |
| 781 | element.addEventListener( 'click', onPreviewLinkClicked, false ); |
| 782 | } |
| 783 | } ); |
| 784 | |
| 785 | } |
| 786 | |
| 787 | /** |
| 788 | * Unbind preview frame links. |
| 789 | */ |
| 790 | function disablePreviewLinks( selector = 'a' ) { |
| 791 | |
| 792 | Array.from( dom.wrapper.querySelectorAll( selector ) ).forEach( element => { |
| 793 | if( /^(http|www)/gi.test( element.getAttribute( 'href' ) ) ) { |
| 794 | element.removeEventListener( 'click', onPreviewLinkClicked, false ); |
| 795 | } |
| 796 | } ); |
| 797 | |
| 798 | } |
| 799 | |
| 800 | /** |
| 801 | * Opens a preview window for the target URL. |
| 802 | * |
| 803 | * @param {string} url - url for preview iframe src |
| 804 | */ |
| 805 | function showPreview( url ) { |
| 806 | |
| 807 | closeOverlay(); |
| 808 | |
| 809 | dom.overlay = document.createElement( 'div' ); |
| 810 | dom.overlay.classList.add( 'overlay' ); |
| 811 | dom.overlay.classList.add( 'overlay-preview' ); |
| 812 | dom.wrapper.appendChild( dom.overlay ); |
| 813 | |
| 814 | dom.overlay.innerHTML = |
| 815 | `<header> |
| 816 | <a class="close" href="#"><span class="icon"></span></a> |
| 817 | <a class="external" href="${url}" target="_blank"><span class="icon"></span></a> |
| 818 | </header> |
| 819 | <div class="spinner"></div> |
| 820 | <div class="viewport"> |
| 821 | <iframe src="${url}"></iframe> |
| 822 | <small class="viewport-inner"> |
| 823 | <span class="x-frame-error">Unable to load iframe. This is likely due to the site's policy (x-frame-options).</span> |
| 824 | </small> |
| 825 | </div>`; |
| 826 | |
| 827 | dom.overlay.querySelector( 'iframe' ).addEventListener( 'load', event => { |
| 828 | dom.overlay.classList.add( 'loaded' ); |
| 829 | }, false ); |
| 830 | |
| 831 | dom.overlay.querySelector( '.close' ).addEventListener( 'click', event => { |
| 832 | closeOverlay(); |
| 833 | event.preventDefault(); |
| 834 | }, false ); |
| 835 | |
| 836 | dom.overlay.querySelector( '.external' ).addEventListener( 'click', event => { |
| 837 | closeOverlay(); |
| 838 | }, false ); |
| 839 | |
| 840 | } |
| 841 | |
| 842 | /** |
| 843 | * Open or close help overlay window. |
| 844 | * |
| 845 | * @param {Boolean} [override] Flag which overrides the |
| 846 | * toggle logic and forcibly sets the desired state. True means |
| 847 | * help is open, false means it's closed. |
| 848 | */ |
| 849 | function toggleHelp( override ){ |
| 850 | |
| 851 | if( typeof override === 'boolean' ) { |
| 852 | override ? showHelp() : closeOverlay(); |
| 853 | } |
| 854 | else { |
| 855 | if( dom.overlay ) { |
| 856 | closeOverlay(); |
| 857 | } |
| 858 | else { |
| 859 | showHelp(); |
| 860 | } |
| 861 | } |
| 862 | } |
| 863 | |
| 864 | /** |
| 865 | * Opens an overlay window with help material. |
| 866 | */ |
| 867 | function showHelp() { |
| 868 | |
| 869 | if( config.help ) { |
| 870 | |
| 871 | closeOverlay(); |
| 872 | |
| 873 | dom.overlay = document.createElement( 'div' ); |
| 874 | dom.overlay.classList.add( 'overlay' ); |
| 875 | dom.overlay.classList.add( 'overlay-help' ); |
| 876 | dom.wrapper.appendChild( dom.overlay ); |
| 877 | |
| 878 | let html = '<p class="title">Keyboard Shortcuts</p><br/>'; |
| 879 | |
| 880 | let shortcuts = keyboard.getShortcuts(), |
| 881 | bindings = keyboard.getBindings(); |
| 882 | |
| 883 | html += '<table><th>KEY</th><th>ACTION</th>'; |
| 884 | for( let key in shortcuts ) { |
| 885 | html += `<tr><td>${key}</td><td>${shortcuts[ key ]}</td></tr>`; |
| 886 | } |
| 887 | |
| 888 | // Add custom key bindings that have associated descriptions |
| 889 | for( let binding in bindings ) { |
| 890 | if( bindings[binding].key && bindings[binding].description ) { |
| 891 | html += `<tr><td>${bindings[binding].key}</td><td>${bindings[binding].description}</td></tr>`; |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | html += '</table>'; |
| 896 | |
| 897 | dom.overlay.innerHTML = ` |
| 898 | <header> |
| 899 | <a class="close" href="#"><span class="icon"></span></a> |
| 900 | </header> |
| 901 | <div class="viewport"> |
| 902 | <div class="viewport-inner">${html}</div> |
| 903 | </div> |
| 904 | `; |
| 905 | |
| 906 | dom.overlay.querySelector( '.close' ).addEventListener( 'click', event => { |
| 907 | closeOverlay(); |
| 908 | event.preventDefault(); |
| 909 | }, false ); |
| 910 | |
| 911 | } |
| 912 | |
| 913 | } |
| 914 | |
| 915 | /** |
| 916 | * Closes any currently open overlay. |
| 917 | */ |
| 918 | function closeOverlay() { |
| 919 | |
| 920 | if( dom.overlay ) { |
| 921 | dom.overlay.parentNode.removeChild( dom.overlay ); |
| 922 | dom.overlay = null; |
| 923 | return true; |
| 924 | } |
| 925 | |
| 926 | return false; |
| 927 | |
| 928 | } |
| 929 | |
| 930 | /** |
| 931 | * Applies JavaScript-controlled layout rules to the |
| 932 | * presentation. |
| 933 | */ |
| 934 | function layout() { |
| 935 | |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 936 | if( dom.wrapper && !printView.isActive() ) { |
| 937 | |
| 938 | const viewportWidth = dom.viewport.offsetWidth; |
| 939 | const viewportHeight = dom.viewport.offsetHeight; |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 940 | |
| 941 | if( !config.disableLayout ) { |
| 942 | |
| 943 | // On some mobile devices '100vh' is taller than the visible |
| 944 | // viewport which leads to part of the presentation being |
| 945 | // cut off. To work around this we define our own '--vh' custom |
| 946 | // property where 100x adds up to the correct height. |
| 947 | // |
| 948 | // https://css-tricks.com/the-trick-to-viewport-units-on-mobile/ |
| 949 | if( Device.isMobile && !config.embedded ) { |
| 950 | document.documentElement.style.setProperty( '--vh', ( window.innerHeight * 0.01 ) + 'px' ); |
| 951 | } |
| 952 | |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 953 | const size = scrollView.isActive() ? |
| 954 | getComputedSlideSize( viewportWidth, viewportHeight ) : |
| 955 | getComputedSlideSize(); |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 956 | |
| 957 | const oldScale = scale; |
| 958 | |
| 959 | // Layout the contents of the slides |
| 960 | layoutSlideContents( config.width, config.height ); |
| 961 | |
| 962 | dom.slides.style.width = size.width + 'px'; |
| 963 | dom.slides.style.height = size.height + 'px'; |
| 964 | |
| 965 | // Determine scale of content to fit within available space |
| 966 | scale = Math.min( size.presentationWidth / size.width, size.presentationHeight / size.height ); |
| 967 | |
| 968 | // Respect max/min scale settings |
| 969 | scale = Math.max( scale, config.minScale ); |
| 970 | scale = Math.min( scale, config.maxScale ); |
| 971 | |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 972 | // Don't apply any scaling styles if scale is 1 or we're |
| 973 | // in the scroll view |
| 974 | if( scale === 1 || scrollView.isActive() ) { |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 975 | dom.slides.style.zoom = ''; |
| 976 | dom.slides.style.left = ''; |
| 977 | dom.slides.style.top = ''; |
| 978 | dom.slides.style.bottom = ''; |
| 979 | dom.slides.style.right = ''; |
| 980 | transformSlides( { layout: '' } ); |
| 981 | } |
| 982 | else { |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 983 | dom.slides.style.zoom = ''; |
| 984 | dom.slides.style.left = '50%'; |
| 985 | dom.slides.style.top = '50%'; |
| 986 | dom.slides.style.bottom = 'auto'; |
| 987 | dom.slides.style.right = 'auto'; |
| 988 | transformSlides( { layout: 'translate(-50%, -50%) scale('+ scale +')' } ); |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | // Select all slides, vertical and horizontal |
| 992 | const slides = Array.from( dom.wrapper.querySelectorAll( SLIDES_SELECTOR ) ); |
| 993 | |
| 994 | for( let i = 0, len = slides.length; i < len; i++ ) { |
| 995 | const slide = slides[ i ]; |
| 996 | |
| 997 | // Don't bother updating invisible slides |
| 998 | if( slide.style.display === 'none' ) { |
| 999 | continue; |
| 1000 | } |
| 1001 | |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 1002 | if( ( config.center || slide.classList.contains( 'center' ) ) ) { |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 1003 | // Vertical stacks are not centred since their section |
| 1004 | // children will be |
| 1005 | if( slide.classList.contains( 'stack' ) ) { |
| 1006 | slide.style.top = 0; |
| 1007 | } |
| 1008 | else { |
| 1009 | slide.style.top = Math.max( ( size.height - slide.scrollHeight ) / 2, 0 ) + 'px'; |
| 1010 | } |
| 1011 | } |
| 1012 | else { |
| 1013 | slide.style.top = ''; |
| 1014 | } |
| 1015 | |
| 1016 | } |
| 1017 | |
| 1018 | if( oldScale !== scale ) { |
| 1019 | dispatchEvent({ |
| 1020 | type: 'resize', |
| 1021 | data: { |
| 1022 | oldScale, |
| 1023 | scale, |
| 1024 | size |
| 1025 | } |
| 1026 | }); |
| 1027 | } |
| 1028 | } |
| 1029 | |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 1030 | checkResponsiveScrollView(); |
| 1031 | |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 1032 | dom.viewport.style.setProperty( '--slide-scale', scale ); |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 1033 | dom.viewport.style.setProperty( '--viewport-width', viewportWidth + 'px' ); |
| 1034 | dom.viewport.style.setProperty( '--viewport-height', viewportHeight + 'px' ); |
| 1035 | |
| 1036 | scrollView.layout(); |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 1037 | |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 1038 | progress.update(); |
| 1039 | backgrounds.updateParallax(); |
| 1040 | |
| 1041 | if( overview.isActive() ) { |
| 1042 | overview.update(); |
| 1043 | } |
| 1044 | |
| 1045 | } |
| 1046 | |
| 1047 | } |
| 1048 | |
| 1049 | /** |
| 1050 | * Applies layout logic to the contents of all slides in |
| 1051 | * the presentation. |
| 1052 | * |
| 1053 | * @param {string|number} width |
| 1054 | * @param {string|number} height |
| 1055 | */ |
| 1056 | function layoutSlideContents( width, height ) { |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 1057 | // Handle sizing of elements with the 'r-stretch' class |
| 1058 | Util.queryAll( dom.slides, 'section > .stretch, section > .r-stretch' ).forEach( element => { |
| 1059 | |
| 1060 | // Determine how much vertical space we can use |
| 1061 | let remainingHeight = Util.getRemainingHeight( element, height ); |
| 1062 | |
| 1063 | // Consider the aspect ratio of media elements |
| 1064 | if( /(img|video)/gi.test( element.nodeName ) ) { |
| 1065 | const nw = element.naturalWidth || element.videoWidth, |
| 1066 | nh = element.naturalHeight || element.videoHeight; |
| 1067 | |
| 1068 | const es = Math.min( width / nw, remainingHeight / nh ); |
| 1069 | |
| 1070 | element.style.width = ( nw * es ) + 'px'; |
| 1071 | element.style.height = ( nh * es ) + 'px'; |
| 1072 | |
| 1073 | } |
| 1074 | else { |
| 1075 | element.style.width = width + 'px'; |
| 1076 | element.style.height = remainingHeight + 'px'; |
| 1077 | } |
| 1078 | |
| 1079 | } ); |
| 1080 | |
| 1081 | } |
| 1082 | |
| 1083 | /** |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 1084 | * Responsively activates the scroll mode when we reach the configured |
| 1085 | * activation width. |
| 1086 | */ |
| 1087 | function checkResponsiveScrollView() { |
| 1088 | |
| 1089 | // Only proceed if... |
| 1090 | // 1. The DOM is ready |
| 1091 | // 2. Layouts aren't disabled via config |
| 1092 | // 3. We're not currently printing |
| 1093 | // 4. There is a scrollActivationWidth set |
| 1094 | // 5. The deck isn't configured to always use the scroll view |
| 1095 | if( |
| 1096 | dom.wrapper && |
| 1097 | !config.disableLayout && |
| 1098 | !printView.isActive() && |
| 1099 | typeof config.scrollActivationWidth === 'number' && |
| 1100 | config.view !== 'scroll' |
| 1101 | ) { |
| 1102 | const size = getComputedSlideSize(); |
| 1103 | |
| 1104 | if( size.presentationWidth > 0 && size.presentationWidth <= config.scrollActivationWidth ) { |
| 1105 | if( !scrollView.isActive() ) { |
| 1106 | backgrounds.create(); |
| 1107 | scrollView.activate() |
| 1108 | }; |
| 1109 | } |
| 1110 | else { |
| 1111 | if( scrollView.isActive() ) scrollView.deactivate(); |
| 1112 | } |
| 1113 | } |
| 1114 | |
| 1115 | } |
| 1116 | |
| 1117 | /** |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 1118 | * Calculates the computed pixel size of our slides. These |
| 1119 | * values are based on the width and height configuration |
| 1120 | * options. |
| 1121 | * |
| 1122 | * @param {number} [presentationWidth=dom.wrapper.offsetWidth] |
| 1123 | * @param {number} [presentationHeight=dom.wrapper.offsetHeight] |
| 1124 | */ |
| 1125 | function getComputedSlideSize( presentationWidth, presentationHeight ) { |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 1126 | |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 1127 | let width = config.width; |
| 1128 | let height = config.height; |
| 1129 | |
| 1130 | if( config.disableLayout ) { |
| 1131 | width = dom.slides.offsetWidth; |
| 1132 | height = dom.slides.offsetHeight; |
| 1133 | } |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 1134 | |
| 1135 | const size = { |
| 1136 | // Slide size |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 1137 | width: width, |
| 1138 | height: height, |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 1139 | |
| 1140 | // Presentation size |
| 1141 | presentationWidth: presentationWidth || dom.wrapper.offsetWidth, |
| 1142 | presentationHeight: presentationHeight || dom.wrapper.offsetHeight |
| 1143 | }; |
| 1144 | |
| 1145 | // Reduce available space by margin |
| 1146 | size.presentationWidth -= ( size.presentationWidth * config.margin ); |
| 1147 | size.presentationHeight -= ( size.presentationHeight * config.margin ); |
| 1148 | |
| 1149 | // Slide width may be a percentage of available width |
| 1150 | if( typeof size.width === 'string' && /%$/.test( size.width ) ) { |
| 1151 | size.width = parseInt( size.width, 10 ) / 100 * size.presentationWidth; |
| 1152 | } |
| 1153 | |
| 1154 | // Slide height may be a percentage of available height |
| 1155 | if( typeof size.height === 'string' && /%$/.test( size.height ) ) { |
| 1156 | size.height = parseInt( size.height, 10 ) / 100 * size.presentationHeight; |
| 1157 | } |
| 1158 | |
| 1159 | return size; |
| 1160 | |
| 1161 | } |
| 1162 | |
| 1163 | /** |
| 1164 | * Stores the vertical index of a stack so that the same |
| 1165 | * vertical slide can be selected when navigating to and |
| 1166 | * from the stack. |
| 1167 | * |
| 1168 | * @param {HTMLElement} stack The vertical stack element |
| 1169 | * @param {string|number} [v=0] Index to memorize |
| 1170 | */ |
| 1171 | function setPreviousVerticalIndex( stack, v ) { |
| 1172 | |
| 1173 | if( typeof stack === 'object' && typeof stack.setAttribute === 'function' ) { |
| 1174 | stack.setAttribute( 'data-previous-indexv', v || 0 ); |
| 1175 | } |
| 1176 | |
| 1177 | } |
| 1178 | |
| 1179 | /** |
| 1180 | * Retrieves the vertical index which was stored using |
| 1181 | * #setPreviousVerticalIndex() or 0 if no previous index |
| 1182 | * exists. |
| 1183 | * |
| 1184 | * @param {HTMLElement} stack The vertical stack element |
| 1185 | */ |
| 1186 | function getPreviousVerticalIndex( stack ) { |
| 1187 | |
| 1188 | if( typeof stack === 'object' && typeof stack.setAttribute === 'function' && stack.classList.contains( 'stack' ) ) { |
| 1189 | // Prefer manually defined start-indexv |
| 1190 | const attributeName = stack.hasAttribute( 'data-start-indexv' ) ? 'data-start-indexv' : 'data-previous-indexv'; |
| 1191 | |
| 1192 | return parseInt( stack.getAttribute( attributeName ) || 0, 10 ); |
| 1193 | } |
| 1194 | |
| 1195 | return 0; |
| 1196 | |
| 1197 | } |
| 1198 | |
| 1199 | /** |
| 1200 | * Checks if the current or specified slide is vertical |
| 1201 | * (nested within another slide). |
| 1202 | * |
| 1203 | * @param {HTMLElement} [slide=currentSlide] The slide to check |
| 1204 | * orientation of |
| 1205 | * @return {Boolean} |
| 1206 | */ |
| 1207 | function isVerticalSlide( slide = currentSlide ) { |
| 1208 | |
| 1209 | return slide && slide.parentNode && !!slide.parentNode.nodeName.match( /section/i ); |
| 1210 | |
| 1211 | } |
| 1212 | |
| 1213 | /** |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 1214 | * Checks if the current or specified slide is a stack containing |
| 1215 | * vertical slides. |
| 1216 | * |
| 1217 | * @param {HTMLElement} [slide=currentSlide] |
| 1218 | * @return {Boolean} |
| 1219 | */ |
| 1220 | function isVerticalStack( slide = currentSlide ) { |
| 1221 | |
| 1222 | return slide.classList.contains( '.stack' ) || slide.querySelector( 'section' ) !== null; |
| 1223 | |
| 1224 | } |
| 1225 | |
| 1226 | /** |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 1227 | * Returns true if we're on the last slide in the current |
| 1228 | * vertical stack. |
| 1229 | */ |
| 1230 | function isLastVerticalSlide() { |
| 1231 | |
| 1232 | if( currentSlide && isVerticalSlide( currentSlide ) ) { |
| 1233 | // Does this slide have a next sibling? |
| 1234 | if( currentSlide.nextElementSibling ) return false; |
| 1235 | |
| 1236 | return true; |
| 1237 | } |
| 1238 | |
| 1239 | return false; |
| 1240 | |
| 1241 | } |
| 1242 | |
| 1243 | /** |
| 1244 | * Returns true if we're currently on the first slide in |
| 1245 | * the presentation. |
| 1246 | */ |
| 1247 | function isFirstSlide() { |
| 1248 | |
| 1249 | return indexh === 0 && indexv === 0; |
| 1250 | |
| 1251 | } |
| 1252 | |
| 1253 | /** |
| 1254 | * Returns true if we're currently on the last slide in |
| 1255 | * the presenation. If the last slide is a stack, we only |
| 1256 | * consider this the last slide if it's at the end of the |
| 1257 | * stack. |
| 1258 | */ |
| 1259 | function isLastSlide() { |
| 1260 | |
| 1261 | if( currentSlide ) { |
| 1262 | // Does this slide have a next sibling? |
| 1263 | if( currentSlide.nextElementSibling ) return false; |
| 1264 | |
| 1265 | // If it's vertical, does its parent have a next sibling? |
| 1266 | if( isVerticalSlide( currentSlide ) && currentSlide.parentNode.nextElementSibling ) return false; |
| 1267 | |
| 1268 | return true; |
| 1269 | } |
| 1270 | |
| 1271 | return false; |
| 1272 | |
| 1273 | } |
| 1274 | |
| 1275 | /** |
| 1276 | * Enters the paused mode which fades everything on screen to |
| 1277 | * black. |
| 1278 | */ |
| 1279 | function pause() { |
| 1280 | |
| 1281 | if( config.pause ) { |
| 1282 | const wasPaused = dom.wrapper.classList.contains( 'paused' ); |
| 1283 | |
| 1284 | cancelAutoSlide(); |
| 1285 | dom.wrapper.classList.add( 'paused' ); |
| 1286 | |
| 1287 | if( wasPaused === false ) { |
| 1288 | dispatchEvent({ type: 'paused' }); |
| 1289 | } |
| 1290 | } |
| 1291 | |
| 1292 | } |
| 1293 | |
| 1294 | /** |
| 1295 | * Exits from the paused mode. |
| 1296 | */ |
| 1297 | function resume() { |
| 1298 | |
| 1299 | const wasPaused = dom.wrapper.classList.contains( 'paused' ); |
| 1300 | dom.wrapper.classList.remove( 'paused' ); |
| 1301 | |
| 1302 | cueAutoSlide(); |
| 1303 | |
| 1304 | if( wasPaused ) { |
| 1305 | dispatchEvent({ type: 'resumed' }); |
| 1306 | } |
| 1307 | |
| 1308 | } |
| 1309 | |
| 1310 | /** |
| 1311 | * Toggles the paused mode on and off. |
| 1312 | */ |
| 1313 | function togglePause( override ) { |
| 1314 | |
| 1315 | if( typeof override === 'boolean' ) { |
| 1316 | override ? pause() : resume(); |
| 1317 | } |
| 1318 | else { |
| 1319 | isPaused() ? resume() : pause(); |
| 1320 | } |
| 1321 | |
| 1322 | } |
| 1323 | |
| 1324 | /** |
| 1325 | * Checks if we are currently in the paused mode. |
| 1326 | * |
| 1327 | * @return {Boolean} |
| 1328 | */ |
| 1329 | function isPaused() { |
| 1330 | |
| 1331 | return dom.wrapper.classList.contains( 'paused' ); |
| 1332 | |
| 1333 | } |
| 1334 | |
| 1335 | /** |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 1336 | * Toggles visibility of the jump-to-slide UI. |
| 1337 | */ |
| 1338 | function toggleJumpToSlide( override ) { |
| 1339 | |
| 1340 | if( typeof override === 'boolean' ) { |
| 1341 | override ? jumpToSlide.show() : jumpToSlide.hide(); |
| 1342 | } |
| 1343 | else { |
| 1344 | jumpToSlide.isVisible() ? jumpToSlide.hide() : jumpToSlide.show(); |
| 1345 | } |
| 1346 | |
| 1347 | } |
| 1348 | |
| 1349 | /** |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 1350 | * Toggles the auto slide mode on and off. |
| 1351 | * |
| 1352 | * @param {Boolean} [override] Flag which sets the desired state. |
| 1353 | * True means autoplay starts, false means it stops. |
| 1354 | */ |
| 1355 | |
| 1356 | function toggleAutoSlide( override ) { |
| 1357 | |
| 1358 | if( typeof override === 'boolean' ) { |
| 1359 | override ? resumeAutoSlide() : pauseAutoSlide(); |
| 1360 | } |
| 1361 | |
| 1362 | else { |
| 1363 | autoSlidePaused ? resumeAutoSlide() : pauseAutoSlide(); |
| 1364 | } |
| 1365 | |
| 1366 | } |
| 1367 | |
| 1368 | /** |
| 1369 | * Checks if the auto slide mode is currently on. |
| 1370 | * |
| 1371 | * @return {Boolean} |
| 1372 | */ |
| 1373 | function isAutoSliding() { |
| 1374 | |
| 1375 | return !!( autoSlide && !autoSlidePaused ); |
| 1376 | |
| 1377 | } |
| 1378 | |
| 1379 | /** |
| 1380 | * Steps from the current point in the presentation to the |
| 1381 | * slide which matches the specified horizontal and vertical |
| 1382 | * indices. |
| 1383 | * |
| 1384 | * @param {number} [h=indexh] Horizontal index of the target slide |
| 1385 | * @param {number} [v=indexv] Vertical index of the target slide |
| 1386 | * @param {number} [f] Index of a fragment within the |
| 1387 | * target slide to activate |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 1388 | * @param {number} [origin] Origin for use in multimaster environments |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 1389 | */ |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 1390 | function slide( h, v, f, origin ) { |
| 1391 | |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 1392 | // Dispatch an event before the slide |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 1393 | const slidechange = dispatchEvent({ |
| 1394 | type: 'beforeslidechange', |
| 1395 | data: { |
| 1396 | indexh: h === undefined ? indexh : h, |
| 1397 | indexv: v === undefined ? indexv : v, |
| 1398 | origin |
| 1399 | } |
| 1400 | }); |
| 1401 | |
| 1402 | // Abort if this slide change was prevented by an event listener |
| 1403 | if( slidechange.defaultPrevented ) return; |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 1404 | |
| 1405 | // Remember where we were at before |
| 1406 | previousSlide = currentSlide; |
| 1407 | |
| 1408 | // Query all horizontal slides in the deck |
| 1409 | const horizontalSlides = dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ); |
| 1410 | |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 1411 | // If we're in scroll mode, we scroll the target slide into view |
| 1412 | // instead of running our standard slide transition |
| 1413 | if( scrollView.isActive() ) { |
| 1414 | const scrollToSlide = scrollView.getSlideByIndices( h, v ); |
| 1415 | if( scrollToSlide ) scrollView.scrollToSlide( scrollToSlide ); |
| 1416 | return; |
| 1417 | } |
| 1418 | |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 1419 | // Abort if there are no slides |
| 1420 | if( horizontalSlides.length === 0 ) return; |
| 1421 | |
| 1422 | // If no vertical index is specified and the upcoming slide is a |
| 1423 | // stack, resume at its previous vertical index |
| 1424 | if( v === undefined && !overview.isActive() ) { |
| 1425 | v = getPreviousVerticalIndex( horizontalSlides[ h ] ); |
| 1426 | } |
| 1427 | |
| 1428 | // If we were on a vertical stack, remember what vertical index |
| 1429 | // it was on so we can resume at the same position when returning |
| 1430 | if( previousSlide && previousSlide.parentNode && previousSlide.parentNode.classList.contains( 'stack' ) ) { |
| 1431 | setPreviousVerticalIndex( previousSlide.parentNode, indexv ); |
| 1432 | } |
| 1433 | |
| 1434 | // Remember the state before this slide |
| 1435 | const stateBefore = state.concat(); |
| 1436 | |
| 1437 | // Reset the state array |
| 1438 | state.length = 0; |
| 1439 | |
| 1440 | let indexhBefore = indexh || 0, |
| 1441 | indexvBefore = indexv || 0; |
| 1442 | |
| 1443 | // Activate and transition to the new slide |
| 1444 | indexh = updateSlides( HORIZONTAL_SLIDES_SELECTOR, h === undefined ? indexh : h ); |
| 1445 | indexv = updateSlides( VERTICAL_SLIDES_SELECTOR, v === undefined ? indexv : v ); |
| 1446 | |
| 1447 | // Dispatch an event if the slide changed |
| 1448 | let slideChanged = ( indexh !== indexhBefore || indexv !== indexvBefore ); |
| 1449 | |
| 1450 | // Ensure that the previous slide is never the same as the current |
| 1451 | if( !slideChanged ) previousSlide = null; |
| 1452 | |
| 1453 | // Find the current horizontal slide and any possible vertical slides |
| 1454 | // within it |
| 1455 | let currentHorizontalSlide = horizontalSlides[ indexh ], |
| 1456 | currentVerticalSlides = currentHorizontalSlide.querySelectorAll( 'section' ); |
| 1457 | |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 1458 | // Indicate when we're on a vertical slide |
| 1459 | revealElement.classList.toggle( 'is-vertical-slide', currentVerticalSlides.length > 1 ); |
| 1460 | |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 1461 | // Store references to the previous and current slides |
| 1462 | currentSlide = currentVerticalSlides[ indexv ] || currentHorizontalSlide; |
| 1463 | |
| 1464 | let autoAnimateTransition = false; |
| 1465 | |
| 1466 | // Detect if we're moving between two auto-animated slides |
| 1467 | if( slideChanged && previousSlide && currentSlide && !overview.isActive() ) { |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 1468 | transition = 'running'; |
| 1469 | |
| 1470 | autoAnimateTransition = shouldAutoAnimateBetween( previousSlide, currentSlide, indexhBefore, indexvBefore ); |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 1471 | |
| 1472 | // If this is an auto-animated transition, we disable the |
| 1473 | // regular slide transition |
| 1474 | // |
| 1475 | // Note 20-03-2020: |
| 1476 | // This needs to happen before we update slide visibility, |
| 1477 | // otherwise transitions will still run in Safari. |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 1478 | if( autoAnimateTransition ) { |
| 1479 | dom.slides.classList.add( 'disable-slide-transitions' ) |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 1480 | } |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | // Update the visibility of slides now that the indices have changed |
| 1484 | updateSlidesVisibility(); |
| 1485 | |
| 1486 | layout(); |
| 1487 | |
| 1488 | // Update the overview if it's currently active |
| 1489 | if( overview.isActive() ) { |
| 1490 | overview.update(); |
| 1491 | } |
| 1492 | |
| 1493 | // Show fragment, if specified |
| 1494 | if( typeof f !== 'undefined' ) { |
| 1495 | fragments.goto( f ); |
| 1496 | } |
| 1497 | |
| 1498 | // Solves an edge case where the previous slide maintains the |
| 1499 | // 'present' class when navigating between adjacent vertical |
| 1500 | // stacks |
| 1501 | if( previousSlide && previousSlide !== currentSlide ) { |
| 1502 | previousSlide.classList.remove( 'present' ); |
| 1503 | previousSlide.setAttribute( 'aria-hidden', 'true' ); |
| 1504 | |
| 1505 | // Reset all slides upon navigate to home |
| 1506 | if( isFirstSlide() ) { |
| 1507 | // Launch async task |
| 1508 | setTimeout( () => { |
| 1509 | getVerticalStacks().forEach( slide => { |
| 1510 | setPreviousVerticalIndex( slide, 0 ); |
| 1511 | } ); |
| 1512 | }, 0 ); |
| 1513 | } |
| 1514 | } |
| 1515 | |
| 1516 | // Apply the new state |
| 1517 | stateLoop: for( let i = 0, len = state.length; i < len; i++ ) { |
| 1518 | // Check if this state existed on the previous slide. If it |
| 1519 | // did, we will avoid adding it repeatedly |
| 1520 | for( let j = 0; j < stateBefore.length; j++ ) { |
| 1521 | if( stateBefore[j] === state[i] ) { |
| 1522 | stateBefore.splice( j, 1 ); |
| 1523 | continue stateLoop; |
| 1524 | } |
| 1525 | } |
| 1526 | |
| 1527 | dom.viewport.classList.add( state[i] ); |
| 1528 | |
| 1529 | // Dispatch custom event matching the state's name |
| 1530 | dispatchEvent({ type: state[i] }); |
| 1531 | } |
| 1532 | |
| 1533 | // Clean up the remains of the previous state |
| 1534 | while( stateBefore.length ) { |
| 1535 | dom.viewport.classList.remove( stateBefore.pop() ); |
| 1536 | } |
| 1537 | |
| 1538 | if( slideChanged ) { |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 1539 | dispatchSlideChanged( origin ); |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | // Handle embedded content |
| 1543 | if( slideChanged || !previousSlide ) { |
| 1544 | slideContent.stopEmbeddedContent( previousSlide ); |
| 1545 | slideContent.startEmbeddedContent( currentSlide ); |
| 1546 | } |
| 1547 | |
| 1548 | // Announce the current slide contents to screen readers |
| 1549 | // Use animation frame to prevent getComputedStyle in getStatusText |
| 1550 | // from triggering layout mid-frame |
| 1551 | requestAnimationFrame( () => { |
| 1552 | announceStatus( getStatusText( currentSlide ) ); |
| 1553 | }); |
| 1554 | |
| 1555 | progress.update(); |
| 1556 | controls.update(); |
| 1557 | notes.update(); |
| 1558 | backgrounds.update(); |
| 1559 | backgrounds.updateParallax(); |
| 1560 | slideNumber.update(); |
| 1561 | fragments.update(); |
| 1562 | |
| 1563 | // Update the URL hash |
| 1564 | location.writeURL(); |
| 1565 | |
| 1566 | cueAutoSlide(); |
| 1567 | |
| 1568 | // Auto-animation |
| 1569 | if( autoAnimateTransition ) { |
| 1570 | |
| 1571 | setTimeout( () => { |
| 1572 | dom.slides.classList.remove( 'disable-slide-transitions' ); |
| 1573 | }, 0 ); |
| 1574 | |
| 1575 | if( config.autoAnimate ) { |
| 1576 | // Run the auto-animation between our slides |
| 1577 | autoAnimate.run( previousSlide, currentSlide ); |
| 1578 | } |
| 1579 | |
| 1580 | } |
| 1581 | |
| 1582 | } |
| 1583 | |
| 1584 | /** |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 1585 | * Checks whether or not an auto-animation should take place between |
| 1586 | * the two given slides. |
| 1587 | * |
| 1588 | * @param {HTMLElement} fromSlide |
| 1589 | * @param {HTMLElement} toSlide |
| 1590 | * @param {number} indexhBefore |
| 1591 | * @param {number} indexvBefore |
| 1592 | * |
| 1593 | * @returns {boolean} |
| 1594 | */ |
| 1595 | function shouldAutoAnimateBetween( fromSlide, toSlide, indexhBefore, indexvBefore ) { |
| 1596 | |
| 1597 | return fromSlide.hasAttribute( 'data-auto-animate' ) && toSlide.hasAttribute( 'data-auto-animate' ) && |
| 1598 | fromSlide.getAttribute( 'data-auto-animate-id' ) === toSlide.getAttribute( 'data-auto-animate-id' ) && |
| 1599 | !( ( indexh > indexhBefore || indexv > indexvBefore ) ? toSlide : fromSlide ).hasAttribute( 'data-auto-animate-restart' ); |
| 1600 | |
| 1601 | } |
| 1602 | |
| 1603 | /** |
| 1604 | * Called anytime a new slide should be activated while in the scroll |
| 1605 | * view. The active slide is the page that occupies the most space in |
| 1606 | * the scrollable viewport. |
| 1607 | * |
| 1608 | * @param {number} pageIndex |
| 1609 | * @param {HTMLElement} slideElement |
| 1610 | */ |
| 1611 | function setCurrentScrollPage( slideElement, h, v ) { |
| 1612 | |
| 1613 | let indexhBefore = indexh || 0; |
| 1614 | |
| 1615 | indexh = h; |
| 1616 | indexv = v; |
| 1617 | |
| 1618 | const slideChanged = currentSlide !== slideElement; |
| 1619 | |
| 1620 | previousSlide = currentSlide; |
| 1621 | currentSlide = slideElement; |
| 1622 | |
| 1623 | if( currentSlide && previousSlide ) { |
| 1624 | if( config.autoAnimate && shouldAutoAnimateBetween( previousSlide, currentSlide, indexhBefore, indexv ) ) { |
| 1625 | // Run the auto-animation between our slides |
| 1626 | autoAnimate.run( previousSlide, currentSlide ); |
| 1627 | } |
| 1628 | } |
| 1629 | |
| 1630 | // Start or stop embedded content like videos and iframes |
| 1631 | if( slideChanged ) { |
| 1632 | if( previousSlide ) { |
| 1633 | slideContent.stopEmbeddedContent( previousSlide ); |
| 1634 | slideContent.stopEmbeddedContent( previousSlide.slideBackgroundElement ); |
| 1635 | } |
| 1636 | |
| 1637 | slideContent.startEmbeddedContent( currentSlide ); |
| 1638 | slideContent.startEmbeddedContent( currentSlide.slideBackgroundElement ); |
| 1639 | } |
| 1640 | |
| 1641 | requestAnimationFrame( () => { |
| 1642 | announceStatus( getStatusText( currentSlide ) ); |
| 1643 | }); |
| 1644 | |
| 1645 | dispatchSlideChanged(); |
| 1646 | |
| 1647 | } |
| 1648 | |
| 1649 | /** |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 1650 | * Syncs the presentation with the current DOM. Useful |
| 1651 | * when new slides or control elements are added or when |
| 1652 | * the configuration has changed. |
| 1653 | */ |
| 1654 | function sync() { |
| 1655 | |
| 1656 | // Subscribe to input |
| 1657 | removeEventListeners(); |
| 1658 | addEventListeners(); |
| 1659 | |
| 1660 | // Force a layout to make sure the current config is accounted for |
| 1661 | layout(); |
| 1662 | |
| 1663 | // Reflect the current autoSlide value |
| 1664 | autoSlide = config.autoSlide; |
| 1665 | |
| 1666 | // Start auto-sliding if it's enabled |
| 1667 | cueAutoSlide(); |
| 1668 | |
| 1669 | // Re-create all slide backgrounds |
| 1670 | backgrounds.create(); |
| 1671 | |
| 1672 | // Write the current hash to the URL |
| 1673 | location.writeURL(); |
| 1674 | |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 1675 | if( config.sortFragmentsOnSync === true ) { |
| 1676 | fragments.sortAll(); |
| 1677 | } |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 1678 | |
| 1679 | controls.update(); |
| 1680 | progress.update(); |
| 1681 | |
| 1682 | updateSlidesVisibility(); |
| 1683 | |
| 1684 | notes.update(); |
| 1685 | notes.updateVisibility(); |
| 1686 | backgrounds.update( true ); |
| 1687 | slideNumber.update(); |
| 1688 | slideContent.formatEmbeddedContent(); |
| 1689 | |
| 1690 | // Start or stop embedded content depending on global config |
| 1691 | if( config.autoPlayMedia === false ) { |
| 1692 | slideContent.stopEmbeddedContent( currentSlide, { unloadIframes: false } ); |
| 1693 | } |
| 1694 | else { |
| 1695 | slideContent.startEmbeddedContent( currentSlide ); |
| 1696 | } |
| 1697 | |
| 1698 | if( overview.isActive() ) { |
| 1699 | overview.layout(); |
| 1700 | } |
| 1701 | |
| 1702 | } |
| 1703 | |
| 1704 | /** |
| 1705 | * Updates reveal.js to keep in sync with new slide attributes. For |
| 1706 | * example, if you add a new `data-background-image` you can call |
| 1707 | * this to have reveal.js render the new background image. |
| 1708 | * |
| 1709 | * Similar to #sync() but more efficient when you only need to |
| 1710 | * refresh a specific slide. |
| 1711 | * |
| 1712 | * @param {HTMLElement} slide |
| 1713 | */ |
| 1714 | function syncSlide( slide = currentSlide ) { |
| 1715 | |
| 1716 | backgrounds.sync( slide ); |
| 1717 | fragments.sync( slide ); |
| 1718 | |
| 1719 | slideContent.load( slide ); |
| 1720 | |
| 1721 | backgrounds.update(); |
| 1722 | notes.update(); |
| 1723 | |
| 1724 | } |
| 1725 | |
| 1726 | /** |
| 1727 | * Resets all vertical slides so that only the first |
| 1728 | * is visible. |
| 1729 | */ |
| 1730 | function resetVerticalSlides() { |
| 1731 | |
| 1732 | getHorizontalSlides().forEach( horizontalSlide => { |
| 1733 | |
| 1734 | Util.queryAll( horizontalSlide, 'section' ).forEach( ( verticalSlide, y ) => { |
| 1735 | |
| 1736 | if( y > 0 ) { |
| 1737 | verticalSlide.classList.remove( 'present' ); |
| 1738 | verticalSlide.classList.remove( 'past' ); |
| 1739 | verticalSlide.classList.add( 'future' ); |
| 1740 | verticalSlide.setAttribute( 'aria-hidden', 'true' ); |
| 1741 | } |
| 1742 | |
| 1743 | } ); |
| 1744 | |
| 1745 | } ); |
| 1746 | |
| 1747 | } |
| 1748 | |
| 1749 | /** |
| 1750 | * Randomly shuffles all slides in the deck. |
| 1751 | */ |
| 1752 | function shuffle( slides = getHorizontalSlides() ) { |
| 1753 | |
| 1754 | slides.forEach( ( slide, i ) => { |
| 1755 | |
| 1756 | // Insert the slide next to a randomly picked sibling slide |
| 1757 | // slide. This may cause the slide to insert before itself, |
| 1758 | // but that's not an issue. |
| 1759 | let beforeSlide = slides[ Math.floor( Math.random() * slides.length ) ]; |
| 1760 | if( beforeSlide.parentNode === slide.parentNode ) { |
| 1761 | slide.parentNode.insertBefore( slide, beforeSlide ); |
| 1762 | } |
| 1763 | |
| 1764 | // Randomize the order of vertical slides (if there are any) |
| 1765 | let verticalSlides = slide.querySelectorAll( 'section' ); |
| 1766 | if( verticalSlides.length ) { |
| 1767 | shuffle( verticalSlides ); |
| 1768 | } |
| 1769 | |
| 1770 | } ); |
| 1771 | |
| 1772 | } |
| 1773 | |
| 1774 | /** |
| 1775 | * Updates one dimension of slides by showing the slide |
| 1776 | * with the specified index. |
| 1777 | * |
| 1778 | * @param {string} selector A CSS selector that will fetch |
| 1779 | * the group of slides we are working with |
| 1780 | * @param {number} index The index of the slide that should be |
| 1781 | * shown |
| 1782 | * |
| 1783 | * @return {number} The index of the slide that is now shown, |
| 1784 | * might differ from the passed in index if it was out of |
| 1785 | * bounds. |
| 1786 | */ |
| 1787 | function updateSlides( selector, index ) { |
| 1788 | |
| 1789 | // Select all slides and convert the NodeList result to |
| 1790 | // an array |
| 1791 | let slides = Util.queryAll( dom.wrapper, selector ), |
| 1792 | slidesLength = slides.length; |
| 1793 | |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 1794 | let printMode = scrollView.isActive() || printView.isActive(); |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 1795 | let loopedForwards = false; |
| 1796 | let loopedBackwards = false; |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 1797 | |
| 1798 | if( slidesLength ) { |
| 1799 | |
| 1800 | // Should the index loop? |
| 1801 | if( config.loop ) { |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 1802 | if( index >= slidesLength ) loopedForwards = true; |
| 1803 | |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 1804 | index %= slidesLength; |
| 1805 | |
| 1806 | if( index < 0 ) { |
| 1807 | index = slidesLength + index; |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 1808 | loopedBackwards = true; |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 1809 | } |
| 1810 | } |
| 1811 | |
| 1812 | // Enforce max and minimum index bounds |
| 1813 | index = Math.max( Math.min( index, slidesLength - 1 ), 0 ); |
| 1814 | |
| 1815 | for( let i = 0; i < slidesLength; i++ ) { |
| 1816 | let element = slides[i]; |
| 1817 | |
| 1818 | let reverse = config.rtl && !isVerticalSlide( element ); |
| 1819 | |
| 1820 | // Avoid .remove() with multiple args for IE11 support |
| 1821 | element.classList.remove( 'past' ); |
| 1822 | element.classList.remove( 'present' ); |
| 1823 | element.classList.remove( 'future' ); |
| 1824 | |
| 1825 | // http://www.w3.org/html/wg/drafts/html/master/editing.html#the-hidden-attribute |
| 1826 | element.setAttribute( 'hidden', '' ); |
| 1827 | element.setAttribute( 'aria-hidden', 'true' ); |
| 1828 | |
| 1829 | // If this element contains vertical slides |
| 1830 | if( element.querySelector( 'section' ) ) { |
| 1831 | element.classList.add( 'stack' ); |
| 1832 | } |
| 1833 | |
| 1834 | // If we're printing static slides, all slides are "present" |
| 1835 | if( printMode ) { |
| 1836 | element.classList.add( 'present' ); |
| 1837 | continue; |
| 1838 | } |
| 1839 | |
| 1840 | if( i < index ) { |
| 1841 | // Any element previous to index is given the 'past' class |
| 1842 | element.classList.add( reverse ? 'future' : 'past' ); |
| 1843 | |
| 1844 | if( config.fragments ) { |
| 1845 | // Show all fragments in prior slides |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 1846 | showFragmentsIn( element ); |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 1847 | } |
| 1848 | } |
| 1849 | else if( i > index ) { |
| 1850 | // Any element subsequent to index is given the 'future' class |
| 1851 | element.classList.add( reverse ? 'past' : 'future' ); |
| 1852 | |
| 1853 | if( config.fragments ) { |
| 1854 | // Hide all fragments in future slides |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 1855 | hideFragmentsIn( element ); |
| 1856 | } |
| 1857 | } |
| 1858 | // Update the visibility of fragments when a presentation loops |
| 1859 | // in either direction |
| 1860 | else if( i === index && config.fragments ) { |
| 1861 | if( loopedForwards ) { |
| 1862 | hideFragmentsIn( element ); |
| 1863 | } |
| 1864 | else if( loopedBackwards ) { |
| 1865 | showFragmentsIn( element ); |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 1866 | } |
| 1867 | } |
| 1868 | } |
| 1869 | |
| 1870 | let slide = slides[index]; |
| 1871 | let wasPresent = slide.classList.contains( 'present' ); |
| 1872 | |
| 1873 | // Mark the current slide as present |
| 1874 | slide.classList.add( 'present' ); |
| 1875 | slide.removeAttribute( 'hidden' ); |
| 1876 | slide.removeAttribute( 'aria-hidden' ); |
| 1877 | |
| 1878 | if( !wasPresent ) { |
| 1879 | // Dispatch an event indicating the slide is now visible |
| 1880 | dispatchEvent({ |
| 1881 | target: slide, |
| 1882 | type: 'visible', |
| 1883 | bubbles: false |
| 1884 | }); |
| 1885 | } |
| 1886 | |
| 1887 | // If this slide has a state associated with it, add it |
| 1888 | // onto the current state of the deck |
| 1889 | let slideState = slide.getAttribute( 'data-state' ); |
| 1890 | if( slideState ) { |
| 1891 | state = state.concat( slideState.split( ' ' ) ); |
| 1892 | } |
| 1893 | |
| 1894 | } |
| 1895 | else { |
| 1896 | // Since there are no slides we can't be anywhere beyond the |
| 1897 | // zeroth index |
| 1898 | index = 0; |
| 1899 | } |
| 1900 | |
| 1901 | return index; |
| 1902 | |
| 1903 | } |
| 1904 | |
| 1905 | /** |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 1906 | * Shows all fragment elements within the given container. |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 1907 | */ |
| 1908 | function showFragmentsIn( container ) { |
| 1909 | |
| 1910 | Util.queryAll( container, '.fragment' ).forEach( fragment => { |
| 1911 | fragment.classList.add( 'visible' ); |
| 1912 | fragment.classList.remove( 'current-fragment' ); |
| 1913 | } ); |
| 1914 | |
| 1915 | } |
| 1916 | |
| 1917 | /** |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 1918 | * Hides all fragment elements within the given container. |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 1919 | */ |
| 1920 | function hideFragmentsIn( container ) { |
| 1921 | |
| 1922 | Util.queryAll( container, '.fragment.visible' ).forEach( fragment => { |
| 1923 | fragment.classList.remove( 'visible', 'current-fragment' ); |
| 1924 | } ); |
| 1925 | |
| 1926 | } |
| 1927 | |
| 1928 | /** |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 1929 | * Optimization method; hide all slides that are far away |
| 1930 | * from the present slide. |
| 1931 | */ |
| 1932 | function updateSlidesVisibility() { |
| 1933 | |
| 1934 | // Select all slides and convert the NodeList result to |
| 1935 | // an array |
| 1936 | let horizontalSlides = getHorizontalSlides(), |
| 1937 | horizontalSlidesLength = horizontalSlides.length, |
| 1938 | distanceX, |
| 1939 | distanceY; |
| 1940 | |
| 1941 | if( horizontalSlidesLength && typeof indexh !== 'undefined' ) { |
| 1942 | |
| 1943 | // The number of steps away from the present slide that will |
| 1944 | // be visible |
| 1945 | let viewDistance = overview.isActive() ? 10 : config.viewDistance; |
| 1946 | |
| 1947 | // Shorten the view distance on devices that typically have |
| 1948 | // less resources |
| 1949 | if( Device.isMobile ) { |
| 1950 | viewDistance = overview.isActive() ? 6 : config.mobileViewDistance; |
| 1951 | } |
| 1952 | |
| 1953 | // All slides need to be visible when exporting to PDF |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 1954 | if( printView.isActive() ) { |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 1955 | viewDistance = Number.MAX_VALUE; |
| 1956 | } |
| 1957 | |
| 1958 | for( let x = 0; x < horizontalSlidesLength; x++ ) { |
| 1959 | let horizontalSlide = horizontalSlides[x]; |
| 1960 | |
| 1961 | let verticalSlides = Util.queryAll( horizontalSlide, 'section' ), |
| 1962 | verticalSlidesLength = verticalSlides.length; |
| 1963 | |
| 1964 | // Determine how far away this slide is from the present |
| 1965 | distanceX = Math.abs( ( indexh || 0 ) - x ) || 0; |
| 1966 | |
| 1967 | // If the presentation is looped, distance should measure |
| 1968 | // 1 between the first and last slides |
| 1969 | if( config.loop ) { |
| 1970 | distanceX = Math.abs( ( ( indexh || 0 ) - x ) % ( horizontalSlidesLength - viewDistance ) ) || 0; |
| 1971 | } |
| 1972 | |
| 1973 | // Show the horizontal slide if it's within the view distance |
| 1974 | if( distanceX < viewDistance ) { |
| 1975 | slideContent.load( horizontalSlide ); |
| 1976 | } |
| 1977 | else { |
| 1978 | slideContent.unload( horizontalSlide ); |
| 1979 | } |
| 1980 | |
| 1981 | if( verticalSlidesLength ) { |
| 1982 | |
| 1983 | let oy = getPreviousVerticalIndex( horizontalSlide ); |
| 1984 | |
| 1985 | for( let y = 0; y < verticalSlidesLength; y++ ) { |
| 1986 | let verticalSlide = verticalSlides[y]; |
| 1987 | |
| 1988 | distanceY = x === ( indexh || 0 ) ? Math.abs( ( indexv || 0 ) - y ) : Math.abs( y - oy ); |
| 1989 | |
| 1990 | if( distanceX + distanceY < viewDistance ) { |
| 1991 | slideContent.load( verticalSlide ); |
| 1992 | } |
| 1993 | else { |
| 1994 | slideContent.unload( verticalSlide ); |
| 1995 | } |
| 1996 | } |
| 1997 | |
| 1998 | } |
| 1999 | } |
| 2000 | |
| 2001 | // Flag if there are ANY vertical slides, anywhere in the deck |
| 2002 | if( hasVerticalSlides() ) { |
| 2003 | dom.wrapper.classList.add( 'has-vertical-slides' ); |
| 2004 | } |
| 2005 | else { |
| 2006 | dom.wrapper.classList.remove( 'has-vertical-slides' ); |
| 2007 | } |
| 2008 | |
| 2009 | // Flag if there are ANY horizontal slides, anywhere in the deck |
| 2010 | if( hasHorizontalSlides() ) { |
| 2011 | dom.wrapper.classList.add( 'has-horizontal-slides' ); |
| 2012 | } |
| 2013 | else { |
| 2014 | dom.wrapper.classList.remove( 'has-horizontal-slides' ); |
| 2015 | } |
| 2016 | |
| 2017 | } |
| 2018 | |
| 2019 | } |
| 2020 | |
| 2021 | /** |
| 2022 | * Determine what available routes there are for navigation. |
| 2023 | * |
| 2024 | * @return {{left: boolean, right: boolean, up: boolean, down: boolean}} |
| 2025 | */ |
| 2026 | function availableRoutes({ includeFragments = false } = {}) { |
| 2027 | |
| 2028 | let horizontalSlides = dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ), |
| 2029 | verticalSlides = dom.wrapper.querySelectorAll( VERTICAL_SLIDES_SELECTOR ); |
| 2030 | |
| 2031 | let routes = { |
| 2032 | left: indexh > 0, |
| 2033 | right: indexh < horizontalSlides.length - 1, |
| 2034 | up: indexv > 0, |
| 2035 | down: indexv < verticalSlides.length - 1 |
| 2036 | }; |
| 2037 | |
| 2038 | // Looped presentations can always be navigated as long as |
| 2039 | // there are slides available |
| 2040 | if( config.loop ) { |
| 2041 | if( horizontalSlides.length > 1 ) { |
| 2042 | routes.left = true; |
| 2043 | routes.right = true; |
| 2044 | } |
| 2045 | |
| 2046 | if( verticalSlides.length > 1 ) { |
| 2047 | routes.up = true; |
| 2048 | routes.down = true; |
| 2049 | } |
| 2050 | } |
| 2051 | |
| 2052 | if ( horizontalSlides.length > 1 && config.navigationMode === 'linear' ) { |
| 2053 | routes.right = routes.right || routes.down; |
| 2054 | routes.left = routes.left || routes.up; |
| 2055 | } |
| 2056 | |
| 2057 | // If includeFragments is set, a route will be considered |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 2058 | // available if either a slid OR fragment is available in |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2059 | // the given direction |
| 2060 | if( includeFragments === true ) { |
| 2061 | let fragmentRoutes = fragments.availableRoutes(); |
| 2062 | routes.left = routes.left || fragmentRoutes.prev; |
| 2063 | routes.up = routes.up || fragmentRoutes.prev; |
| 2064 | routes.down = routes.down || fragmentRoutes.next; |
| 2065 | routes.right = routes.right || fragmentRoutes.next; |
| 2066 | } |
| 2067 | |
| 2068 | // Reverse horizontal controls for rtl |
| 2069 | if( config.rtl ) { |
| 2070 | let left = routes.left; |
| 2071 | routes.left = routes.right; |
| 2072 | routes.right = left; |
| 2073 | } |
| 2074 | |
| 2075 | return routes; |
| 2076 | |
| 2077 | } |
| 2078 | |
| 2079 | /** |
| 2080 | * Returns the number of past slides. This can be used as a global |
| 2081 | * flattened index for slides. |
| 2082 | * |
| 2083 | * @param {HTMLElement} [slide=currentSlide] The slide we're counting before |
| 2084 | * |
| 2085 | * @return {number} Past slide count |
| 2086 | */ |
| 2087 | function getSlidePastCount( slide = currentSlide ) { |
| 2088 | |
| 2089 | let horizontalSlides = getHorizontalSlides(); |
| 2090 | |
| 2091 | // The number of past slides |
| 2092 | let pastCount = 0; |
| 2093 | |
| 2094 | // Step through all slides and count the past ones |
| 2095 | mainLoop: for( let i = 0; i < horizontalSlides.length; i++ ) { |
| 2096 | |
| 2097 | let horizontalSlide = horizontalSlides[i]; |
| 2098 | let verticalSlides = horizontalSlide.querySelectorAll( 'section' ); |
| 2099 | |
| 2100 | for( let j = 0; j < verticalSlides.length; j++ ) { |
| 2101 | |
| 2102 | // Stop as soon as we arrive at the present |
| 2103 | if( verticalSlides[j] === slide ) { |
| 2104 | break mainLoop; |
| 2105 | } |
| 2106 | |
| 2107 | // Don't count slides with the "uncounted" class |
| 2108 | if( verticalSlides[j].dataset.visibility !== 'uncounted' ) { |
| 2109 | pastCount++; |
| 2110 | } |
| 2111 | |
| 2112 | } |
| 2113 | |
| 2114 | // Stop as soon as we arrive at the present |
| 2115 | if( horizontalSlide === slide ) { |
| 2116 | break; |
| 2117 | } |
| 2118 | |
| 2119 | // Don't count the wrapping section for vertical slides and |
| 2120 | // slides marked as uncounted |
| 2121 | if( horizontalSlide.classList.contains( 'stack' ) === false && horizontalSlide.dataset.visibility !== 'uncounted' ) { |
| 2122 | pastCount++; |
| 2123 | } |
| 2124 | |
| 2125 | } |
| 2126 | |
| 2127 | return pastCount; |
| 2128 | |
| 2129 | } |
| 2130 | |
| 2131 | /** |
| 2132 | * Returns a value ranging from 0-1 that represents |
| 2133 | * how far into the presentation we have navigated. |
| 2134 | * |
| 2135 | * @return {number} |
| 2136 | */ |
| 2137 | function getProgress() { |
| 2138 | |
| 2139 | // The number of past and total slides |
| 2140 | let totalCount = getTotalSlides(); |
| 2141 | let pastCount = getSlidePastCount(); |
| 2142 | |
| 2143 | if( currentSlide ) { |
| 2144 | |
| 2145 | let allFragments = currentSlide.querySelectorAll( '.fragment' ); |
| 2146 | |
| 2147 | // If there are fragments in the current slide those should be |
| 2148 | // accounted for in the progress. |
| 2149 | if( allFragments.length > 0 ) { |
| 2150 | let visibleFragments = currentSlide.querySelectorAll( '.fragment.visible' ); |
| 2151 | |
| 2152 | // This value represents how big a portion of the slide progress |
| 2153 | // that is made up by its fragments (0-1) |
| 2154 | let fragmentWeight = 0.9; |
| 2155 | |
| 2156 | // Add fragment progress to the past slide count |
| 2157 | pastCount += ( visibleFragments.length / allFragments.length ) * fragmentWeight; |
| 2158 | } |
| 2159 | |
| 2160 | } |
| 2161 | |
| 2162 | return Math.min( pastCount / ( totalCount - 1 ), 1 ); |
| 2163 | |
| 2164 | } |
| 2165 | |
| 2166 | /** |
| 2167 | * Retrieves the h/v location and fragment of the current, |
| 2168 | * or specified, slide. |
| 2169 | * |
| 2170 | * @param {HTMLElement} [slide] If specified, the returned |
| 2171 | * index will be for this slide rather than the currently |
| 2172 | * active one |
| 2173 | * |
| 2174 | * @return {{h: number, v: number, f: number}} |
| 2175 | */ |
| 2176 | function getIndices( slide ) { |
| 2177 | |
| 2178 | // By default, return the current indices |
| 2179 | let h = indexh, |
| 2180 | v = indexv, |
| 2181 | f; |
| 2182 | |
| 2183 | // If a slide is specified, return the indices of that slide |
| 2184 | if( slide ) { |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 2185 | // In scroll mode the original h/x index is stored on the slide |
| 2186 | if( scrollView.isActive() ) { |
| 2187 | h = parseInt( slide.getAttribute( 'data-index-h' ), 10 ); |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2188 | |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 2189 | if( slide.getAttribute( 'data-index-v' ) ) { |
| 2190 | v = parseInt( slide.getAttribute( 'data-index-v' ), 10 ); |
| 2191 | } |
| 2192 | } |
| 2193 | else { |
| 2194 | let isVertical = isVerticalSlide( slide ); |
| 2195 | let slideh = isVertical ? slide.parentNode : slide; |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2196 | |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 2197 | // Select all horizontal slides |
| 2198 | let horizontalSlides = getHorizontalSlides(); |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2199 | |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 2200 | // Now that we know which the horizontal slide is, get its index |
| 2201 | h = Math.max( horizontalSlides.indexOf( slideh ), 0 ); |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2202 | |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 2203 | // Assume we're not vertical |
| 2204 | v = undefined; |
| 2205 | |
| 2206 | // If this is a vertical slide, grab the vertical index |
| 2207 | if( isVertical ) { |
| 2208 | v = Math.max( Util.queryAll( slide.parentNode, 'section' ).indexOf( slide ), 0 ); |
| 2209 | } |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2210 | } |
| 2211 | } |
| 2212 | |
| 2213 | if( !slide && currentSlide ) { |
| 2214 | let hasFragments = currentSlide.querySelectorAll( '.fragment' ).length > 0; |
| 2215 | if( hasFragments ) { |
| 2216 | let currentFragment = currentSlide.querySelector( '.current-fragment' ); |
| 2217 | if( currentFragment && currentFragment.hasAttribute( 'data-fragment-index' ) ) { |
| 2218 | f = parseInt( currentFragment.getAttribute( 'data-fragment-index' ), 10 ); |
| 2219 | } |
| 2220 | else { |
| 2221 | f = currentSlide.querySelectorAll( '.fragment.visible' ).length - 1; |
| 2222 | } |
| 2223 | } |
| 2224 | } |
| 2225 | |
| 2226 | return { h, v, f }; |
| 2227 | |
| 2228 | } |
| 2229 | |
| 2230 | /** |
| 2231 | * Retrieves all slides in this presentation. |
| 2232 | */ |
| 2233 | function getSlides() { |
| 2234 | |
| 2235 | return Util.queryAll( dom.wrapper, SLIDES_SELECTOR + ':not(.stack):not([data-visibility="uncounted"])' ); |
| 2236 | |
| 2237 | } |
| 2238 | |
| 2239 | /** |
| 2240 | * Returns a list of all horizontal slides in the deck. Each |
| 2241 | * vertical stack is included as one horizontal slide in the |
| 2242 | * resulting array. |
| 2243 | */ |
| 2244 | function getHorizontalSlides() { |
| 2245 | |
| 2246 | return Util.queryAll( dom.wrapper, HORIZONTAL_SLIDES_SELECTOR ); |
| 2247 | |
| 2248 | } |
| 2249 | |
| 2250 | /** |
| 2251 | * Returns all vertical slides that exist within this deck. |
| 2252 | */ |
| 2253 | function getVerticalSlides() { |
| 2254 | |
| 2255 | return Util.queryAll( dom.wrapper, '.slides>section>section' ); |
| 2256 | |
| 2257 | } |
| 2258 | |
| 2259 | /** |
| 2260 | * Returns all vertical stacks (each stack can contain multiple slides). |
| 2261 | */ |
| 2262 | function getVerticalStacks() { |
| 2263 | |
| 2264 | return Util.queryAll( dom.wrapper, HORIZONTAL_SLIDES_SELECTOR + '.stack'); |
| 2265 | |
| 2266 | } |
| 2267 | |
| 2268 | /** |
| 2269 | * Returns true if there are at least two horizontal slides. |
| 2270 | */ |
| 2271 | function hasHorizontalSlides() { |
| 2272 | |
| 2273 | return getHorizontalSlides().length > 1; |
| 2274 | } |
| 2275 | |
| 2276 | /** |
| 2277 | * Returns true if there are at least two vertical slides. |
| 2278 | */ |
| 2279 | function hasVerticalSlides() { |
| 2280 | |
| 2281 | return getVerticalSlides().length > 1; |
| 2282 | |
| 2283 | } |
| 2284 | |
| 2285 | /** |
| 2286 | * Returns an array of objects where each object represents the |
| 2287 | * attributes on its respective slide. |
| 2288 | */ |
| 2289 | function getSlidesAttributes() { |
| 2290 | |
| 2291 | return getSlides().map( slide => { |
| 2292 | |
| 2293 | let attributes = {}; |
| 2294 | for( let i = 0; i < slide.attributes.length; i++ ) { |
| 2295 | let attribute = slide.attributes[ i ]; |
| 2296 | attributes[ attribute.name ] = attribute.value; |
| 2297 | } |
| 2298 | return attributes; |
| 2299 | |
| 2300 | } ); |
| 2301 | |
| 2302 | } |
| 2303 | |
| 2304 | /** |
| 2305 | * Retrieves the total number of slides in this presentation. |
| 2306 | * |
| 2307 | * @return {number} |
| 2308 | */ |
| 2309 | function getTotalSlides() { |
| 2310 | |
| 2311 | return getSlides().length; |
| 2312 | |
| 2313 | } |
| 2314 | |
| 2315 | /** |
| 2316 | * Returns the slide element matching the specified index. |
| 2317 | * |
| 2318 | * @return {HTMLElement} |
| 2319 | */ |
| 2320 | function getSlide( x, y ) { |
| 2321 | |
| 2322 | let horizontalSlide = getHorizontalSlides()[ x ]; |
| 2323 | let verticalSlides = horizontalSlide && horizontalSlide.querySelectorAll( 'section' ); |
| 2324 | |
| 2325 | if( verticalSlides && verticalSlides.length && typeof y === 'number' ) { |
| 2326 | return verticalSlides ? verticalSlides[ y ] : undefined; |
| 2327 | } |
| 2328 | |
| 2329 | return horizontalSlide; |
| 2330 | |
| 2331 | } |
| 2332 | |
| 2333 | /** |
| 2334 | * Returns the background element for the given slide. |
| 2335 | * All slides, even the ones with no background properties |
| 2336 | * defined, have a background element so as long as the |
| 2337 | * index is valid an element will be returned. |
| 2338 | * |
| 2339 | * @param {mixed} x Horizontal background index OR a slide |
| 2340 | * HTML element |
| 2341 | * @param {number} y Vertical background index |
| 2342 | * @return {(HTMLElement[]|*)} |
| 2343 | */ |
| 2344 | function getSlideBackground( x, y ) { |
| 2345 | |
| 2346 | let slide = typeof x === 'number' ? getSlide( x, y ) : x; |
| 2347 | if( slide ) { |
| 2348 | return slide.slideBackgroundElement; |
| 2349 | } |
| 2350 | |
| 2351 | return undefined; |
| 2352 | |
| 2353 | } |
| 2354 | |
| 2355 | /** |
| 2356 | * Retrieves the current state of the presentation as |
| 2357 | * an object. This state can then be restored at any |
| 2358 | * time. |
| 2359 | * |
| 2360 | * @return {{indexh: number, indexv: number, indexf: number, paused: boolean, overview: boolean}} |
| 2361 | */ |
| 2362 | function getState() { |
| 2363 | |
| 2364 | let indices = getIndices(); |
| 2365 | |
| 2366 | return { |
| 2367 | indexh: indices.h, |
| 2368 | indexv: indices.v, |
| 2369 | indexf: indices.f, |
| 2370 | paused: isPaused(), |
| 2371 | overview: overview.isActive() |
| 2372 | }; |
| 2373 | |
| 2374 | } |
| 2375 | |
| 2376 | /** |
| 2377 | * Restores the presentation to the given state. |
| 2378 | * |
| 2379 | * @param {object} state As generated by getState() |
| 2380 | * @see {@link getState} generates the parameter `state` |
| 2381 | */ |
| 2382 | function setState( state ) { |
| 2383 | |
| 2384 | if( typeof state === 'object' ) { |
| 2385 | slide( Util.deserialize( state.indexh ), Util.deserialize( state.indexv ), Util.deserialize( state.indexf ) ); |
| 2386 | |
| 2387 | let pausedFlag = Util.deserialize( state.paused ), |
| 2388 | overviewFlag = Util.deserialize( state.overview ); |
| 2389 | |
| 2390 | if( typeof pausedFlag === 'boolean' && pausedFlag !== isPaused() ) { |
| 2391 | togglePause( pausedFlag ); |
| 2392 | } |
| 2393 | |
| 2394 | if( typeof overviewFlag === 'boolean' && overviewFlag !== overview.isActive() ) { |
| 2395 | overview.toggle( overviewFlag ); |
| 2396 | } |
| 2397 | } |
| 2398 | |
| 2399 | } |
| 2400 | |
| 2401 | /** |
| 2402 | * Cues a new automated slide if enabled in the config. |
| 2403 | */ |
| 2404 | function cueAutoSlide() { |
| 2405 | |
| 2406 | cancelAutoSlide(); |
| 2407 | |
| 2408 | if( currentSlide && config.autoSlide !== false ) { |
| 2409 | |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 2410 | let fragment = currentSlide.querySelector( '.current-fragment[data-autoslide]' ); |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2411 | |
| 2412 | let fragmentAutoSlide = fragment ? fragment.getAttribute( 'data-autoslide' ) : null; |
| 2413 | let parentAutoSlide = currentSlide.parentNode ? currentSlide.parentNode.getAttribute( 'data-autoslide' ) : null; |
| 2414 | let slideAutoSlide = currentSlide.getAttribute( 'data-autoslide' ); |
| 2415 | |
| 2416 | // Pick value in the following priority order: |
| 2417 | // 1. Current fragment's data-autoslide |
| 2418 | // 2. Current slide's data-autoslide |
| 2419 | // 3. Parent slide's data-autoslide |
| 2420 | // 4. Global autoSlide setting |
| 2421 | if( fragmentAutoSlide ) { |
| 2422 | autoSlide = parseInt( fragmentAutoSlide, 10 ); |
| 2423 | } |
| 2424 | else if( slideAutoSlide ) { |
| 2425 | autoSlide = parseInt( slideAutoSlide, 10 ); |
| 2426 | } |
| 2427 | else if( parentAutoSlide ) { |
| 2428 | autoSlide = parseInt( parentAutoSlide, 10 ); |
| 2429 | } |
| 2430 | else { |
| 2431 | autoSlide = config.autoSlide; |
| 2432 | |
| 2433 | // If there are media elements with data-autoplay, |
| 2434 | // automatically set the autoSlide duration to the |
| 2435 | // length of that media. Not applicable if the slide |
| 2436 | // is divided up into fragments. |
| 2437 | // playbackRate is accounted for in the duration. |
| 2438 | if( currentSlide.querySelectorAll( '.fragment' ).length === 0 ) { |
| 2439 | Util.queryAll( currentSlide, 'video, audio' ).forEach( el => { |
| 2440 | if( el.hasAttribute( 'data-autoplay' ) ) { |
| 2441 | if( autoSlide && (el.duration * 1000 / el.playbackRate ) > autoSlide ) { |
| 2442 | autoSlide = ( el.duration * 1000 / el.playbackRate ) + 1000; |
| 2443 | } |
| 2444 | } |
| 2445 | } ); |
| 2446 | } |
| 2447 | } |
| 2448 | |
| 2449 | // Cue the next auto-slide if: |
| 2450 | // - There is an autoSlide value |
| 2451 | // - Auto-sliding isn't paused by the user |
| 2452 | // - The presentation isn't paused |
| 2453 | // - The overview isn't active |
| 2454 | // - The presentation isn't over |
| 2455 | if( autoSlide && !autoSlidePaused && !isPaused() && !overview.isActive() && ( !isLastSlide() || fragments.availableRoutes().next || config.loop === true ) ) { |
| 2456 | autoSlideTimeout = setTimeout( () => { |
| 2457 | if( typeof config.autoSlideMethod === 'function' ) { |
| 2458 | config.autoSlideMethod() |
| 2459 | } |
| 2460 | else { |
| 2461 | navigateNext(); |
| 2462 | } |
| 2463 | cueAutoSlide(); |
| 2464 | }, autoSlide ); |
| 2465 | autoSlideStartTime = Date.now(); |
| 2466 | } |
| 2467 | |
| 2468 | if( autoSlidePlayer ) { |
| 2469 | autoSlidePlayer.setPlaying( autoSlideTimeout !== -1 ); |
| 2470 | } |
| 2471 | |
| 2472 | } |
| 2473 | |
| 2474 | } |
| 2475 | |
| 2476 | /** |
| 2477 | * Cancels any ongoing request to auto-slide. |
| 2478 | */ |
| 2479 | function cancelAutoSlide() { |
| 2480 | |
| 2481 | clearTimeout( autoSlideTimeout ); |
| 2482 | autoSlideTimeout = -1; |
| 2483 | |
| 2484 | } |
| 2485 | |
| 2486 | function pauseAutoSlide() { |
| 2487 | |
| 2488 | if( autoSlide && !autoSlidePaused ) { |
| 2489 | autoSlidePaused = true; |
| 2490 | dispatchEvent({ type: 'autoslidepaused' }); |
| 2491 | clearTimeout( autoSlideTimeout ); |
| 2492 | |
| 2493 | if( autoSlidePlayer ) { |
| 2494 | autoSlidePlayer.setPlaying( false ); |
| 2495 | } |
| 2496 | } |
| 2497 | |
| 2498 | } |
| 2499 | |
| 2500 | function resumeAutoSlide() { |
| 2501 | |
| 2502 | if( autoSlide && autoSlidePaused ) { |
| 2503 | autoSlidePaused = false; |
| 2504 | dispatchEvent({ type: 'autoslideresumed' }); |
| 2505 | cueAutoSlide(); |
| 2506 | } |
| 2507 | |
| 2508 | } |
| 2509 | |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 2510 | function navigateLeft({skipFragments=false}={}) { |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2511 | |
| 2512 | navigationHistory.hasNavigatedHorizontally = true; |
| 2513 | |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 2514 | // Scroll view navigation is handled independently |
| 2515 | if( scrollView.isActive() ) return scrollView.prev(); |
| 2516 | |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2517 | // Reverse for RTL |
| 2518 | if( config.rtl ) { |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 2519 | if( ( overview.isActive() || skipFragments || fragments.next() === false ) && availableRoutes().left ) { |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2520 | slide( indexh + 1, config.navigationMode === 'grid' ? indexv : undefined ); |
| 2521 | } |
| 2522 | } |
| 2523 | // Normal navigation |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 2524 | else if( ( overview.isActive() || skipFragments || fragments.prev() === false ) && availableRoutes().left ) { |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2525 | slide( indexh - 1, config.navigationMode === 'grid' ? indexv : undefined ); |
| 2526 | } |
| 2527 | |
| 2528 | } |
| 2529 | |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 2530 | function navigateRight({skipFragments=false}={}) { |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2531 | |
| 2532 | navigationHistory.hasNavigatedHorizontally = true; |
| 2533 | |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 2534 | // Scroll view navigation is handled independently |
| 2535 | if( scrollView.isActive() ) return scrollView.next(); |
| 2536 | |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2537 | // Reverse for RTL |
| 2538 | if( config.rtl ) { |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 2539 | if( ( overview.isActive() || skipFragments || fragments.prev() === false ) && availableRoutes().right ) { |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2540 | slide( indexh - 1, config.navigationMode === 'grid' ? indexv : undefined ); |
| 2541 | } |
| 2542 | } |
| 2543 | // Normal navigation |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 2544 | else if( ( overview.isActive() || skipFragments || fragments.next() === false ) && availableRoutes().right ) { |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2545 | slide( indexh + 1, config.navigationMode === 'grid' ? indexv : undefined ); |
| 2546 | } |
| 2547 | |
| 2548 | } |
| 2549 | |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 2550 | function navigateUp({skipFragments=false}={}) { |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2551 | |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 2552 | // Scroll view navigation is handled independently |
| 2553 | if( scrollView.isActive() ) return scrollView.prev(); |
| 2554 | |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2555 | // Prioritize hiding fragments |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 2556 | if( ( overview.isActive() || skipFragments || fragments.prev() === false ) && availableRoutes().up ) { |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2557 | slide( indexh, indexv - 1 ); |
| 2558 | } |
| 2559 | |
| 2560 | } |
| 2561 | |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 2562 | function navigateDown({skipFragments=false}={}) { |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2563 | |
| 2564 | navigationHistory.hasNavigatedVertically = true; |
| 2565 | |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 2566 | // Scroll view navigation is handled independently |
| 2567 | if( scrollView.isActive() ) return scrollView.next(); |
| 2568 | |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2569 | // Prioritize revealing fragments |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 2570 | if( ( overview.isActive() || skipFragments || fragments.next() === false ) && availableRoutes().down ) { |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2571 | slide( indexh, indexv + 1 ); |
| 2572 | } |
| 2573 | |
| 2574 | } |
| 2575 | |
| 2576 | /** |
| 2577 | * Navigates backwards, prioritized in the following order: |
| 2578 | * 1) Previous fragment |
| 2579 | * 2) Previous vertical slide |
| 2580 | * 3) Previous horizontal slide |
| 2581 | */ |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 2582 | function navigatePrev({skipFragments=false}={}) { |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2583 | |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 2584 | // Scroll view navigation is handled independently |
| 2585 | if( scrollView.isActive() ) return scrollView.prev(); |
| 2586 | |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2587 | // Prioritize revealing fragments |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 2588 | if( skipFragments || fragments.prev() === false ) { |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2589 | if( availableRoutes().up ) { |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 2590 | navigateUp({skipFragments}); |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2591 | } |
| 2592 | else { |
| 2593 | // Fetch the previous horizontal slide, if there is one |
| 2594 | let previousSlide; |
| 2595 | |
| 2596 | if( config.rtl ) { |
| 2597 | previousSlide = Util.queryAll( dom.wrapper, HORIZONTAL_SLIDES_SELECTOR + '.future' ).pop(); |
| 2598 | } |
| 2599 | else { |
| 2600 | previousSlide = Util.queryAll( dom.wrapper, HORIZONTAL_SLIDES_SELECTOR + '.past' ).pop(); |
| 2601 | } |
| 2602 | |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 2603 | // When going backwards and arriving on a stack we start |
| 2604 | // at the bottom of the stack |
| 2605 | if( previousSlide && previousSlide.classList.contains( 'stack' ) ) { |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2606 | let v = ( previousSlide.querySelectorAll( 'section' ).length - 1 ) || undefined; |
| 2607 | let h = indexh - 1; |
| 2608 | slide( h, v ); |
| 2609 | } |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 2610 | else if( config.rtl ) { |
| 2611 | navigateRight({skipFragments}); |
| 2612 | } |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 2613 | else { |
| 2614 | navigateLeft({skipFragments}); |
| 2615 | } |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2616 | } |
| 2617 | } |
| 2618 | |
| 2619 | } |
| 2620 | |
| 2621 | /** |
| 2622 | * The reverse of #navigatePrev(). |
| 2623 | */ |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 2624 | function navigateNext({skipFragments=false}={}) { |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2625 | |
| 2626 | navigationHistory.hasNavigatedHorizontally = true; |
| 2627 | navigationHistory.hasNavigatedVertically = true; |
| 2628 | |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 2629 | // Scroll view navigation is handled independently |
| 2630 | if( scrollView.isActive() ) return scrollView.next(); |
| 2631 | |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2632 | // Prioritize revealing fragments |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 2633 | if( skipFragments || fragments.next() === false ) { |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2634 | |
| 2635 | let routes = availableRoutes(); |
| 2636 | |
| 2637 | // When looping is enabled `routes.down` is always available |
| 2638 | // so we need a separate check for when we've reached the |
| 2639 | // end of a stack and should move horizontally |
| 2640 | if( routes.down && routes.right && config.loop && isLastVerticalSlide() ) { |
| 2641 | routes.down = false; |
| 2642 | } |
| 2643 | |
| 2644 | if( routes.down ) { |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 2645 | navigateDown({skipFragments}); |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2646 | } |
| 2647 | else if( config.rtl ) { |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 2648 | navigateLeft({skipFragments}); |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2649 | } |
| 2650 | else { |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 2651 | navigateRight({skipFragments}); |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2652 | } |
| 2653 | } |
| 2654 | |
| 2655 | } |
| 2656 | |
| 2657 | |
| 2658 | // --------------------------------------------------------------------// |
| 2659 | // ----------------------------- EVENTS -------------------------------// |
| 2660 | // --------------------------------------------------------------------// |
| 2661 | |
| 2662 | /** |
| 2663 | * Called by all event handlers that are based on user |
| 2664 | * input. |
| 2665 | * |
| 2666 | * @param {object} [event] |
| 2667 | */ |
| 2668 | function onUserInput( event ) { |
| 2669 | |
| 2670 | if( config.autoSlideStoppable ) { |
| 2671 | pauseAutoSlide(); |
| 2672 | } |
| 2673 | |
| 2674 | } |
| 2675 | |
| 2676 | /** |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 2677 | * Listener for post message events posted to this window. |
| 2678 | */ |
| 2679 | function onPostMessage( event ) { |
| 2680 | |
| 2681 | let data = event.data; |
| 2682 | |
| 2683 | // Make sure we're dealing with JSON |
| 2684 | if( typeof data === 'string' && data.charAt( 0 ) === '{' && data.charAt( data.length - 1 ) === '}' ) { |
| 2685 | data = JSON.parse( data ); |
| 2686 | |
| 2687 | // Check if the requested method can be found |
| 2688 | if( data.method && typeof Reveal[data.method] === 'function' ) { |
| 2689 | |
| 2690 | if( POST_MESSAGE_METHOD_BLACKLIST.test( data.method ) === false ) { |
| 2691 | |
| 2692 | const result = Reveal[data.method].apply( Reveal, data.args ); |
| 2693 | |
| 2694 | // Dispatch a postMessage event with the returned value from |
| 2695 | // our method invocation for getter functions |
| 2696 | dispatchPostMessage( 'callback', { method: data.method, result: result } ); |
| 2697 | |
| 2698 | } |
| 2699 | else { |
| 2700 | console.warn( 'reveal.js: "'+ data.method +'" is is blacklisted from the postMessage API' ); |
| 2701 | } |
| 2702 | |
| 2703 | } |
| 2704 | } |
| 2705 | |
| 2706 | } |
| 2707 | |
| 2708 | /** |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2709 | * Event listener for transition end on the current slide. |
| 2710 | * |
| 2711 | * @param {object} [event] |
| 2712 | */ |
| 2713 | function onTransitionEnd( event ) { |
| 2714 | |
| 2715 | if( transition === 'running' && /section/gi.test( event.target.nodeName ) ) { |
| 2716 | transition = 'idle'; |
| 2717 | dispatchEvent({ |
| 2718 | type: 'slidetransitionend', |
| 2719 | data: { indexh, indexv, previousSlide, currentSlide } |
| 2720 | }); |
| 2721 | } |
| 2722 | |
| 2723 | } |
| 2724 | |
| 2725 | /** |
Christophe Dervieux | 8afae13 | 2021-12-06 15:16:42 +0100 | [diff] [blame] | 2726 | * A global listener for all click events inside of the |
| 2727 | * .slides container. |
| 2728 | * |
| 2729 | * @param {object} [event] |
| 2730 | */ |
| 2731 | function onSlidesClicked( event ) { |
| 2732 | |
| 2733 | const anchor = Util.closest( event.target, 'a[href^="#"]' ); |
| 2734 | |
| 2735 | // If a hash link is clicked, we find the target slide |
| 2736 | // and navigate to it. We previously relied on 'hashchange' |
| 2737 | // for links like these but that prevented media with |
| 2738 | // audio tracks from playing in mobile browsers since it |
| 2739 | // wasn't considered a direct interaction with the document. |
| 2740 | if( anchor ) { |
| 2741 | const hash = anchor.getAttribute( 'href' ); |
| 2742 | const indices = location.getIndicesFromHash( hash ); |
| 2743 | |
| 2744 | if( indices ) { |
| 2745 | Reveal.slide( indices.h, indices.v, indices.f ); |
| 2746 | event.preventDefault(); |
| 2747 | } |
| 2748 | } |
| 2749 | |
| 2750 | } |
| 2751 | |
| 2752 | /** |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2753 | * Handler for the window level 'resize' event. |
| 2754 | * |
| 2755 | * @param {object} [event] |
| 2756 | */ |
| 2757 | function onWindowResize( event ) { |
| 2758 | |
| 2759 | layout(); |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2760 | } |
| 2761 | |
| 2762 | /** |
| 2763 | * Handle for the window level 'visibilitychange' event. |
| 2764 | * |
| 2765 | * @param {object} [event] |
| 2766 | */ |
| 2767 | function onPageVisibilityChange( event ) { |
| 2768 | |
| 2769 | // If, after clicking a link or similar and we're coming back, |
| 2770 | // focus the document.body to ensure we can use keyboard shortcuts |
| 2771 | if( document.hidden === false && document.activeElement !== document.body ) { |
| 2772 | // Not all elements support .blur() - SVGs among them. |
| 2773 | if( typeof document.activeElement.blur === 'function' ) { |
| 2774 | document.activeElement.blur(); |
| 2775 | } |
| 2776 | document.body.focus(); |
| 2777 | } |
| 2778 | |
| 2779 | } |
| 2780 | |
| 2781 | /** |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 2782 | * Handler for the document level 'fullscreenchange' event. |
| 2783 | * |
| 2784 | * @param {object} [event] |
| 2785 | */ |
| 2786 | function onFullscreenChange( event ) { |
| 2787 | |
| 2788 | let element = document.fullscreenElement || document.webkitFullscreenElement; |
| 2789 | if( element === dom.wrapper ) { |
| 2790 | event.stopImmediatePropagation(); |
| 2791 | |
| 2792 | // Timeout to avoid layout shift in Safari |
| 2793 | setTimeout( () => { |
| 2794 | Reveal.layout(); |
| 2795 | Reveal.focus.focus(); // focus.focus :'( |
| 2796 | }, 1 ); |
| 2797 | } |
| 2798 | |
| 2799 | } |
| 2800 | |
| 2801 | /** |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2802 | * Handles clicks on links that are set to preview in the |
| 2803 | * iframe overlay. |
| 2804 | * |
| 2805 | * @param {object} event |
| 2806 | */ |
| 2807 | function onPreviewLinkClicked( event ) { |
| 2808 | |
| 2809 | if( event.currentTarget && event.currentTarget.hasAttribute( 'href' ) ) { |
| 2810 | let url = event.currentTarget.getAttribute( 'href' ); |
| 2811 | if( url ) { |
| 2812 | showPreview( url ); |
| 2813 | event.preventDefault(); |
| 2814 | } |
| 2815 | } |
| 2816 | |
| 2817 | } |
| 2818 | |
| 2819 | /** |
| 2820 | * Handles click on the auto-sliding controls element. |
| 2821 | * |
| 2822 | * @param {object} [event] |
| 2823 | */ |
| 2824 | function onAutoSlidePlayerClick( event ) { |
| 2825 | |
| 2826 | // Replay |
| 2827 | if( isLastSlide() && config.loop === false ) { |
| 2828 | slide( 0, 0 ); |
| 2829 | resumeAutoSlide(); |
| 2830 | } |
| 2831 | // Resume |
| 2832 | else if( autoSlidePaused ) { |
| 2833 | resumeAutoSlide(); |
| 2834 | } |
| 2835 | // Pause |
| 2836 | else { |
| 2837 | pauseAutoSlide(); |
| 2838 | } |
| 2839 | |
| 2840 | } |
| 2841 | |
| 2842 | |
| 2843 | // --------------------------------------------------------------------// |
| 2844 | // ------------------------------- API --------------------------------// |
| 2845 | // --------------------------------------------------------------------// |
| 2846 | |
| 2847 | // The public reveal.js API |
| 2848 | const API = { |
| 2849 | VERSION, |
| 2850 | |
| 2851 | initialize, |
| 2852 | configure, |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 2853 | destroy, |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2854 | |
| 2855 | sync, |
| 2856 | syncSlide, |
| 2857 | syncFragments: fragments.sync.bind( fragments ), |
| 2858 | |
| 2859 | // Navigation methods |
| 2860 | slide, |
| 2861 | left: navigateLeft, |
| 2862 | right: navigateRight, |
| 2863 | up: navigateUp, |
| 2864 | down: navigateDown, |
| 2865 | prev: navigatePrev, |
| 2866 | next: navigateNext, |
| 2867 | |
| 2868 | // Navigation aliases |
| 2869 | navigateLeft, navigateRight, navigateUp, navigateDown, navigatePrev, navigateNext, |
| 2870 | |
| 2871 | // Fragment methods |
| 2872 | navigateFragment: fragments.goto.bind( fragments ), |
| 2873 | prevFragment: fragments.prev.bind( fragments ), |
| 2874 | nextFragment: fragments.next.bind( fragments ), |
| 2875 | |
| 2876 | // Event binding |
| 2877 | on, |
| 2878 | off, |
| 2879 | |
| 2880 | // Legacy event binding methods left in for backwards compatibility |
| 2881 | addEventListener: on, |
| 2882 | removeEventListener: off, |
| 2883 | |
| 2884 | // Forces an update in slide layout |
| 2885 | layout, |
| 2886 | |
| 2887 | // Randomizes the order of slides |
| 2888 | shuffle, |
| 2889 | |
| 2890 | // Returns an object with the available routes as booleans (left/right/top/bottom) |
| 2891 | availableRoutes, |
| 2892 | |
| 2893 | // Returns an object with the available fragments as booleans (prev/next) |
| 2894 | availableFragments: fragments.availableRoutes.bind( fragments ), |
| 2895 | |
| 2896 | // Toggles a help overlay with keyboard shortcuts |
| 2897 | toggleHelp, |
| 2898 | |
| 2899 | // Toggles the overview mode on/off |
| 2900 | toggleOverview: overview.toggle.bind( overview ), |
| 2901 | |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 2902 | // Toggles the scroll view on/off |
| 2903 | toggleScrollView: scrollView.toggle.bind( scrollView ), |
| 2904 | |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2905 | // Toggles the "black screen" mode on/off |
| 2906 | togglePause, |
| 2907 | |
| 2908 | // Toggles the auto slide mode on/off |
| 2909 | toggleAutoSlide, |
| 2910 | |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 2911 | // Toggles visibility of the jump-to-slide UI |
| 2912 | toggleJumpToSlide, |
| 2913 | |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2914 | // Slide navigation checks |
| 2915 | isFirstSlide, |
| 2916 | isLastSlide, |
| 2917 | isLastVerticalSlide, |
| 2918 | isVerticalSlide, |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 2919 | isVerticalStack, |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2920 | |
| 2921 | // State checks |
| 2922 | isPaused, |
| 2923 | isAutoSliding, |
| 2924 | isSpeakerNotes: notes.isSpeakerNotesWindow.bind( notes ), |
| 2925 | isOverview: overview.isActive.bind( overview ), |
| 2926 | isFocused: focus.isFocused.bind( focus ), |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 2927 | |
| 2928 | isScrollView: scrollView.isActive.bind( scrollView ), |
| 2929 | isPrintView: printView.isActive.bind( printView ), |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2930 | |
| 2931 | // Checks if reveal.js has been loaded and is ready for use |
| 2932 | isReady: () => ready, |
| 2933 | |
| 2934 | // Slide preloading |
| 2935 | loadSlide: slideContent.load.bind( slideContent ), |
| 2936 | unloadSlide: slideContent.unload.bind( slideContent ), |
| 2937 | |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 2938 | // Start/stop all media inside of the current slide |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 2939 | startEmbeddedContent: () => slideContent.startEmbeddedContent( currentSlide ), |
| 2940 | stopEmbeddedContent: () => slideContent.stopEmbeddedContent( currentSlide, { unloadIframes: false } ), |
| 2941 | |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 2942 | // Preview management |
| 2943 | showPreview, |
| 2944 | hidePreview: closeOverlay, |
| 2945 | |
| 2946 | // Adds or removes all internal event listeners |
| 2947 | addEventListeners, |
| 2948 | removeEventListeners, |
| 2949 | dispatchEvent, |
| 2950 | |
| 2951 | // Facility for persisting and restoring the presentation state |
| 2952 | getState, |
| 2953 | setState, |
| 2954 | |
| 2955 | // Presentation progress on range of 0-1 |
| 2956 | getProgress, |
| 2957 | |
| 2958 | // Returns the indices of the current, or specified, slide |
| 2959 | getIndices, |
| 2960 | |
| 2961 | // Returns an Array of key:value maps of the attributes of each |
| 2962 | // slide in the deck |
| 2963 | getSlidesAttributes, |
| 2964 | |
| 2965 | // Returns the number of slides that we have passed |
| 2966 | getSlidePastCount, |
| 2967 | |
| 2968 | // Returns the total number of slides |
| 2969 | getTotalSlides, |
| 2970 | |
| 2971 | // Returns the slide element at the specified index |
| 2972 | getSlide, |
| 2973 | |
| 2974 | // Returns the previous slide element, may be null |
| 2975 | getPreviousSlide: () => previousSlide, |
| 2976 | |
| 2977 | // Returns the current slide element |
| 2978 | getCurrentSlide: () => currentSlide, |
| 2979 | |
| 2980 | // Returns the slide background element at the specified index |
| 2981 | getSlideBackground, |
| 2982 | |
| 2983 | // Returns the speaker notes string for a slide, or null |
| 2984 | getSlideNotes: notes.getSlideNotes.bind( notes ), |
| 2985 | |
| 2986 | // Returns an Array of all slides |
| 2987 | getSlides, |
| 2988 | |
| 2989 | // Returns an array with all horizontal/vertical slides in the deck |
| 2990 | getHorizontalSlides, |
| 2991 | getVerticalSlides, |
| 2992 | |
| 2993 | // Checks if the presentation contains two or more horizontal |
| 2994 | // and vertical slides |
| 2995 | hasHorizontalSlides, |
| 2996 | hasVerticalSlides, |
| 2997 | |
| 2998 | // Checks if the deck has navigated on either axis at least once |
| 2999 | hasNavigatedHorizontally: () => navigationHistory.hasNavigatedHorizontally, |
| 3000 | hasNavigatedVertically: () => navigationHistory.hasNavigatedVertically, |
| 3001 | |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 3002 | shouldAutoAnimateBetween, |
| 3003 | |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 3004 | // Adds/removes a custom key binding |
| 3005 | addKeyBinding: keyboard.addKeyBinding.bind( keyboard ), |
| 3006 | removeKeyBinding: keyboard.removeKeyBinding.bind( keyboard ), |
| 3007 | |
| 3008 | // Programmatically triggers a keyboard event |
| 3009 | triggerKey: keyboard.triggerKey.bind( keyboard ), |
| 3010 | |
| 3011 | // Registers a new shortcut to include in the help overlay |
| 3012 | registerKeyboardShortcut: keyboard.registerKeyboardShortcut.bind( keyboard ), |
| 3013 | |
| 3014 | getComputedSlideSize, |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 3015 | setCurrentScrollPage, |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 3016 | |
| 3017 | // Returns the current scale of the presentation content |
| 3018 | getScale: () => scale, |
| 3019 | |
| 3020 | // Returns the current configuration object |
| 3021 | getConfig: () => config, |
| 3022 | |
| 3023 | // Helper method, retrieves query string as a key:value map |
| 3024 | getQueryHash: Util.getQueryHash, |
| 3025 | |
Marc Kupietz | 09b7575 | 2023-10-07 09:32:19 +0200 | [diff] [blame] | 3026 | // Returns the path to the current slide as represented in the URL |
| 3027 | getSlidePath: location.getHash.bind( location ), |
| 3028 | |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 3029 | // Returns reveal.js DOM elements |
| 3030 | getRevealElement: () => revealElement, |
| 3031 | getSlidesElement: () => dom.slides, |
| 3032 | getViewportElement: () => dom.viewport, |
| 3033 | getBackgroundsElement: () => backgrounds.element, |
| 3034 | |
| 3035 | // API for registering and retrieving plugins |
| 3036 | registerPlugin: plugins.registerPlugin.bind( plugins ), |
| 3037 | hasPlugin: plugins.hasPlugin.bind( plugins ), |
| 3038 | getPlugin: plugins.getPlugin.bind( plugins ), |
| 3039 | getPlugins: plugins.getRegisteredPlugins.bind( plugins ) |
| 3040 | |
| 3041 | }; |
| 3042 | |
| 3043 | // Our internal API which controllers have access to |
| 3044 | Util.extend( Reveal, { |
| 3045 | ...API, |
| 3046 | |
| 3047 | // Methods for announcing content to screen readers |
| 3048 | announceStatus, |
| 3049 | getStatusText, |
| 3050 | |
| 3051 | // Controllers |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 3052 | focus, |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 3053 | scroll: scrollView, |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 3054 | progress, |
| 3055 | controls, |
| 3056 | location, |
| 3057 | overview, |
| 3058 | fragments, |
Marc Kupietz | 9c036a4 | 2024-05-14 13:17:25 +0200 | [diff] [blame^] | 3059 | backgrounds, |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 3060 | slideContent, |
| 3061 | slideNumber, |
| 3062 | |
| 3063 | onUserInput, |
| 3064 | closeOverlay, |
| 3065 | updateSlidesVisibility, |
| 3066 | layoutSlideContents, |
| 3067 | transformSlides, |
| 3068 | cueAutoSlide, |
| 3069 | cancelAutoSlide |
| 3070 | } ); |
| 3071 | |
| 3072 | return API; |
| 3073 | |
| 3074 | }; |