App-revealup
view release on metacpan or search on metacpan
share/revealjs/js/reveal.js view on Meta::CPAN
// Special setup and config is required when printing to PDF
if( print.isPrintingPDF() ) {
removeEventListeners();
// The document needs to have loaded for the PDF layout
// measurements to be accurate
if( document.readyState === 'complete' ) {
print.setupPDF();
}
else {
window.addEventListener( 'load', () => {
print.setupPDF();
} );
}
}
}
/**
* Removes all slides with data-visibility="hidden". This
* is done right before the rest of the presentation is
* initialized.
*
* If you want to show all hidden slides, initialize
* reveal.js with showHiddenSlides set to true.
*/
function removeHiddenSlides() {
if( !config.showHiddenSlides ) {
Util.queryAll( dom.wrapper, 'section[data-visibility="hidden"]' ).forEach( slide => {
slide.parentNode.removeChild( slide );
} );
}
}
/**
* Finds and stores references to DOM elements which are
* required by the presentation. If a required element is
* not found, it is created.
*/
function setupDOM() {
// Prevent transitions while we're loading
dom.slides.classList.add( 'no-transition' );
if( Device.isMobile ) {
dom.wrapper.classList.add( 'no-hover' );
}
else {
dom.wrapper.classList.remove( 'no-hover' );
}
backgrounds.render();
slideNumber.render();
controls.render();
progress.render();
notes.render();
// Overlay graphic which is displayed during the paused mode
dom.pauseOverlay = Util.createSingletonNode( dom.wrapper, 'div', 'pause-overlay', config.controls ? '<button class="resume-button">Resume presentation</button>' : null );
dom.statusElement = createStatusElement();
dom.wrapper.setAttribute( 'role', 'application' );
}
/**
* Creates a hidden div with role aria-live to announce the
* current slide content. Hide the div off-screen to make it
* available only to Assistive Technologies.
*
* @return {HTMLElement}
*/
function createStatusElement() {
let statusElement = dom.wrapper.querySelector( '.aria-status' );
if( !statusElement ) {
statusElement = document.createElement( 'div' );
statusElement.style.position = 'absolute';
statusElement.style.height = '1px';
statusElement.style.width = '1px';
statusElement.style.overflow = 'hidden';
statusElement.style.clip = 'rect( 1px, 1px, 1px, 1px )';
statusElement.classList.add( 'aria-status' );
statusElement.setAttribute( 'aria-live', 'polite' );
statusElement.setAttribute( 'aria-atomic','true' );
dom.wrapper.appendChild( statusElement );
}
return statusElement;
}
/**
* Announces the given text to screen readers.
*/
function announceStatus( value ) {
dom.statusElement.textContent = value;
}
/**
* Converts the given HTML element into a string of text
* that can be announced to a screen reader. Hidden
* elements are excluded.
*/
function getStatusText( node ) {
let text = '';
// Text node
if( node.nodeType === 3 ) {
text += node.textContent;
}
// Element node
else if( node.nodeType === 1 ) {
let isAriaHidden = node.getAttribute( 'aria-hidden' );
let isDisplayHidden = window.getComputedStyle( node )['display'] === 'none';
if( isAriaHidden !== 'true' && !isDisplayHidden ) {
share/revealjs/js/reveal.js view on Meta::CPAN
return event;
}
/**
* Dispatched a postMessage of the given type from our window.
*/
function dispatchPostMessage( type, data ) {
if( config.postMessageEvents && window.parent !== window.self ) {
let message = {
namespace: 'reveal',
eventName: type,
state: getState()
};
Util.extend( message, data );
window.parent.postMessage( JSON.stringify( message ), '*' );
}
}
/**
* Bind preview frame links.
*
* @param {string} [selector=a] - selector for anchors
*/
function enablePreviewLinks( selector = 'a' ) {
Array.from( dom.wrapper.querySelectorAll( selector ) ).forEach( element => {
if( /^(http|www)/gi.test( element.getAttribute( 'href' ) ) ) {
element.addEventListener( 'click', onPreviewLinkClicked, false );
}
} );
}
/**
* Unbind preview frame links.
*/
function disablePreviewLinks( selector = 'a' ) {
Array.from( dom.wrapper.querySelectorAll( selector ) ).forEach( element => {
if( /^(http|www)/gi.test( element.getAttribute( 'href' ) ) ) {
element.removeEventListener( 'click', onPreviewLinkClicked, false );
}
} );
}
/**
* Opens a preview window for the target URL.
*
* @param {string} url - url for preview iframe src
*/
function showPreview( url ) {
closeOverlay();
dom.overlay = document.createElement( 'div' );
dom.overlay.classList.add( 'overlay' );
dom.overlay.classList.add( 'overlay-preview' );
dom.wrapper.appendChild( dom.overlay );
dom.overlay.innerHTML =
`<header>
<a class="close" href="#"><span class="icon"></span></a>
<a class="external" href="${url}" target="_blank"><span class="icon"></span></a>
</header>
<div class="spinner"></div>
<div class="viewport">
<iframe src="${url}"></iframe>
<small class="viewport-inner">
<span class="x-frame-error">Unable to load iframe. This is likely due to the site's policy (x-frame-options).</span>
</small>
</div>`;
dom.overlay.querySelector( 'iframe' ).addEventListener( 'load', event => {
dom.overlay.classList.add( 'loaded' );
}, false );
dom.overlay.querySelector( '.close' ).addEventListener( 'click', event => {
closeOverlay();
event.preventDefault();
}, false );
dom.overlay.querySelector( '.external' ).addEventListener( 'click', event => {
closeOverlay();
}, false );
}
/**
* Open or close help overlay window.
*
* @param {Boolean} [override] Flag which overrides the
* toggle logic and forcibly sets the desired state. True means
* help is open, false means it's closed.
*/
function toggleHelp( override ){
if( typeof override === 'boolean' ) {
override ? showHelp() : closeOverlay();
}
else {
if( dom.overlay ) {
closeOverlay();
}
else {
showHelp();
}
}
}
/**
* Opens an overlay window with help material.
*/
function showHelp() {
if( config.help ) {
closeOverlay();
dom.overlay = document.createElement( 'div' );
dom.overlay.classList.add( 'overlay' );
dom.overlay.classList.add( 'overlay-help' );
dom.wrapper.appendChild( dom.overlay );
let html = '<p class="title">Keyboard Shortcuts</p><br/>';
let shortcuts = keyboard.getShortcuts(),
bindings = keyboard.getBindings();
html += '<table><th>KEY</th><th>ACTION</th>';
for( let key in shortcuts ) {
html += `<tr><td>${key}</td><td>${shortcuts[ key ]}</td></tr>`;
}
// Add custom key bindings that have associated descriptions
for( let binding in bindings ) {
if( bindings[binding].key && bindings[binding].description ) {
html += `<tr><td>${bindings[binding].key}</td><td>${bindings[binding].description}</td></tr>`;
}
}
html += '</table>';
dom.overlay.innerHTML = `
<header>
<a class="close" href="#"><span class="icon"></span></a>
</header>
<div class="viewport">
<div class="viewport-inner">${html}</div>
</div>
`;
dom.overlay.querySelector( '.close' ).addEventListener( 'click', event => {
closeOverlay();
event.preventDefault();
}, false );
}
}
/**
* Closes any currently open overlay.
*/
function closeOverlay() {
if( dom.overlay ) {
dom.overlay.parentNode.removeChild( dom.overlay );
dom.overlay = null;
return true;
}
return false;
}
/**
* Applies JavaScript-controlled layout rules to the
* presentation.
*/
function layout() {
if( dom.wrapper && !print.isPrintingPDF() ) {
if( !config.disableLayout ) {
// On some mobile devices '100vh' is taller than the visible
// viewport which leads to part of the presentation being
// cut off. To work around this we define our own '--vh' custom
// property where 100x adds up to the correct height.
//
// https://css-tricks.com/the-trick-to-viewport-units-on-mobile/
if( Device.isMobile && !config.embedded ) {
document.documentElement.style.setProperty( '--vh', ( window.innerHeight * 0.01 ) + 'px' );
}
const size = getComputedSlideSize();
const oldScale = scale;
// Layout the contents of the slides
layoutSlideContents( config.width, config.height );
dom.slides.style.width = size.width + 'px';
dom.slides.style.height = size.height + 'px';
// Determine scale of content to fit within available space
scale = Math.min( size.presentationWidth / size.width, size.presentationHeight / size.height );
// Respect max/min scale settings
scale = Math.max( scale, config.minScale );
scale = Math.min( scale, config.maxScale );
// Don't apply any scaling styles if scale is 1
if( scale === 1 ) {
dom.slides.style.zoom = '';
dom.slides.style.left = '';
dom.slides.style.top = '';
dom.slides.style.bottom = '';
dom.slides.style.right = '';
transformSlides( { layout: '' } );
}
else {
dom.slides.style.zoom = '';
dom.slides.style.left = '50%';
dom.slides.style.top = '50%';
dom.slides.style.bottom = 'auto';
dom.slides.style.right = 'auto';
transformSlides( { layout: 'translate(-50%, -50%) scale('+ scale +')' } );
share/revealjs/js/reveal.js view on Meta::CPAN
if( indices ) {
Reveal.slide( indices.h, indices.v, indices.f );
event.preventDefault();
}
}
}
/**
* Handler for the window level 'resize' event.
*
* @param {object} [event]
*/
function onWindowResize( event ) {
layout();
}
/**
* Handle for the window level 'visibilitychange' event.
*
* @param {object} [event]
*/
function onPageVisibilityChange( event ) {
// If, after clicking a link or similar and we're coming back,
// focus the document.body to ensure we can use keyboard shortcuts
if( document.hidden === false && document.activeElement !== document.body ) {
// Not all elements support .blur() - SVGs among them.
if( typeof document.activeElement.blur === 'function' ) {
document.activeElement.blur();
}
document.body.focus();
}
}
/**
* Handler for the document level 'fullscreenchange' event.
*
* @param {object} [event]
*/
function onFullscreenChange( event ) {
let element = document.fullscreenElement || document.webkitFullscreenElement;
if( element === dom.wrapper ) {
event.stopImmediatePropagation();
// Timeout to avoid layout shift in Safari
setTimeout( () => {
Reveal.layout();
Reveal.focus.focus(); // focus.focus :'(
}, 1 );
}
}
/**
* Handles clicks on links that are set to preview in the
* iframe overlay.
*
* @param {object} event
*/
function onPreviewLinkClicked( event ) {
if( event.currentTarget && event.currentTarget.hasAttribute( 'href' ) ) {
let url = event.currentTarget.getAttribute( 'href' );
if( url ) {
showPreview( url );
event.preventDefault();
}
}
}
/**
* Handles click on the auto-sliding controls element.
*
* @param {object} [event]
*/
function onAutoSlidePlayerClick( event ) {
// Replay
if( isLastSlide() && config.loop === false ) {
slide( 0, 0 );
resumeAutoSlide();
}
// Resume
else if( autoSlidePaused ) {
resumeAutoSlide();
}
// Pause
else {
pauseAutoSlide();
}
}
// --------------------------------------------------------------------//
// ------------------------------- API --------------------------------//
// --------------------------------------------------------------------//
// The public reveal.js API
const API = {
VERSION,
initialize,
configure,
destroy,
sync,
syncSlide,
syncFragments: fragments.sync.bind( fragments ),
// Navigation methods
slide,
left: navigateLeft,
right: navigateRight,
up: navigateUp,
down: navigateDown,
prev: navigatePrev,
next: navigateNext,
// Navigation aliases
navigateLeft, navigateRight, navigateUp, navigateDown, navigatePrev, navigateNext,
// Fragment methods
navigateFragment: fragments.goto.bind( fragments ),
prevFragment: fragments.prev.bind( fragments ),
nextFragment: fragments.next.bind( fragments ),
// Event binding
on,
off,
// Legacy event binding methods left in for backwards compatibility
addEventListener: on,
removeEventListener: off,
// Forces an update in slide layout
layout,
// Randomizes the order of slides
shuffle,
// Returns an object with the available routes as booleans (left/right/top/bottom)
availableRoutes,
// Returns an object with the available fragments as booleans (prev/next)
availableFragments: fragments.availableRoutes.bind( fragments ),
// Toggles a help overlay with keyboard shortcuts
toggleHelp,
// Toggles the overview mode on/off
toggleOverview: overview.toggle.bind( overview ),
// Toggles the "black screen" mode on/off
togglePause,
// Toggles the auto slide mode on/off
toggleAutoSlide,
// Slide navigation checks
isFirstSlide,
isLastSlide,
isLastVerticalSlide,
isVerticalSlide,
// State checks
isPaused,
isAutoSliding,
isSpeakerNotes: notes.isSpeakerNotesWindow.bind( notes ),
isOverview: overview.isActive.bind( overview ),
isFocused: focus.isFocused.bind( focus ),
isPrintingPDF: print.isPrintingPDF.bind( print ),
// Checks if reveal.js has been loaded and is ready for use
isReady: () => ready,
// Slide preloading
loadSlide: slideContent.load.bind( slideContent ),
unloadSlide: slideContent.unload.bind( slideContent ),
// Preview management
showPreview,
hidePreview: closeOverlay,
// Adds or removes all internal event listeners
addEventListeners,
removeEventListeners,
dispatchEvent,
// Facility for persisting and restoring the presentation state
getState,
setState,
// Presentation progress on range of 0-1
getProgress,
// Returns the indices of the current, or specified, slide
getIndices,
// Returns an Array of key:value maps of the attributes of each
// slide in the deck
getSlidesAttributes,
// Returns the number of slides that we have passed
getSlidePastCount,
// Returns the total number of slides
getTotalSlides,
// Returns the slide element at the specified index
getSlide,
// Returns the previous slide element, may be null
getPreviousSlide: () => previousSlide,
// Returns the current slide element
getCurrentSlide: () => currentSlide,
// Returns the slide background element at the specified index
getSlideBackground,
// Returns the speaker notes string for a slide, or null
getSlideNotes: notes.getSlideNotes.bind( notes ),
// Returns an Array of all slides
getSlides,
// Returns an array with all horizontal/vertical slides in the deck
getHorizontalSlides,
getVerticalSlides,
// Checks if the presentation contains two or more horizontal
// and vertical slides
hasHorizontalSlides,
hasVerticalSlides,
// Checks if the deck has navigated on either axis at least once
hasNavigatedHorizontally: () => navigationHistory.hasNavigatedHorizontally,
hasNavigatedVertically: () => navigationHistory.hasNavigatedVertically,
// Adds/removes a custom key binding
addKeyBinding: keyboard.addKeyBinding.bind( keyboard ),
removeKeyBinding: keyboard.removeKeyBinding.bind( keyboard ),
// Programmatically triggers a keyboard event
triggerKey: keyboard.triggerKey.bind( keyboard ),
// Registers a new shortcut to include in the help overlay
registerKeyboardShortcut: keyboard.registerKeyboardShortcut.bind( keyboard ),
getComputedSlideSize,
// Returns the current scale of the presentation content
getScale: () => scale,
// Returns the current configuration object
getConfig: () => config,
// Helper method, retrieves query string as a key:value map
getQueryHash: Util.getQueryHash,
// Returns the path to the current slide as represented in the URL
getSlidePath: location.getHash.bind( location ),
// Returns reveal.js DOM elements
getRevealElement: () => revealElement,
getSlidesElement: () => dom.slides,
getViewportElement: () => dom.viewport,
getBackgroundsElement: () => backgrounds.element,
// API for registering and retrieving plugins
registerPlugin: plugins.registerPlugin.bind( plugins ),
hasPlugin: plugins.hasPlugin.bind( plugins ),
getPlugin: plugins.getPlugin.bind( plugins ),
getPlugins: plugins.getRegisteredPlugins.bind( plugins )
};
// Our internal API which controllers have access to
Util.extend( Reveal, {
...API,
// Methods for announcing content to screen readers
announceStatus,
getStatusText,
// Controllers
print,
focus,
progress,
controls,
location,
overview,
fragments,
slideContent,
slideNumber,
onUserInput,
closeOverlay,
updateSlidesVisibility,
layoutSlideContents,
transformSlides,
cueAutoSlide,
cancelAutoSlide
} );
return API;
( run in 1.574 second using v1.01-cache-2.11-cpan-7f9471e7e0a )