added support for looped presentations
authorHakim El Hattab <hakim.elhattab@gmail.com>
Sat, 28 Apr 2012 16:16:56 +0000 (12:16 -0400)
committerHakim El Hattab <hakim.elhattab@gmail.com>
Sat, 28 Apr 2012 16:16:56 +0000 (12:16 -0400)
README.md
index.html
js/reveal.js
js/reveal.min.js

index d3c222860488d99c0e6e4accf2f3cef398808361..b1e73551b1fb13eed91ddb6736c2d3aa4ce3e5ee 100644 (file)
--- a/README.md
+++ b/README.md
@@ -58,6 +58,9 @@ Reveal.initialize({
        // If true; each slide will be pushed to the browser history
        history: true,
 
+       // Loops the presentation, defaults to false
+       loop: false,
+
        // Flags if mouse wheel navigation should be enabled
        mouseWheel: true,
 
@@ -98,6 +101,7 @@ document.addEventListener( 'someState', function() {
 
 #### 1.3 (master)
 - 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
 
index 69d598f3df52f78ea7f351a6398380f1e67d7b3c..5346e34915f825c69a1d8486790bb839f653f570 100644 (file)
                                // If true; each slide will be pushed to the browser history
                                history: true,
 
+                               // Loops the presentation, defaults to false
+                               loop: false,
+
                                // Flags if mouse wheel navigation should be enabled
                                mouseWheel: true,
 
index 237386dc3f7705e7d5ffac86078ccf76de3912c8..3360255a440377d7b1ba948f7dcaf685314f3977 100644 (file)
@@ -19,10 +19,11 @@ var Reveal = (function(){
                        controls: false,
                        progress: false,
                        history: false,
-                       transition: 'default',
-                       theme: 'default',
+                       loop: false,
                        mouseWheel: true,
-                       rollingLinks: true
+                       rollingLinks: true,
+                       transition: 'default',
+                       theme: 'default'
                },
 
                // 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
                // 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 ) {
-                       // Enforce max and minimum index bounds
-                       index = Math.max(Math.min(index, slides.length - 1), 0);
+               if( slidesLength ) {
 
-                       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];
 
                                // Optimization; hide all slides that are three or more steps 
                                // away from the present slide
                                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' );
index 749bdcdc7c0f48ac245219dca75eb81504842b44..2bbb956f8eaea0cbfc3619064c4fc5475605dd7d 100644 (file)
@@ -5,7 +5,7 @@
  * 
  * 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");
 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");
@@ -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");
 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");
-}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));
-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";
+}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(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");
 }}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);