switch old toArray helper to Array.from

This commit is contained in:
Hakim El Hattab committed 2020-03-16 15:18:47 +01:00
1 parent 6ff4e9306c
commit 2540712714
10 files changed
+111 -113

No files matched your search

+1 -1
View File
@@ -5,4 +5,4 @@
*
* Copyright (C) 2020 Hakim El Hattab, https://hakim.se
*/
!function(e){var t={};function i(a){if(t[a])return t[a].exports;var s=t[a]={i:a,l:!1,exports:{}};return e[a].call(s.exports,s,s.exports,i),s.l=!0,s.exports}i.m=e,i.c=t,i.d=function(e,t,a){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(i.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)i.d(a,s,function(t){return e[t]}.bind(null,s));return a},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=0)}([function(e,t,i){"use strict";i.r(t);const a=/registerPlugin|registerKeyboardShortcut|addKeyBinding|addEventListener/,s=(e,t)=>{for(let i in t)e[i]=t[i];return e},n=e=>Array.prototype.slice.call(e),r=e=>{if("string"==typeof e){if("null"===e)return null;if("true"===e)return!0;if("false"===e)return!1;if(e.match(/^-?[\d\.]+$/))return parseFloat(e)}return e},o=(e,t)=>{e.style.transform=t},l=(e,t)=>{let i=e.parentNode;for(;i;){let e=i.matches||i.matchesSelector||i.msMatchesSelector;if(e&&e.call(i,t))return i;i=i.parentNode}return null},d=e=>{let t=document.createElement("style");return t.type="text/css",e&&e.length>0&&(t.styleSheet?t.styleSheet.cssText=e:t.appendChild(document.createTextNode(e))),document.head.appendChild(t),t},c=()=>{let e={};location.search.replace(/[A-Z0-9]+?=([\w\.%-]*)/gi,t=>{e[t.split("=").shift()]=t.split("=").pop()});for(let t in e){let i=e[t];e[t]=r(unescape(i))}return void 0!==e.dependencies&&delete e.dependencies,e},h=navigator.userAgent,u=document.createElement("div"),g=/(iphone|ipod|ipad|android)/gi.test(h)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1,v=/chrome/i.test(h)&&!/edge/i.test(h),p=/android/gi.test(h),m="zoom"in u.style&&!g&&(v||/Version\/[\d\.]+.*Safari/.test(h));class f{constructor(e){this.Reveal=e}shouldPreload(e){let t=this.Reveal.getConfig().preloadIframes;return"boolean"!=typeof t&&(t=e.hasAttribute("data-preload")),t}load(e,t={}){e.style.display=this.Reveal.getConfig().display,n(e.querySelectorAll("img[data-src], video[data-src], audio[data-src], iframe[data-src]")).forEach(e=>{("IFRAME"!==e.tagName||this.shouldPreload(e))&&(e.setAttribute("src",e.getAttribute("data-src")),e.setAttribute("data-lazy-loaded",""),e.removeAttribute("data-src"))}),n(e.querySelectorAll("video, audio")).forEach(e=>{let t=0;n(e.querySelectorAll("source[data-src]")).forEach(e=>{e.setAttribute("src",e.getAttribute("data-src")),e.removeAttribute("data-src"),e.setAttribute("data-lazy-loaded",""),t+=1}),t>0&&e.load()});let i=e.slideBackgroundElement;if(i){i.style.display="block";let a=e.slideBackgroundContentElement,s=e.getAttribute("data-background-iframe");if(!1===i.hasAttribute("data-loaded")){i.setAttribute("data-loaded","true");let n=e.getAttribute("data-background-image"),r=e.getAttribute("data-background-video"),o=e.hasAttribute("data-background-video-loop"),l=e.hasAttribute("data-background-video-muted");if(n)a.style.backgroundImage="url("+encodeURI(n)+")";else if(r&&!this.Reveal.isSpeakerNotes()){let e=document.createElement("video");o&&e.setAttribute("loop",""),l&&(e.muted=!0),g&&(e.muted=!0,e.autoplay=!0,e.setAttribute("playsinline","")),r.split(",").forEach(t=>{e.innerHTML+='<source src="'+t+'">'}),a.appendChild(e)}else if(s&&!0!==t.excludeIframes){let e=document.createElement("iframe");e.setAttribute("allowfullscreen",""),e.setAttribute("mozallowfullscreen",""),e.setAttribute("webkitallowfullscreen",""),e.setAttribute("allow","autoplay"),e.setAttribute("data-src",s),e.style.width="100%",e.style.height="100%",e.style.maxHeight="100%",e.style.maxWidth="100%",a.appendChild(e)}}let n=a.querySelector("iframe[data-src]");n&&this.shouldPreload(i)&&!/autoplay=(1|true|yes)/gi.test(s)&&n.getAttribute("src")!==s&&n.setAttribute("src",s)}}unload(e){e.style.display="none";let t=this.Reveal.getSlideBackground(e);t&&(t.style.display="none",n(t.querySelectorAll("iframe[src]")).forEach(e=>{e.removeAttribute("src")})),n(e.querySelectorAll("video[data-lazy-loaded][src], audio[data-lazy-loaded][src], iframe[data-lazy-loaded][src]")).forEach(e=>{e.setAttribute("data-src",e.getAttribute("src")),e.removeAttribute("src")}),n(e.querySelectorAll("video[data-lazy-loaded] source[src], audio source[src]")).forEach(e=>{e.setAttribute("data-src",e.getAttribute("src")),e.removeAttribute("src")})}formatEmbeddedContent(){let e=(e,t,i)=>{n(this.Reveal.getSlidesElement().querySelectorAll("iframe["+e+'*="'+t+'"]')).forEach(t=>{let a=t.getAttribute(e);a&&-1===a.indexOf(i)&&t.setAttribute(e,a+(/\?/.test(a)?"&":"?")+i)})};e("src","youtube.com/embed/","enablejsapi=1"),e("data-src","youtube.com/embed/","enablejsapiLine truncated
!function(e){var t={};function i(a){if(t[a])return t[a].exports;var s=t[a]={i:a,l:!1,exports:{}};return e[a].call(s.exports,s,s.exports,i),s.l=!0,s.exports}i.m=e,i.c=t,i.d=function(e,t,a){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(i.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)i.d(a,s,function(t){return e[t]}.bind(null,s));return a},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=0)}([function(e,t,i){"use strict";i.r(t);const a=/registerPlugin|registerKeyboardShortcut|addKeyBinding|addEventListener/,s=(e,t)=>{for(let i in t)e[i]=t[i];return e},n=(e,t)=>Array.from(e.querySelectorAll(t)),r=e=>{if("string"==typeof e){if("null"===e)return null;if("true"===e)return!0;if("false"===e)return!1;if(e.match(/^-?[\d\.]+$/))return parseFloat(e)}return e},o=(e,t)=>{e.style.transform=t},l=(e,t)=>{let i=e.parentNode;for(;i;){let e=i.matches||i.matchesSelector||i.msMatchesSelector;if(e&&e.call(i,t))return i;i=i.parentNode}return null},d=e=>{let t=document.createElement("style");return t.type="text/css",e&&e.length>0&&(t.styleSheet?t.styleSheet.cssText=e:t.appendChild(document.createTextNode(e))),document.head.appendChild(t),t},c=()=>{let e={};location.search.replace(/[A-Z0-9]+?=([\w\.%-]*)/gi,t=>{e[t.split("=").shift()]=t.split("=").pop()});for(let t in e){let i=e[t];e[t]=r(unescape(i))}return void 0!==e.dependencies&&delete e.dependencies,e},h=navigator.userAgent,u=document.createElement("div"),g=/(iphone|ipod|ipad|android)/gi.test(h)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1,v=/chrome/i.test(h)&&!/edge/i.test(h),p=/android/gi.test(h),m="zoom"in u.style&&!g&&(v||/Version\/[\d\.]+.*Safari/.test(h));class f{constructor(e){this.Reveal=e}shouldPreload(e){let t=this.Reveal.getConfig().preloadIframes;return"boolean"!=typeof t&&(t=e.hasAttribute("data-preload")),t}load(e,t={}){e.style.display=this.Reveal.getConfig().display,n(e,"img[data-src], video[data-src], audio[data-src], iframe[data-src]").forEach(e=>{("IFRAME"!==e.tagName||this.shouldPreload(e))&&(e.setAttribute("src",e.getAttribute("data-src")),e.setAttribute("data-lazy-loaded",""),e.removeAttribute("data-src"))}),n(e,"video, audio").forEach(e=>{let t=0;n(e,"source[data-src]").forEach(e=>{e.setAttribute("src",e.getAttribute("data-src")),e.removeAttribute("data-src"),e.setAttribute("data-lazy-loaded",""),t+=1}),t>0&&e.load()});let i=e.slideBackgroundElement;if(i){i.style.display="block";let a=e.slideBackgroundContentElement,s=e.getAttribute("data-background-iframe");if(!1===i.hasAttribute("data-loaded")){i.setAttribute("data-loaded","true");let n=e.getAttribute("data-background-image"),r=e.getAttribute("data-background-video"),o=e.hasAttribute("data-background-video-loop"),l=e.hasAttribute("data-background-video-muted");if(n)a.style.backgroundImage="url("+encodeURI(n)+")";else if(r&&!this.Reveal.isSpeakerNotes()){let e=document.createElement("video");o&&e.setAttribute("loop",""),l&&(e.muted=!0),g&&(e.muted=!0,e.autoplay=!0,e.setAttribute("playsinline","")),r.split(",").forEach(t=>{e.innerHTML+='<source src="'+t+'">'}),a.appendChild(e)}else if(s&&!0!==t.excludeIframes){let e=document.createElement("iframe");e.setAttribute("allowfullscreen",""),e.setAttribute("mozallowfullscreen",""),e.setAttribute("webkitallowfullscreen",""),e.setAttribute("allow","autoplay"),e.setAttribute("data-src",s),e.style.width="100%",e.style.height="100%",e.style.maxHeight="100%",e.style.maxWidth="100%",a.appendChild(e)}}let n=a.querySelector("iframe[data-src]");n&&this.shouldPreload(i)&&!/autoplay=(1|true|yes)/gi.test(s)&&n.getAttribute("src")!==s&&n.setAttribute("src",s)}}unload(e){e.style.display="none";let t=this.Reveal.getSlideBackground(e);t&&(t.style.display="none",n(t,"iframe[src]").forEach(e=>{e.removeAttribute("src")})),n(e,"video[data-lazy-loaded][src], audio[data-lazy-loaded][src], iframe[data-lazy-loaded][src]").forEach(e=>{e.setAttribute("data-src",e.getAttribute("src")),e.removeAttribute("src")}),n(e,"video[data-lazy-loaded] source[src], audio source[src]").forEach(e=>{e.setAttribute("data-src",e.getAttribute("src")),e.removeAttribute("src")})}formatEmbeddedContent(){let e=(e,t,i)=>{n(this.Reveal.getSlidesElement(),"iframe["+e+'*="'+t+'"]').forEach(t=>{let a=t.getAttribute(e);a&&-1===a.indexOf(i)&&t.setAttribute(e,a+(/\?/.test(a)?"&":"?")+i)})};e("src","youtube.com/embed/","enablejsapi=1"),e("data-src","youtube.com/embed/","enablejsapi=1"),e("src","player.vimeo.com/","api=1"),e("data-src","player.vimeo.com/","api=1")}startEmbeddedContent(e){e&&!this.RLine truncated
+3 -3
View File
@@ -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;
} );
+4 -4
View File
@@ -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' );
+7 -7
View File
@@ -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' );
+6 -6
View File
@@ -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 );
+7 -7
View File
@@ -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, '' );
} );
+4 -4
View File
@@ -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' );
} );
}
+17 -17
View File
@@ -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' );
+22 -58
View File
@@ -23,12 +23,13 @@ import {
} from './utils/constants.js'
import {
extend,
toArray,
queryAll,
deserialize,
transformElement,
createSingletonNode,
closestParent,
getQueryHash
getQueryHash,
getRemainingHeight
} from './utils/util.js'
/**
@@ -298,7 +299,7 @@ export default function( revealElement, options ) {
let isDisplayHidden = window.getComputedStyle( node )['display'] === 'none';
if( isAriaHidden !== 'true' && !isDisplayHidden ) {
toArray( node.childNodes ).forEach( child => {
Array.from( node.childNodes ).forEach( child => {
text += getStatusText( child );
} );
@@ -559,43 +560,6 @@ export default function( revealElement, options ) {
}
/**
* Returns the remaining height within the parent of the
* target element.
*
* remaining height = [ configured parent height ] - [ current parent height ]
*
* @param {HTMLElement} element
* @param {number} [height]
*/
function getRemainingHeight( element, height = 0 ) {
if( element ) {
let newHeight, oldHeight = element.style.height;
// Change the .stretch element height to 0 in order find the height of all
// the other elements
element.style.height = '0px';
// In Overview mode, the parent (.slide) height is set of 700px.
// Restore it temporarily to its natural height.
element.parentNode.style.height = 'auto';
newHeight = height - element.parentNode.offsetHeight;
// Restore the old height, just in case
element.style.height = oldHeight + 'px';
// Clear the parent (.slide) height. .removeProperty works in IE9+
element.parentNode.style.removeProperty('height');
return newHeight;
}
return height;
}
/**
* Dispatches an event of the specified type from the
* reveal DOM element.
@@ -641,7 +605,7 @@ export default function( revealElement, options ) {
*/
function enablePreviewLinks( selector = 'a' ) {
toArray( dom.wrapper.querySelectorAll( selector ) ).forEach( element => {
Array.from( dom.wrapper.querySelectorAll( selector ) ).forEach( element => {
if( /^(http|www)/gi.test( element.getAttribute( 'href' ) ) ) {
element.addEventListener( 'click', onPreviewLinkClicked, false );
}
@@ -654,7 +618,7 @@ export default function( revealElement, options ) {
*/
function disablePreviewLinks( selector = 'a' ) {
toArray( dom.wrapper.querySelectorAll( selector ) ).forEach( element => {
Array.from( dom.wrapper.querySelectorAll( selector ) ).forEach( element => {
if( /^(http|www)/gi.test( element.getAttribute( 'href' ) ) ) {
element.removeEventListener( 'click', onPreviewLinkClicked, false );
}
@@ -864,7 +828,7 @@ export default function( revealElement, options ) {
}
// Select all slides, vertical and horizontal
const slides = toArray( dom.wrapper.querySelectorAll( SLIDES_SELECTOR ) );
const slides = Array.from( dom.wrapper.querySelectorAll( SLIDES_SELECTOR ) );
for( let i = 0, len = slides.length; i < len; i++ ) {
const slide = slides[ i ];
@@ -923,7 +887,7 @@ export default function( revealElement, options ) {
function layoutSlideContents( width, height ) {
// Handle sizing of elements with the 'stretch' class
toArray( dom.slides.querySelectorAll( 'section > .stretch' ) ).forEach( element => {
queryAll( dom.slides, 'section > .stretch' ).forEach( element => {
// Determine how much vertical space we can use
let remainingHeight = getRemainingHeight( element, height );
@@ -1340,7 +1304,6 @@ export default function( revealElement, options ) {
// Announce the current slide contents to screen readers
announceStatus( getStatusText( currentSlide ) );
progress.update();
controls.update();
notes.update();
@@ -1459,7 +1422,7 @@ export default function( revealElement, options ) {
getHorizontalSlides().forEach( horizontalSlide => {
toArray( horizontalSlide.querySelectorAll( 'section' ) ).forEach( ( verticalSlide, y ) => {
queryAll( horizontalSlide, 'section' ).forEach( ( verticalSlide, y ) => {
if( y > 0 ) {
verticalSlide.classList.remove( 'present' );
@@ -1506,7 +1469,7 @@ export default function( revealElement, options ) {
// Select all slides and convert the NodeList result to
// an array
let slides = toArray( dom.wrapper.querySelectorAll( selector ) ),
let slides = queryAll( dom.wrapper, selector ),
slidesLength = slides.length;
let printMode = print.isPrintingPDF();
@@ -1553,7 +1516,7 @@ export default function( revealElement, options ) {
if( config.fragments ) {
// Show all fragments in prior slides
toArray( element.querySelectorAll( '.fragment' ) ).forEach( fragment => {
queryAll( element, '.fragment' ).forEach( fragment => {
fragment.classList.add( 'visible' );
fragment.classList.remove( 'current-fragment' );
} );
@@ -1565,7 +1528,7 @@ export default function( revealElement, options ) {
if( config.fragments ) {
// Hide all fragments in future slides
toArray( element.querySelectorAll( '.fragment.visible' ) ).forEach( fragment => {
queryAll( element, '.fragment.visible' ).forEach( fragment => {
fragment.classList.remove( 'visible', 'current-fragment' );
} );
}
@@ -1640,7 +1603,7 @@ export default function( revealElement, options ) {
for( let x = 0; x < horizontalSlidesLength; x++ ) {
let horizontalSlide = horizontalSlides[x];
let verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) ),
let verticalSlides = queryAll( horizontalSlide, 'section' ),
verticalSlidesLength = verticalSlides.length;
// Determine how far away this slide is from the present
@@ -1867,7 +1830,7 @@ export default function( revealElement, options ) {
// If this is a vertical slide, grab the vertical index
if( isVertical ) {
v = Math.max( toArray( slide.parentNode.querySelectorAll( 'section' ) ).indexOf( slide ), 0 );
v = Math.max( queryAll( slide.parentNode, 'section' ).indexOf( slide ), 0 );
}
}
@@ -1893,7 +1856,7 @@ export default function( revealElement, options ) {
*/
function getSlides() {
return toArray( dom.wrapper.querySelectorAll( SLIDES_SELECTOR + ':not(.stack):not([data-visibility="uncounted"])' ) );
return queryAll( dom.wrapper, SLIDES_SELECTOR + ':not(.stack):not([data-visibility="uncounted"])' );
}
@@ -1904,7 +1867,7 @@ export default function( revealElement, options ) {
*/
function getHorizontalSlides() {
return toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
return queryAll( dom.wrapper, HORIZONTAL_SLIDES_SELECTOR );
}
@@ -1913,7 +1876,7 @@ export default function( revealElement, options ) {
*/
function getVerticalSlides() {
return toArray( dom.wrapper.querySelectorAll( '.slides>section>section' ) );
return queryAll( dom.wrapper, '.slides>section>section' );
}
@@ -1922,7 +1885,7 @@ export default function( revealElement, options ) {
*/
function getVerticalStacks() {
return toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.stack') );
return queryAll( dom.wrapper, HORIZONTAL_SLIDES_SELECTOR + '.stack');
}
@@ -2102,7 +2065,7 @@ export default function( revealElement, options ) {
// is divided up into fragments.
// playbackRate is accounted for in the duration.
if( currentSlide.querySelectorAll( '.fragment' ).length === 0 ) {
toArray( currentSlide.querySelectorAll( 'video, audio' ) ).forEach( el => {
queryAll( currentSlide, 'video, audio' ).forEach( el => {
if( el.hasAttribute( 'data-autoplay' ) ) {
if( autoSlide && (el.duration * 1000 / el.playbackRate ) > autoSlide ) {
autoSlide = ( el.duration * 1000 / el.playbackRate ) + 1000;
@@ -2244,10 +2207,10 @@ export default function( revealElement, options ) {
let previousSlide;
if( config.rtl ) {
previousSlide = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.future' ) ).pop();
previousSlide = queryAll( dom.wrapper, HORIZONTAL_SLIDES_SELECTOR + '.future' ).pop();
}
else {
previousSlide = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.past' ) ).pop();
previousSlide = queryAll( dom.wrapper, HORIZONTAL_SLIDES_SELECTOR + '.past' ).pop();
}
if( previousSlide ) {
@@ -2607,6 +2570,7 @@ export default function( revealElement, options ) {
// Returns reveal.js DOM elements
getRevealElement: () => dom.wrapper || document.querySelector( '.reveal' ),
getSlidesElement: () => dom.slides,
getBackgroundsElement: () => backgrounds.element,
// Checks if reveal.js has been loaded and is ready for use
isReady: () => ready,
+40 -6
View File
@@ -16,14 +16,11 @@ export const extend = ( a, b ) => {
}
/**
* Converts the target object to an array.
*
* @param {object} o
* @return {object[]}
* querySelectorAll but returns an Array.
*/
export const toArray = ( o ) => {
export const queryAll = ( el, selector ) => {
return Array.prototype.slice.call( o );
return Array.from( el.querySelectorAll( selector ) );
}
@@ -220,4 +217,41 @@ export const getQueryHash = () => {
return query;
}
/**
* Returns the remaining height within the parent of the
* target element.
*
* remaining height = [ configured parent height ] - [ current parent height ]
*
* @param {HTMLElement} element
* @param {number} [height]
*/
export const getRemainingHeight = ( element, height = 0 ) => {
if( element ) {
let newHeight, oldHeight = element.style.height;
// Change the .stretch element height to 0 in order find the height of all
// the other elements
element.style.height = '0px';
// In Overview mode, the parent (.slide) height is set of 700px.
// Restore it temporarily to its natural height.
element.parentNode.style.height = 'auto';
newHeight = height - element.parentNode.offsetHeight;
// Restore the old height, just in case
element.style.height = oldHeight + 'px';
// Clear the parent (.slide) height. .removeProperty works in IE9+
element.parentNode.style.removeProperty('height');
return newHeight;
}
return height;
}