added support for looped presentations

This commit is contained in:
Hakim El Hattab 2012-04-28 12:16:56 -04:00
parent eee6e5f964
commit cde5362db3
4 changed files with 35 additions and 12 deletions

View File

@ -58,6 +58,9 @@ Reveal.initialize({
// If true; each slide will be pushed to the browser history // If true; each slide will be pushed to the browser history
history: true, history: true,
// Loops the presentation, defaults to false
loop: false,
// Flags if mouse wheel navigation should be enabled // Flags if mouse wheel navigation should be enabled
mouseWheel: true, mouseWheel: true,
@ -98,6 +101,7 @@ document.addEventListener( 'someState', function() {
#### 1.3 (master) #### 1.3 (master)
- Revised keyboard shortcuts, including ESC for overview, N for next, P for previous. Thanks [mahemoff](https://github.com/mahemoff) - Revised keyboard shortcuts, including ESC for overview, N for next, P for previous. Thanks [mahemoff](https://github.com/mahemoff)
- Added support for looped presentations via config
#### 1.2 #### 1.2

View File

@ -260,6 +260,9 @@
// If true; each slide will be pushed to the browser history // If true; each slide will be pushed to the browser history
history: true, history: true,
// Loops the presentation, defaults to false
loop: false,
// Flags if mouse wheel navigation should be enabled // Flags if mouse wheel navigation should be enabled
mouseWheel: true, mouseWheel: true,

View File

@ -19,10 +19,11 @@ var Reveal = (function(){
controls: false, controls: false,
progress: false, progress: false,
history: false, history: false,
transition: 'default', loop: false,
theme: 'default',
mouseWheel: true, mouseWheel: true,
rollingLinks: true rollingLinks: true,
transition: 'default',
theme: 'default'
}, },
// Slides may hold a data-state attribute which we pick up and apply // Slides may hold a data-state attribute which we pick up and apply
@ -406,19 +407,34 @@ var Reveal = (function(){
// Select all slides and convert the NodeList result to // Select all slides and convert the NodeList result to
// an array // an array
var slides = Array.prototype.slice.call( document.querySelectorAll( selector ) ); var slides = Array.prototype.slice.call( document.querySelectorAll( selector ) ),
slidesLength = slides.length;
if( slides.length ) { if( slidesLength ) {
// Enforce max and minimum index bounds
index = Math.max(Math.min(index, slides.length - 1), 0);
for( var i = 0; i < slides.length; i++ ) { // Should the index loop?
if( config.loop ) {
index %= slidesLength;
if( index < 0 ) {
index = slidesLength + index;
}
}
// Enforce max and minimum index bounds
index = Math.max( Math.min( index, slidesLength - 1 ), 0 );
for( var i = 0; i < slidesLength; i++ ) {
var slide = slides[i]; var slide = slides[i];
// Optimization; hide all slides that are three or more steps // Optimization; hide all slides that are three or more steps
// away from the present slide // away from the present slide
if( overviewIsActive() === false ) { if( overviewIsActive() === false ) {
slide.style.display = Math.abs( index - i ) > 3 ? 'none' : 'block'; // The distance loops so that it measures 1 between the first
// and last slides
var distance = Math.abs( ( index - i ) % ( slidesLength - 3 ) ) || 0;
slide.style.display = distance > 3 ? 'none' : 'block';
} }
slides[i].classList.remove( 'past' ); slides[i].classList.remove( 'past' );

6
js/reveal.min.js vendored
View File

@ -5,7 +5,7 @@
* *
* Copyright (C) 2012 Hakim El Hattab, http://hakim.se * Copyright (C) 2012 Hakim El Hattab, http://hakim.se
*/ */
var Reveal=(function(){var i="#reveal .slides>section",a="#reveal .slides>section.present>section",j=0,c=0,E={controls:false,progress:false,history:false,transition:"default",theme:"default",mouseWheel:true,rollingLinks:true},K=[],d={},F=document.body.style.perspectiveProperty!==undefined||document.body.style.WebkitPerspective!==undefined||document.body.style.MozPerspective!==undefined||document.body.style.msPerspective!==undefined||document.body.style.OPerspective!==undefined,k=document.body.style.transformProperty!==undefined||document.body.style.WebkitTransform!==undefined||document.body.style.MozTransform!==undefined||document.body.style.msTransform!==undefined||document.body.style.OTransform!==undefined,t=0,w=0; var Reveal=(function(){var i="#reveal .slides>section",a="#reveal .slides>section.present>section",j=0,c=0,E={controls:false,progress:false,history:false,loop:false,mouseWheel:true,rollingLinks:true,transition:"default",theme:"default"},K=[],d={},F=document.body.style.perspectiveProperty!==undefined||document.body.style.WebkitPerspective!==undefined||document.body.style.MozPerspective!==undefined||document.body.style.msPerspective!==undefined||document.body.style.OPerspective!==undefined,k=document.body.style.transformProperty!==undefined||document.body.style.WebkitTransform!==undefined||document.body.style.MozTransform!==undefined||document.body.style.msTransform!==undefined||document.body.style.OTransform!==undefined,t=0,w=0;
function g(M){if(!k&&!F){document.body.setAttribute("class","no-transforms");return;}d.wrapper=document.querySelector("#reveal");d.progress=document.querySelector("#reveal .progress"); function g(M){if(!k&&!F){document.body.setAttribute("class","no-transforms");return;}d.wrapper=document.querySelector("#reveal");d.progress=document.querySelector("#reveal .progress");
d.progressbar=document.querySelector("#reveal .progress span");d.controls=document.querySelector("#reveal .controls");d.controlsLeft=document.querySelector("#reveal .controls .left"); d.progressbar=document.querySelector("#reveal .progress span");d.controls=document.querySelector("#reveal .controls");d.controlsLeft=document.querySelector("#reveal .controls .left");
d.controlsRight=document.querySelector("#reveal .controls .right");d.controlsUp=document.querySelector("#reveal .controls .up");d.controlsDown=document.querySelector("#reveal .controls .down"); d.controlsRight=document.querySelector("#reveal .controls .right");d.controlsUp=document.querySelector("#reveal .controls .up");d.controlsDown=document.querySelector("#reveal .controls .down");
@ -28,8 +28,8 @@ Q<N;Q++){var T=U[Q],S="translate(0%, "+((Q-c)*105)+"%)";T.setAttribute("data-ind
T.style.MozTransform=S;T.style.msTransform=S;T.style.OTransform=S;T.style.transform=S;T.addEventListener("click",x,true);}}}function I(){d.wrapper.classList.remove("overview"); T.style.MozTransform=S;T.style.msTransform=S;T.style.OTransform=S;T.style.transform=S;T.addEventListener("click",x,true);}}}function I(){d.wrapper.classList.remove("overview");
var P=Array.prototype.slice.call(document.querySelectorAll("#reveal .slides section"));for(var O=0,M=P.length;O<M;O++){var N=P[O];N.style.WebkitTransform=""; var P=Array.prototype.slice.call(document.querySelectorAll("#reveal .slides section"));for(var O=0,M=P.length;O<M;O++){var N=P[O];N.style.WebkitTransform="";
N.style.MozTransform="";N.style.msTransform="";N.style.OTransform="";N.style.transform="";N.removeEventListener("click",x);}b();}function H(){return d.wrapper.classList.contains("overview"); N.style.MozTransform="";N.style.msTransform="";N.style.OTransform="";N.style.transform="";N.removeEventListener("click",x);}b();}function H(){return d.wrapper.classList.contains("overview");
}function x(M){if(H()){M.preventDefault();I();j=this.getAttribute("data-index-h");c=this.getAttribute("data-index-v");b();}}function L(N,P){var R=Array.prototype.slice.call(document.querySelectorAll(N)); }function x(M){if(H()){M.preventDefault();I();j=this.getAttribute("data-index-h");c=this.getAttribute("data-index-v");b();}}function L(N,P){var R=Array.prototype.slice.call(document.querySelectorAll(N)),S=R.length;
if(R.length){P=Math.max(Math.min(P,R.length-1),0);for(var Q=0;Q<R.length;Q++){var M=R[Q];if(H()===false){M.style.display=Math.abs(P-Q)>3?"none":"block"; if(S){if(E.loop){P%=S;if(P<0){P=S+P;}}P=Math.max(Math.min(P,S-1),0);for(var Q=0;Q<S;Q++){var M=R[Q];if(H()===false){var T=Math.abs((P-Q)%(S-3))||0;M.style.display=T>3?"none":"block";
}R[Q].classList.remove("past");R[Q].classList.remove("present");R[Q].classList.remove("future");if(Q<P){R[Q].classList.add("past");}else{if(Q>P){R[Q].classList.add("future"); }R[Q].classList.remove("past");R[Q].classList.remove("present");R[Q].classList.remove("future");if(Q<P){R[Q].classList.add("past");}else{if(Q>P){R[Q].classList.add("future");
}}if(M.querySelector("section")){R[Q].classList.add("stack");}}R[P].classList.add("present");var O=R[P].dataset.state;if(O){K=K.concat(O.split(" "));}}else{P=0; }}if(M.querySelector("section")){R[Q].classList.add("stack");}}R[P].classList.add("present");var O=R[P].dataset.state;if(O){K=K.concat(O.split(" "));}}else{P=0;
}return P;}function b(){var Q=K.concat();K.length=0;j=L(i,j);c=L(a,c);stateLoop:for(var O=0,M=K.length;O<M;O++){for(var N=0;N<Q.length;N++){if(Q[N]===K[O]){Q.splice(N,1); }return P;}function b(){var Q=K.concat();K.length=0;j=L(i,j);c=L(a,c);stateLoop:for(var O=0,M=K.length;O<M;O++){for(var N=0;N<Q.length;N++){if(Q[N]===K[O]){Q.splice(N,1);