Skip to content

Commit b0ee199

Browse files
m42ehenrikingo
authored andcommitted
Add progress bar plugin by Matthias Bilger (@m42e).
Originally from https://github.com/m42e/impress.js-progress and adapted for the new plugin api. Also made the sample CSS produce a smaller bar and font. Adds event.detail.next to impress:stepleave event in impress.js.
1 parent f6ec70c commit b0ee199

2 files changed

Lines changed: 104 additions & 0 deletions

File tree

‎src/plugins/progress/README.md‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Progress plugin
2+
===============
3+
4+
Progressbar and pagexounter for impress.js presentations
5+
6+
Usage
7+
-----
8+
9+
Add a div for progressbar and/or progress as you can see it here:
10+
11+
### HTML
12+
13+
<div class="impress-progressbar"><div></div></div>
14+
<div class="impress-progress"></div>
15+
16+
### Sample CSS
17+
18+
.impress-progressbar {
19+
position: absolute;
20+
right: 318px;
21+
bottom: 1px;
22+
left: 118px;
23+
border-radius: 7px;
24+
border: 2px solid rgba(100, 100, 100, 0.2);
25+
}
26+
.impress-progressbar DIV {
27+
width: 0;
28+
height: 2px;
29+
border-radius: 5px;
30+
background: rgba(75, 75, 75, 0.4);
31+
transition: width 1s linear;
32+
}
33+
.impress-progress {
34+
position: absolute;
35+
left: 59px;
36+
bottom: 1px;
37+
text-align: left;
38+
opacity: 0.6;
39+
}
40+
41+
Feel free to change the style of your progressbar as you like by editing the CSS file.
42+
43+
Author
44+
------
45+
46+
Copyright 2014: Matthias Bilger (@m42e)

‎src/plugins/progress/progress.js‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* global document */
2+
( function( document ) {
3+
"use strict";
4+
var root;
5+
var stepids = [];
6+
7+
// Get stepids from the steps under impress root
8+
var getSteps = function() {
9+
stepids = [];
10+
var steps = root.querySelectorAll( ".step" );
11+
for ( var i = 0; i < steps.length; i++ )
12+
{
13+
stepids[ i + 1 ] = steps[ i ].id;
14+
}
15+
};
16+
17+
// Wait for impress.js to be initialized
18+
document.addEventListener( "impress:init", function( event ) {
19+
root = event.target;
20+
getSteps();
21+
var gc = event.detail.api.lib.gc;
22+
gc.addCallback( function() {
23+
stepids = [];
24+
if ( progressbar ) {
25+
progressbar.style.width = "";
26+
}
27+
if ( progress ) {
28+
progress.innerHTML = "";
29+
}
30+
} );
31+
} );
32+
33+
var progressbar = document.querySelector( "div.impress-progressbar div" );
34+
var progress = document.querySelector( "div.impress-progress" );
35+
36+
if ( null !== progressbar || null !== progress ) {
37+
document.addEventListener( "impress:stepleave", function( event ) {
38+
updateProgressbar( event.detail.next.id );
39+
} );
40+
41+
document.addEventListener( "impress:steprefresh", function( event ) {
42+
getSteps();
43+
updateProgressbar( event.target.id );
44+
} );
45+
46+
}
47+
48+
function updateProgressbar( slideId ) {
49+
var slideNumber = stepids.indexOf( slideId );
50+
if ( null !== progressbar ) {
51+
var width = 100 / ( stepids.length - 1 ) * ( slideNumber );
52+
progressbar.style.width = width.toFixed( 2 ) + "%";
53+
}
54+
if ( null !== progress ) {
55+
progress.innerHTML = slideNumber + "/" + ( stepids.length - 1 );
56+
}
57+
}
58+
} )( document );

0 commit comments

Comments
 (0)