functional playback control for auto sliding
This commit is contained in:
1 parent
356a1cf3b7
commit
abf33e55b0
4 files changed
+107
-44
No files matched your search
+103
-41
@@ -114,9 +114,6 @@ var Reveal = (function(){
|
||||
// Flags if reveal.js is loaded (has dispatched the 'ready' event)
|
||||
loaded = false,
|
||||
|
||||
// The current auto-slide duration
|
||||
autoSlide = 0,
|
||||
|
||||
// The horizontal and vertical index of the currently active slide
|
||||
indexh,
|
||||
indexv,
|
||||
@@ -145,9 +142,6 @@ var Reveal = (function(){
|
||||
// Throttles mouse wheel navigation
|
||||
lastMouseWheelStep = 0,
|
||||
|
||||
// An interval used to automatically move on to the next slide
|
||||
autoSlideTimeout = 0,
|
||||
|
||||
// Delays updates to the URL due to a Chrome thumbnailer bug
|
||||
writeURLTimeout = 0,
|
||||
|
||||
@@ -160,8 +154,14 @@ var Reveal = (function(){
|
||||
// Flags if the interaction event listeners are bound
|
||||
eventsAreBound = false,
|
||||
|
||||
// A visual component used to control auto slide playback
|
||||
// The current auto-slide duration
|
||||
autoSlide = 0,
|
||||
|
||||
// Auto slide properties
|
||||
autoSlidePlayer,
|
||||
autoSlideTimeout = 0,
|
||||
autoSlideStartTime = -1,
|
||||
autoSlidePaused = false,
|
||||
|
||||
// Holds information about the currently ongoing touch input
|
||||
touch = {
|
||||
@@ -574,12 +574,15 @@ var Reveal = (function(){
|
||||
enablePreviewLinks( '[data-preview-link]' );
|
||||
}
|
||||
|
||||
if( config.autoSlide && config.autoSlideStoppable ) {
|
||||
// Auto-slide playback controls
|
||||
if( config.autoSlide && config.autoSlideStoppable && features.canvas && features.requestAnimationFrame ) {
|
||||
autoSlidePlayer = new Playback( dom.wrapper, function() {
|
||||
return 0.5;
|
||||
return Math.min( Math.max( ( Date.now() - autoSlideStartTime ) / autoSlide, 0 ), 1 );
|
||||
} );
|
||||
|
||||
autoSlidePlayer.setPlaying( true );
|
||||
autoSlidePlayer.on( 'click', function() {
|
||||
autoSlidePaused ? resumeAutoSlide() : pauseAutoSlide();
|
||||
} );
|
||||
}
|
||||
else if( autoSlidePlayer ) {
|
||||
autoSlidePlayer.destroy();
|
||||
@@ -1607,6 +1610,18 @@ var Reveal = (function(){
|
||||
// Update the URL hash
|
||||
writeURL();
|
||||
|
||||
// If the current slide has a data-autoslide use that,
|
||||
// otherwise use the config.autoSlide value
|
||||
var slideAutoSlide = currentSlide.getAttribute( 'data-autoslide' );
|
||||
if( slideAutoSlide ) {
|
||||
autoSlide = parseInt( slideAutoSlide, 10 );
|
||||
}
|
||||
else {
|
||||
autoSlide = config.autoSlide;
|
||||
}
|
||||
|
||||
cueAutoSlide();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1717,18 +1732,6 @@ var Reveal = (function(){
|
||||
state = state.concat( slideState.split( ' ' ) );
|
||||
}
|
||||
|
||||
// If this slide has a data-autoslide attribute associated use this as
|
||||
// autoSlide value otherwise use the global configured time
|
||||
var slideAutoSlide = slides[index].getAttribute( 'data-autoslide' );
|
||||
if( slideAutoSlide ) {
|
||||
autoSlide = parseInt( slideAutoSlide, 10 );
|
||||
}
|
||||
else {
|
||||
autoSlide = config.autoSlide;
|
||||
}
|
||||
|
||||
cueAutoSlide();
|
||||
|
||||
}
|
||||
else {
|
||||
// Since there are no slides we can't be anywhere beyond the
|
||||
@@ -2256,12 +2259,24 @@ var Reveal = (function(){
|
||||
function cueAutoSlide() {
|
||||
|
||||
clearTimeout( autoSlideTimeout );
|
||||
autoSlideTimeout = -1;
|
||||
|
||||
// Cue the next auto-slide if enabled
|
||||
if( autoSlide && !isPaused() && !isOverview() ) {
|
||||
autoSlideStartTime = Date.now();
|
||||
|
||||
// Cue the next auto-slide if:
|
||||
// - There is an autoSlide value
|
||||
// - Auto-sliding isn't paused by the user
|
||||
// - The presentation isn't paused
|
||||
// - The overview isn't active
|
||||
// - The presentation isn't over
|
||||
if( autoSlide && !autoSlidePaused && !isPaused() && !isOverview() && ( !Reveal.isLastSlide() || config.loop === true ) ) {
|
||||
autoSlideTimeout = setTimeout( navigateNext, autoSlide );
|
||||
}
|
||||
|
||||
if( autoSlidePlayer ) {
|
||||
autoSlidePlayer.setPlaying( autoSlideTimeout !== -1 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2273,6 +2288,24 @@ var Reveal = (function(){
|
||||
|
||||
}
|
||||
|
||||
function pauseAutoSlide() {
|
||||
|
||||
autoSlidePaused = true;
|
||||
clearTimeout( autoSlideTimeout );
|
||||
|
||||
if( autoSlidePlayer ) {
|
||||
autoSlidePlayer.setPlaying( false );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function resumeAutoSlide() {
|
||||
|
||||
autoSlidePaused = false;
|
||||
cueAutoSlide();
|
||||
|
||||
}
|
||||
|
||||
function navigateLeft() {
|
||||
|
||||
// Reverse for RTL
|
||||
@@ -2376,8 +2409,7 @@ var Reveal = (function(){
|
||||
function onUserInput( event ) {
|
||||
|
||||
if( config.autoSlideStoppable ) {
|
||||
config.autoSlide = 0;
|
||||
cancelAutoSlide();
|
||||
pauseAutoSlide();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2387,6 +2419,8 @@ var Reveal = (function(){
|
||||
*/
|
||||
function onDocumentKeyDown( event ) {
|
||||
|
||||
onUserInput( event );
|
||||
|
||||
// Check if there's a focused element that could be using
|
||||
// the keyboard
|
||||
var activeElement = document.activeElement;
|
||||
@@ -2488,8 +2522,6 @@ var Reveal = (function(){
|
||||
// another timeout
|
||||
cueAutoSlide();
|
||||
|
||||
onUserInput( event );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2498,6 +2530,8 @@ var Reveal = (function(){
|
||||
*/
|
||||
function onTouchStart( event ) {
|
||||
|
||||
onUserInput( event );
|
||||
|
||||
touch.startX = event.touches[0].clientX;
|
||||
touch.startY = event.touches[0].clientY;
|
||||
touch.startCount = event.touches.length;
|
||||
@@ -2514,8 +2548,6 @@ var Reveal = (function(){
|
||||
} );
|
||||
}
|
||||
|
||||
onUserInput( event );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2617,13 +2649,13 @@ var Reveal = (function(){
|
||||
*/
|
||||
function onPointerDown( event ) {
|
||||
|
||||
onUserInput( event );
|
||||
|
||||
if( event.pointerType === event.MSPOINTER_TYPE_TOUCH ) {
|
||||
event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
|
||||
onTouchStart( event );
|
||||
}
|
||||
|
||||
onUserInput( event );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2680,6 +2712,8 @@ var Reveal = (function(){
|
||||
*/
|
||||
function onProgressClicked( event ) {
|
||||
|
||||
onUserInput( event );
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
var slidesTotal = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ).length;
|
||||
@@ -2687,19 +2721,17 @@ var Reveal = (function(){
|
||||
|
||||
slide( slideIndex );
|
||||
|
||||
onUserInput( event );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Event handler for navigation control buttons.
|
||||
*/
|
||||
function onNavigateLeftClicked( event ) { event.preventDefault(); navigateLeft(); onUserInput(); }
|
||||
function onNavigateRightClicked( event ) { event.preventDefault(); navigateRight(); onUserInput(); }
|
||||
function onNavigateUpClicked( event ) { event.preventDefault(); navigateUp(); onUserInput(); }
|
||||
function onNavigateDownClicked( event ) { event.preventDefault(); navigateDown(); onUserInput(); }
|
||||
function onNavigatePrevClicked( event ) { event.preventDefault(); navigatePrev(); onUserInput(); }
|
||||
function onNavigateNextClicked( event ) { event.preventDefault(); navigateNext(); onUserInput(); }
|
||||
function onNavigateLeftClicked( event ) { event.preventDefault(); onUserInput(); navigateLeft(); }
|
||||
function onNavigateRightClicked( event ) { event.preventDefault(); onUserInput(); navigateRight(); }
|
||||
function onNavigateUpClicked( event ) { event.preventDefault(); onUserInput(); navigateUp(); }
|
||||
function onNavigateDownClicked( event ) { event.preventDefault(); onUserInput(); navigateDown(); }
|
||||
function onNavigatePrevClicked( event ) { event.preventDefault(); onUserInput(); navigatePrev(); }
|
||||
function onNavigateNextClicked( event ) { event.preventDefault(); onUserInput(); navigateNext(); }
|
||||
|
||||
/**
|
||||
* Handler for the window level 'hashchange' event.
|
||||
@@ -2845,12 +2877,14 @@ var Reveal = (function(){
|
||||
|
||||
Playback.prototype.render = function() {
|
||||
|
||||
var progress = this.playing ? this.progress : 0;
|
||||
|
||||
var radius = ( this.size / 2 ) - this.thickness,
|
||||
x = this.size / 2,
|
||||
y = this.size / 2;
|
||||
|
||||
var startAngle = - Math.PI / 2;
|
||||
var endAngle = startAngle + ( this.progress * ( Math.PI * 2 ) );
|
||||
var endAngle = startAngle + ( progress * ( Math.PI * 2 ) );
|
||||
|
||||
this.context.save();
|
||||
this.context.clearRect( 0, 0, this.size, this.size );
|
||||
@@ -2875,6 +2909,26 @@ var Reveal = (function(){
|
||||
this.context.strokeStyle = '#fff';
|
||||
this.context.stroke();
|
||||
|
||||
var iconSize = 14;
|
||||
|
||||
this.context.translate( x - ( iconSize / 2 ), y - ( iconSize / 2 ) );
|
||||
|
||||
// Draw play/pause icons
|
||||
if( this.playing ) {
|
||||
this.context.fillStyle = '#fff';
|
||||
this.context.fillRect( 0, 0, iconSize / 2 - 2, iconSize );
|
||||
this.context.fillRect( iconSize / 2 + 2, 0, iconSize / 2 - 2, iconSize );
|
||||
}
|
||||
else {
|
||||
this.context.beginPath();
|
||||
this.context.translate( 2, 0 );
|
||||
this.context.moveTo( 0, 0 );
|
||||
this.context.lineTo( iconSize - 2, iconSize / 2 );
|
||||
this.context.lineTo( 0, iconSize );
|
||||
this.context.fillStyle = '#fff';
|
||||
this.context.fill();
|
||||
}
|
||||
|
||||
this.context.restore();
|
||||
|
||||
};
|
||||
@@ -2887,6 +2941,14 @@ var Reveal = (function(){
|
||||
|
||||
};
|
||||
|
||||
Playback.prototype.on = function( type, listener ) {
|
||||
this.canvas.addEventListener( type, listener, false );
|
||||
};
|
||||
|
||||
Playback.prototype.off = function( type, listener ) {
|
||||
this.canvas.removeEventListener( type, listener, false );
|
||||
};
|
||||
|
||||
|
||||
// --------------------------------------------------------------------//
|
||||
// ------------------------------- API --------------------------------//
|
||||
|
||||
Vendored
+2
-2
@@ -1,8 +1,8 @@
|
||||
/*!
|
||||
* reveal.js 2.6.0-dev (2013-10-13, 13:08)
|
||||
* reveal.js 2.6.0-dev (2013-10-13, 14:35)
|
||||
* http://lab.hakim.se/reveal-js
|
||||
* MIT licensed
|
||||
*
|
||||
* Copyright (C) 2013 Hakim El Hattab, http://hakim.se
|
||||
*/
|
||||
var Reveal=function(){"use strict";function a(a){return b(),Zb.transforms2d||Zb.transforms3d?(window.addEventListener("load",C,!1),l(Tb,a),l(Tb,Reveal.getQueryHash()),s(),c(),void 0):(document.body.setAttribute("class","no-transforms"),void 0)}function b(){Zb.transforms3d="WebkitPerspective"in document.body.style||"MozPerspective"in document.body.style||"msPerspective"in document.body.style||"OPerspective"in document.body.style||"perspective"in document.body.style,Zb.transforms2d="WebkitTransform"in document.body.style||"MozTransform"in document.body.style||"msTransform"in document.body.style||"OTransform"in document.body.style||"transform"in document.body.style,Zb.requestAnimationFrame="function"==typeof window.requestAnimationFrame,Zb.canvas=!!document.createElement("canvas").getContext,Nb=navigator.userAgent.match(/(iphone|ipod|android)/gi)}function c(){function a(){c.length&&head.js.apply(null,c),d()}for(var b=[],c=[],e=0,f=Tb.dependencies.length;f>e;e++){var g=Tb.dependencies[e];(!g.condition||g.condition())&&(g.async?c.push(g.src):b.push(g.src),"function"==typeof g.callback&&head.ready(g.src.match(/([\w\d_\-]*)\.?js$|[^\\\/]*$/i)[0],g.callback))}b.length?(head.ready(a),head.js.apply(null,b)):a()}function d(){f(),e(),i(),ab(),setTimeout(function(){Yb.slides.classList.remove("no-transition"),Ub=!0,u("ready",{indexh:Jb,indexv:Kb,currentSlide:Mb})},1)}function e(){var a=m(document.querySelectorAll(Qb));a.forEach(function(a){var b=m(a.querySelectorAll("section"));b.forEach(function(a,b){b>0&&a.classList.add("future")})})}function f(){Yb.theme=document.querySelector("#theme"),Yb.wrapper=document.querySelector(".reveal"),Yb.slides=document.querySelector(".reveal .slides"),Yb.slides.classList.add("no-transition"),Yb.background=g(Yb.wrapper,"div","backgrounds",null),Yb.progress=g(Yb.wrapper,"div","progress","<span></span>"),Yb.progressbar=Yb.progress.querySelector("span"),g(Yb.wrapper,"aside","controls",'<div class="navigate-left"></div><div class="navigate-right"></div><div class="navigate-up"></div><div class="navigate-down"></div>'),g(Yb.wrapper,"div","state-background",null),g(Yb.wrapper,"div","pause-overlay",null),Yb.controls=document.querySelector(".reveal .controls"),Yb.controlsLeft=m(document.querySelectorAll(".navigate-left")),Yb.controlsRight=m(document.querySelectorAll(".navigate-right")),Yb.controlsUp=m(document.querySelectorAll(".navigate-up")),Yb.controlsDown=m(document.querySelectorAll(".navigate-down")),Yb.controlsPrev=m(document.querySelectorAll(".navigate-prev")),Yb.controlsNext=m(document.querySelectorAll(".navigate-next"))}function g(a,b,c,d){var e=a.querySelector("."+c);return e||(e=document.createElement(b),e.classList.add(c),null!==d&&(e.innerHTML=d),a.appendChild(e)),e}function h(){function a(a,b){var c={background:a.getAttribute("data-background"),backgroundSize:a.getAttribute("data-background-size"),backgroundImage:a.getAttribute("data-background-image"),backgroundColor:a.getAttribute("data-background-color"),backgroundRepeat:a.getAttribute("data-background-repeat"),backgroundPosition:a.getAttribute("data-background-position"),backgroundTransition:a.getAttribute("data-background-transition")},d=document.createElement("div");return d.className="slide-background",c.background&&(/^(http|file|\/\/)/gi.test(c.background)||/\.(svg|png|jpg|jpeg|gif|bmp)$/gi.test(c.background)?d.style.backgroundImage="url("+c.background+")":d.style.background=c.background),c.backgroundSize&&(d.style.backgroundSize=c.backgroundSize),c.backgroundImage&&(d.style.backgroundImage='url("'+c.backgroundImage+'")'),c.backgroundColor&&(d.style.backgroundColor=c.backgroundColor),c.backgroundRepeat&&(d.style.backgroundRepeat=c.backgroundRepeat),c.backgroundPosition&&(d.style.backgroundPosition=c.backgroundPosition),c.backgroundTransition&&d.setAttribute("data-background-transition",c.backgroundTransition),b.appendChild(d),d}r()&&document.body.classList.add("print-pdf"),Yb.background.innerHTML="",Yb.background.classList.add("no-transition"),m(document.querySelectorAll(Qb)).forEach(function(b){var c;c=r()?a(b,b):a(b,Yb.background),m(b.querySelectorAll("section")).forEach(function(b){r()?a(b,b):a(b,c)})}),Tb.parallaxBackgroundImage?(Yb.background.style.backgroundImage='url("'+Tb.parallaxBackgroundImage+'")',Yb.background.style.backgroundSize=Tb.parallaxBackgroundSize,setTimeout(function(){Yb.wrapper.classList.add("has-parallax-background")},1)):(Yb.background.style.backgroundImage="",Yb.wrapper.classList.remove("has-parallax-background"))}function i(a){if(Yb.wrapper.classList.remove(Tb.transition),"object"==typeof a&&l(Tb,a),Zb.transforms3d===!1&&(Tb.transition="linear"),Yb.wrapper.classList.add(Tb.transition),Yb.wrapper.setAttribute("data-transition-speed",Tb.transitionSpeed),Yb.wrapper.setAttribute("data-background-transition",Tb.backgroundTransition),Yb.controls.style.display=Tb.controls?"block":"none",Yb.progress.style.display=Tb.progress?"block":"none",Tb.rtl?Yb.wrapper.classList.add("rtl"):Yb.wrapper.classList.removeLine truncated
|
||||
var Reveal=function(){"use strict";function a(a){return b(),$b.transforms2d||$b.transforms3d?(window.addEventListener("load",C,!1),l(Vb,a),l(Vb,Reveal.getQueryHash()),s(),c(),void 0):(document.body.setAttribute("class","no-transforms"),void 0)}function b(){$b.transforms3d="WebkitPerspective"in document.body.style||"MozPerspective"in document.body.style||"msPerspective"in document.body.style||"OPerspective"in document.body.style||"perspective"in document.body.style,$b.transforms2d="WebkitTransform"in document.body.style||"MozTransform"in document.body.style||"msTransform"in document.body.style||"OTransform"in document.body.style||"transform"in document.body.style,$b.requestAnimationFrame="function"==typeof window.requestAnimationFrame,$b.canvas=!!document.createElement("canvas").getContext,Pb=navigator.userAgent.match(/(iphone|ipod|android)/gi)}function c(){function a(){c.length&&head.js.apply(null,c),d()}for(var b=[],c=[],e=0,f=Vb.dependencies.length;f>e;e++){var g=Vb.dependencies[e];(!g.condition||g.condition())&&(g.async?c.push(g.src):b.push(g.src),"function"==typeof g.callback&&head.ready(g.src.match(/([\w\d_\-]*)\.?js$|[^\\\/]*$/i)[0],g.callback))}b.length?(head.ready(a),head.js.apply(null,b)):a()}function d(){f(),e(),i(),ab(),setTimeout(function(){Zb.slides.classList.remove("no-transition"),Wb=!0,u("ready",{indexh:Lb,indexv:Mb,currentSlide:Ob})},1)}function e(){var a=m(document.querySelectorAll(Sb));a.forEach(function(a){var b=m(a.querySelectorAll("section"));b.forEach(function(a,b){b>0&&a.classList.add("future")})})}function f(){Zb.theme=document.querySelector("#theme"),Zb.wrapper=document.querySelector(".reveal"),Zb.slides=document.querySelector(".reveal .slides"),Zb.slides.classList.add("no-transition"),Zb.background=g(Zb.wrapper,"div","backgrounds",null),Zb.progress=g(Zb.wrapper,"div","progress","<span></span>"),Zb.progressbar=Zb.progress.querySelector("span"),g(Zb.wrapper,"aside","controls",'<div class="navigate-left"></div><div class="navigate-right"></div><div class="navigate-up"></div><div class="navigate-down"></div>'),g(Zb.wrapper,"div","state-background",null),g(Zb.wrapper,"div","pause-overlay",null),Zb.controls=document.querySelector(".reveal .controls"),Zb.controlsLeft=m(document.querySelectorAll(".navigate-left")),Zb.controlsRight=m(document.querySelectorAll(".navigate-right")),Zb.controlsUp=m(document.querySelectorAll(".navigate-up")),Zb.controlsDown=m(document.querySelectorAll(".navigate-down")),Zb.controlsPrev=m(document.querySelectorAll(".navigate-prev")),Zb.controlsNext=m(document.querySelectorAll(".navigate-next"))}function g(a,b,c,d){var e=a.querySelector("."+c);return e||(e=document.createElement(b),e.classList.add(c),null!==d&&(e.innerHTML=d),a.appendChild(e)),e}function h(){function a(a,b){var c={background:a.getAttribute("data-background"),backgroundSize:a.getAttribute("data-background-size"),backgroundImage:a.getAttribute("data-background-image"),backgroundColor:a.getAttribute("data-background-color"),backgroundRepeat:a.getAttribute("data-background-repeat"),backgroundPosition:a.getAttribute("data-background-position"),backgroundTransition:a.getAttribute("data-background-transition")},d=document.createElement("div");return d.className="slide-background",c.background&&(/^(http|file|\/\/)/gi.test(c.background)||/\.(svg|png|jpg|jpeg|gif|bmp)$/gi.test(c.background)?d.style.backgroundImage="url("+c.background+")":d.style.background=c.background),c.backgroundSize&&(d.style.backgroundSize=c.backgroundSize),c.backgroundImage&&(d.style.backgroundImage='url("'+c.backgroundImage+'")'),c.backgroundColor&&(d.style.backgroundColor=c.backgroundColor),c.backgroundRepeat&&(d.style.backgroundRepeat=c.backgroundRepeat),c.backgroundPosition&&(d.style.backgroundPosition=c.backgroundPosition),c.backgroundTransition&&d.setAttribute("data-background-transition",c.backgroundTransition),b.appendChild(d),d}r()&&document.body.classList.add("print-pdf"),Zb.background.innerHTML="",Zb.background.classList.add("no-transition"),m(document.querySelectorAll(Sb)).forEach(function(b){var c;c=r()?a(b,b):a(b,Zb.background),m(b.querySelectorAll("section")).forEach(function(b){r()?a(b,b):a(b,c)})}),Vb.parallaxBackgroundImage?(Zb.background.style.backgroundImage='url("'+Vb.parallaxBackgroundImage+'")',Zb.background.style.backgroundSize=Vb.parallaxBackgroundSize,setTimeout(function(){Zb.wrapper.classList.add("has-parallax-background")},1)):(Zb.background.style.backgroundImage="",Zb.wrapper.classList.remove("has-parallax-background"))}function i(a){if(Zb.wrapper.classList.remove(Vb.transition),"object"==typeof a&&l(Vb,a),$b.transforms3d===!1&&(Vb.transition="linear"),Zb.wrapper.classList.add(Vb.transition),Zb.wrapper.setAttribute("data-transition-speed",Vb.transitionSpeed),Zb.wrapper.setAttribute("data-background-transition",Vb.backgroundTransition),Zb.controls.style.display=Vb.controls?"block":"none",Zb.progress.style.display=Vb.progress?"block":"none",Vb.rtl?Zb.wrapper.classList.add("rtl"):Zb.wrapper.classList.removeLine truncated
|
||||
Reference in new issue
Block a user