switch old toArray helper to Array.from
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { extend, toArray, createStyleSheet } from '../utils/util.js'
|
||||
import { queryAll, extend, createStyleSheet } from '../utils/util.js'
|
||||
|
||||
/**
|
||||
* Automatically animates matching elements across
|
||||
@ -87,12 +87,12 @@ export default class AutoAnimate {
|
||||
reset() {
|
||||
|
||||
// Reset slides
|
||||
toArray( this.Reveal.getRevealElement().querySelectorAll( '[data-auto-animate]:not([data-auto-animate=""])' ) ).forEach( element => {
|
||||
queryAll( this.Reveal.getRevealElement(), '[data-auto-animate]:not([data-auto-animate=""])' ).forEach( element => {
|
||||
element.dataset.autoAnimate = '';
|
||||
} );
|
||||
|
||||
// Reset elements
|
||||
toArray( this.Reveal.getRevealElement().querySelectorAll( '[data-auto-animate-target]' ) ).forEach( element => {
|
||||
queryAll( this.Reveal.getRevealElement(), '[data-auto-animate-target]' ).forEach( element => {
|
||||
delete element.dataset.autoAnimateTarget;
|
||||
} );
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { toArray } from '../utils/util.js'
|
||||
import { queryAll } from '../utils/util.js'
|
||||
import { colorToRgb, colorBrightness } from '../utils/color.js'
|
||||
|
||||
/**
|
||||
@ -39,7 +39,7 @@ export default class Backgrounds {
|
||||
let backgroundStack = this.createBackground( slideh, this.element );
|
||||
|
||||
// Iterate over all vertical slides
|
||||
toArray( slideh.querySelectorAll( 'section' ) ).forEach( slidev => {
|
||||
queryAll( slideh, 'section' ).forEach( slidev => {
|
||||
|
||||
this.createBackground( slidev, backgroundStack );
|
||||
|
||||
@ -238,7 +238,7 @@ export default class Backgrounds {
|
||||
|
||||
// Update the classes of all backgrounds to match the
|
||||
// states of their slides (past/present/future)
|
||||
toArray( this.element.childNodes ).forEach( ( backgroundh, h ) => {
|
||||
Array.from( this.element.childNodes ).forEach( ( backgroundh, h ) => {
|
||||
|
||||
backgroundh.classList.remove( 'past', 'present', 'future' );
|
||||
|
||||
@ -256,7 +256,7 @@ export default class Backgrounds {
|
||||
}
|
||||
|
||||
if( includeAll || h === indices.h ) {
|
||||
toArray( backgroundh.querySelectorAll( '.slide-background' ) ).forEach( ( backgroundv, v ) => {
|
||||
queryAll( backgroundh, '.slide-background' ).forEach( ( backgroundv, v ) => {
|
||||
|
||||
backgroundv.classList.remove( 'past', 'present', 'future' );
|
||||
|
||||
|
14
js/controllers/controls.js
vendored
14
js/controllers/controls.js
vendored
@ -1,4 +1,4 @@
|
||||
import { toArray } from '../utils/util.js'
|
||||
import { queryAll } from '../utils/util.js'
|
||||
import { isAndroid } from '../utils/device.js'
|
||||
|
||||
/**
|
||||
@ -44,12 +44,12 @@ export default class Controls {
|
||||
this.Reveal.getRevealElement().appendChild( this.element );
|
||||
|
||||
// There can be multiple instances of controls throughout the page
|
||||
this.controlsLeft = toArray( revealElement.querySelectorAll( '.navigate-left' ) );
|
||||
this.controlsRight = toArray( revealElement.querySelectorAll( '.navigate-right' ) );
|
||||
this.controlsUp = toArray( revealElement.querySelectorAll( '.navigate-up' ) );
|
||||
this.controlsDown = toArray( revealElement.querySelectorAll( '.navigate-down' ) );
|
||||
this.controlsPrev = toArray( revealElement.querySelectorAll( '.navigate-prev' ) );
|
||||
this.controlsNext = toArray( revealElement.querySelectorAll( '.navigate-next' ) );
|
||||
this.controlsLeft = queryAll( revealElement, '.navigate-left' );
|
||||
this.controlsRight = queryAll( revealElement, '.navigate-right' );
|
||||
this.controlsUp = queryAll( revealElement, '.navigate-up' );
|
||||
this.controlsDown = queryAll( revealElement, '.navigate-down' );
|
||||
this.controlsPrev = queryAll( revealElement, '.navigate-prev' );
|
||||
this.controlsNext = queryAll( revealElement, '.navigate-next' );
|
||||
|
||||
// The left, right and down arrows in the standard reveal.js controls
|
||||
this.controlsRightArrow = this.element.querySelector( '.navigate-right' );
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { extend, toArray } from '../utils/util.js'
|
||||
import { extend, queryAll } from '../utils/util.js'
|
||||
|
||||
/**
|
||||
* Handles sorting and navigation of slide fragments.
|
||||
@ -33,7 +33,7 @@ export default class Fragments {
|
||||
*/
|
||||
disable() {
|
||||
|
||||
toArray( this.Reveal.getSlidesElement().querySelectorAll( '.fragment' ) ).forEach( element => {
|
||||
queryAll( this.Reveal.getSlidesElement(), '.fragment' ).forEach( element => {
|
||||
element.classList.add( 'visible' );
|
||||
element.classList.remove( 'current-fragment' );
|
||||
} );
|
||||
@ -46,7 +46,7 @@ export default class Fragments {
|
||||
*/
|
||||
enable() {
|
||||
|
||||
toArray( this.Reveal.getSlidesElement().querySelectorAll( '.fragment' ) ).forEach( element => {
|
||||
queryAll( this.Reveal.getSlidesElement(), '.fragment' ).forEach( element => {
|
||||
element.classList.remove( 'visible' );
|
||||
element.classList.remove( 'current-fragment' );
|
||||
} );
|
||||
@ -98,7 +98,7 @@ export default class Fragments {
|
||||
*/
|
||||
sort( fragments, grouped = false ) {
|
||||
|
||||
fragments = toArray( fragments );
|
||||
fragments = Array.from( fragments );
|
||||
|
||||
let ordered = [],
|
||||
unordered = [],
|
||||
@ -151,7 +151,7 @@ export default class Fragments {
|
||||
|
||||
this.Reveal.getHorizontalSlides().forEach( horizontalSlide => {
|
||||
|
||||
let verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
|
||||
let verticalSlides = queryAll( horizontalSlide, 'section' );
|
||||
verticalSlides.forEach( ( verticalSlide, y ) => {
|
||||
|
||||
this.sort( verticalSlide.querySelectorAll( '.fragment' ) );
|
||||
@ -197,7 +197,7 @@ export default class Fragments {
|
||||
}
|
||||
}
|
||||
|
||||
toArray( fragments ).forEach( ( el, i ) => {
|
||||
Array.from( fragments ).forEach( ( el, i ) => {
|
||||
|
||||
if( el.hasAttribute( 'data-fragment-index' ) ) {
|
||||
i = parseInt( el.getAttribute( 'data-fragment-index' ), 10 );
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { SLIDES_SELECTOR } from '../utils/constants.js'
|
||||
import { extend, toArray, transformElement } from '../utils/util.js'
|
||||
import { extend, queryAll, transformElement } from '../utils/util.js'
|
||||
|
||||
/**
|
||||
* Handles all logic related to the overview mode
|
||||
@ -38,7 +38,7 @@ export default class Overview {
|
||||
this.Reveal.getSlidesElement().appendChild( this.Reveal.getBackgroundsElement() );
|
||||
|
||||
// Clicking on an overview slide navigates to it
|
||||
toArray( this.Reveal.getRevealElement().querySelectorAll( SLIDES_SELECTOR ) ).forEach( slide => {
|
||||
queryAll( this.Reveal.getRevealElement(), SLIDES_SELECTOR ).forEach( slide => {
|
||||
if( !slide.classList.contains( 'stack' ) ) {
|
||||
slide.addEventListener( 'click', this.onSlideClicked, true );
|
||||
}
|
||||
@ -91,7 +91,7 @@ export default class Overview {
|
||||
|
||||
if( hslide.classList.contains( 'stack' ) ) {
|
||||
|
||||
toArray( hslide.querySelectorAll( 'section' ) ).forEach( ( vslide, v ) => {
|
||||
queryAll( hslide, 'section' ).forEach( ( vslide, v ) => {
|
||||
vslide.setAttribute( 'data-index-h', h );
|
||||
vslide.setAttribute( 'data-index-v', v );
|
||||
|
||||
@ -102,10 +102,10 @@ export default class Overview {
|
||||
} );
|
||||
|
||||
// Layout slide backgrounds
|
||||
toArray( this.Reveal.getBackgroundsElement().childNodes ).forEach( ( hbackground, h ) => {
|
||||
Array.from( this.Reveal.getBackgroundsElement().childNodes ).forEach( ( hbackground, h ) => {
|
||||
transformElement( hbackground, 'translate3d(' + ( h * this.overviewSlideWidth ) + 'px, 0, 0)' );
|
||||
|
||||
toArray( hbackground.querySelectorAll( '.slide-background' ) ).forEach( ( vbackground, v ) => {
|
||||
queryAll( hbackground, '.slide-background' ).forEach( ( vbackground, v ) => {
|
||||
transformElement( vbackground, 'translate3d(0, ' + ( v * this.overviewSlideHeight ) + 'px, 0)' );
|
||||
} );
|
||||
} );
|
||||
@ -158,14 +158,14 @@ export default class Overview {
|
||||
this.Reveal.getRevealElement().appendChild( this.Reveal.getBackgroundsElement() );
|
||||
|
||||
// Clean up changes made to slides
|
||||
toArray( this.Reveal.getRevealElement().querySelectorAll( SLIDES_SELECTOR ) ).forEach( slide => {
|
||||
queryAll( this.Reveal.getRevealElement(), SLIDES_SELECTOR ).forEach( slide => {
|
||||
transformElement( slide, '' );
|
||||
|
||||
slide.removeEventListener( 'click', this.onSlideClicked, true );
|
||||
} );
|
||||
|
||||
// Clean up changes made to backgrounds
|
||||
toArray( this.Reveal.getBackgroundsElement().querySelectorAll( '.slide-background' ) ).forEach( background => {
|
||||
queryAll( this.Reveal.getBackgroundsElement(), '.slide-background' ).forEach( background => {
|
||||
transformElement( background, '' );
|
||||
} );
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { SLIDES_SELECTOR } from '../utils/constants.js'
|
||||
import { toArray, createStyleSheet } from '../utils/util.js'
|
||||
import { queryAll, createStyleSheet } from '../utils/util.js'
|
||||
|
||||
/**
|
||||
* Setups up our presentation for printing/exporting to PDF.
|
||||
@ -45,12 +45,12 @@ export default class Print {
|
||||
|
||||
// Compute slide numbers now, before we start duplicating slides
|
||||
let doingSlideNumbers = config.slideNumber && /all|print/i.test( config.showSlideNumber );
|
||||
toArray( this.Reveal.getRevealElement().querySelectorAll( SLIDES_SELECTOR ) ).forEach( function( slide ) {
|
||||
queryAll( this.Reveal.getRevealElement(), SLIDES_SELECTOR ).forEach( function( slide ) {
|
||||
slide.setAttribute( 'data-slide-number', this.Reveal.slideNumber.getSlideNumber( slide ) );
|
||||
}, this );
|
||||
|
||||
// Slide and slide background layout
|
||||
toArray( this.Reveal.getRevealElement().querySelectorAll( SLIDES_SELECTOR ) ).forEach( function( slide ) {
|
||||
queryAll( this.Reveal.getRevealElement(), SLIDES_SELECTOR ).forEach( function( slide ) {
|
||||
|
||||
// Vertical stacks are not centred since their section
|
||||
// children will be
|
||||
@ -169,7 +169,7 @@ export default class Print {
|
||||
}
|
||||
// Show all fragments
|
||||
else {
|
||||
toArray( page.querySelectorAll( '.fragment:not(.fade-out)' ) ).forEach( function( fragment ) {
|
||||
queryAll( page, '.fragment:not(.fade-out)' ).forEach( function( fragment ) {
|
||||
fragment.classList.add( 'visible' );
|
||||
} );
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { HORIZONTAL_SLIDES_SELECTOR, VERTICAL_SLIDES_SELECTOR } from '../utils/constants.js'
|
||||
import { extend, toArray, closestParent } from '../utils/util.js'
|
||||
import { extend, queryAll, closestParent } from '../utils/util.js'
|
||||
import { isMobile } from '../utils/device.js'
|
||||
|
||||
/**
|
||||
@ -47,7 +47,7 @@ export default class SlideContent {
|
||||
slide.style.display = this.Reveal.getConfig().display;
|
||||
|
||||
// Media elements with data-src attributes
|
||||
toArray( slide.querySelectorAll( 'img[data-src], video[data-src], audio[data-src], iframe[data-src]' ) ).forEach( element => {
|
||||
queryAll( slide, 'img[data-src], video[data-src], audio[data-src], iframe[data-src]' ).forEach( element => {
|
||||
if( element.tagName !== 'IFRAME' || this.shouldPreload( element ) ) {
|
||||
element.setAttribute( 'src', element.getAttribute( 'data-src' ) );
|
||||
element.setAttribute( 'data-lazy-loaded', '' );
|
||||
@ -56,10 +56,10 @@ export default class SlideContent {
|
||||
} );
|
||||
|
||||
// Media elements with <source> children
|
||||
toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( media => {
|
||||
queryAll( slide, 'video, audio' ).forEach( media => {
|
||||
let sources = 0;
|
||||
|
||||
toArray( media.querySelectorAll( 'source[data-src]' ) ).forEach( source => {
|
||||
queryAll( media, 'source[data-src]' ).forEach( source => {
|
||||
source.setAttribute( 'src', source.getAttribute( 'data-src' ) );
|
||||
source.removeAttribute( 'data-src' );
|
||||
source.setAttribute( 'data-lazy-loaded', '' );
|
||||
@ -176,19 +176,19 @@ export default class SlideContent {
|
||||
background.style.display = 'none';
|
||||
|
||||
// Unload any background iframes
|
||||
toArray( background.querySelectorAll( 'iframe[src]' ) ).forEach( element => {
|
||||
queryAll( background, 'iframe[src]' ).forEach( element => {
|
||||
element.removeAttribute( 'src' );
|
||||
} );
|
||||
}
|
||||
|
||||
// Reset lazy-loaded media elements with src attributes
|
||||
toArray( slide.querySelectorAll( 'video[data-lazy-loaded][src], audio[data-lazy-loaded][src], iframe[data-lazy-loaded][src]' ) ).forEach( element => {
|
||||
queryAll( slide, 'video[data-lazy-loaded][src], audio[data-lazy-loaded][src], iframe[data-lazy-loaded][src]' ).forEach( element => {
|
||||
element.setAttribute( 'data-src', element.getAttribute( 'src' ) );
|
||||
element.removeAttribute( 'src' );
|
||||
} );
|
||||
|
||||
// Reset lazy-loaded media elements with <source> children
|
||||
toArray( slide.querySelectorAll( 'video[data-lazy-loaded] source[src], audio source[src]' ) ).forEach( source => {
|
||||
queryAll( slide, 'video[data-lazy-loaded] source[src], audio source[src]' ).forEach( source => {
|
||||
source.setAttribute( 'data-src', source.getAttribute( 'src' ) );
|
||||
source.removeAttribute( 'src' );
|
||||
} );
|
||||
@ -201,7 +201,7 @@ export default class SlideContent {
|
||||
formatEmbeddedContent() {
|
||||
|
||||
let _appendParamToIframeSource = ( sourceAttribute, sourceURL, param ) => {
|
||||
toArray( this.Reveal.getSlidesElement().querySelectorAll( 'iframe['+ sourceAttribute +'*="'+ sourceURL +'"]' ) ).forEach( el => {
|
||||
queryAll( this.Reveal.getSlidesElement(), 'iframe['+ sourceAttribute +'*="'+ sourceURL +'"]' ).forEach( el => {
|
||||
let src = el.getAttribute( sourceAttribute );
|
||||
if( src && src.indexOf( param ) === -1 ) {
|
||||
el.setAttribute( sourceAttribute, src + ( !/\?/.test( src ) ? '?' : '&' ) + param );
|
||||
@ -230,14 +230,14 @@ export default class SlideContent {
|
||||
if( element && !this.Reveal.isSpeakerNotes() ) {
|
||||
|
||||
// Restart GIFs
|
||||
toArray( element.querySelectorAll( 'img[src$=".gif"]' ) ).forEach( el => {
|
||||
queryAll( element, 'img[src$=".gif"]' ).forEach( el => {
|
||||
// Setting the same unchanged source like this was confirmed
|
||||
// to work in Chrome, FF & Safari
|
||||
el.setAttribute( 'src', el.getAttribute( 'src' ) );
|
||||
} );
|
||||
|
||||
// HTML5 media elements
|
||||
toArray( element.querySelectorAll( 'video, audio' ) ).forEach( el => {
|
||||
queryAll( element, 'video, audio' ).forEach( el => {
|
||||
if( closestParent( el, '.fragment' ) && !closestParent( el, '.fragment.visible' ) ) {
|
||||
return;
|
||||
}
|
||||
@ -285,7 +285,7 @@ export default class SlideContent {
|
||||
} );
|
||||
|
||||
// Normal iframes
|
||||
toArray( element.querySelectorAll( 'iframe[src]' ) ).forEach( el => {
|
||||
queryAll( element, 'iframe[src]' ).forEach( el => {
|
||||
if( closestParent( el, '.fragment' ) && !closestParent( el, '.fragment.visible' ) ) {
|
||||
return;
|
||||
}
|
||||
@ -294,7 +294,7 @@ export default class SlideContent {
|
||||
} );
|
||||
|
||||
// Lazy loading iframes
|
||||
toArray( element.querySelectorAll( 'iframe[data-src]' ) ).forEach( el => {
|
||||
queryAll( element, 'iframe[data-src]' ).forEach( el => {
|
||||
if( closestParent( el, '.fragment' ) && !closestParent( el, '.fragment.visible' ) ) {
|
||||
return;
|
||||
}
|
||||
@ -390,7 +390,7 @@ export default class SlideContent {
|
||||
|
||||
if( element && element.parentNode ) {
|
||||
// HTML5 media elements
|
||||
toArray( element.querySelectorAll( 'video, audio' ) ).forEach( el => {
|
||||
queryAll( element, 'video, audio' ).forEach( el => {
|
||||
if( !el.hasAttribute( 'data-ignore' ) && typeof el.pause === 'function' ) {
|
||||
el.setAttribute('data-paused-by-reveal', '');
|
||||
el.pause();
|
||||
@ -398,20 +398,20 @@ export default class SlideContent {
|
||||
} );
|
||||
|
||||
// Generic postMessage API for non-lazy loaded iframes
|
||||
toArray( element.querySelectorAll( 'iframe' ) ).forEach( el => {
|
||||
queryAll( element, 'iframe' ).forEach( el => {
|
||||
if( el.contentWindow ) el.contentWindow.postMessage( 'slide:stop', '*' );
|
||||
el.removeEventListener( 'load', this.startEmbeddedIframe );
|
||||
});
|
||||
|
||||
// YouTube postMessage API
|
||||
toArray( element.querySelectorAll( 'iframe[src*="youtube.com/embed/"]' ) ).forEach( el => {
|
||||
queryAll( element, 'iframe[src*="youtube.com/embed/"]' ).forEach( el => {
|
||||
if( !el.hasAttribute( 'data-ignore' ) && el.contentWindow && typeof el.contentWindow.postMessage === 'function' ) {
|
||||
el.contentWindow.postMessage( '{"event":"command","func":"pauseVideo","args":""}', '*' );
|
||||
}
|
||||
});
|
||||
|
||||
// Vimeo postMessage API
|
||||
toArray( element.querySelectorAll( 'iframe[src*="player.vimeo.com/"]' ) ).forEach( el => {
|
||||
queryAll( element, 'iframe[src*="player.vimeo.com/"]' ).forEach( el => {
|
||||
if( !el.hasAttribute( 'data-ignore' ) && el.contentWindow && typeof el.contentWindow.postMessage === 'function' ) {
|
||||
el.contentWindow.postMessage( '{"method":"pause"}', '*' );
|
||||
}
|
||||
@ -419,7 +419,7 @@ export default class SlideContent {
|
||||
|
||||
if( options.unloadIframes === true ) {
|
||||
// Unload lazy-loaded iframes
|
||||
toArray( element.querySelectorAll( 'iframe[data-src]' ) ).forEach( el => {
|
||||
queryAll( element, 'iframe[data-src]' ).forEach( el => {
|
||||
// Only removing the src doesn't actually unload the frame
|
||||
// in all browsers (Firefox) so we set it to blank first
|
||||
el.setAttribute( 'src', 'about:blank' );
|
||||
|
Reference in New Issue
Block a user