Skip to content

Commit

Permalink
Added optional progress bar - fixes jdan#16
Browse files Browse the repository at this point in the history
  • Loading branch information
Ignat Zakrevsky authored and jdan committed Sep 23, 2013
1 parent 73aab54 commit 7bb714c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ the following fields.
* **controls**: Option whether or not arrow buttons should be included (default: *true*)
* **agenda**: Option whether or not to insert an agenda slide (similar to a table of contents) after the title (default: *false*)
* **encoding**: A specified content encoding (default: *utf-8*)
* **progress*: Option whether or not to display a small progress bar at the top of the page
(default: *true*)

**Power Users**

Expand Down
2 changes: 2 additions & 0 deletions lib/cleaver.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,13 @@ Cleaver.prototype._loadAssets = function () {
*/
Cleaver.prototype._renderSlideshow = function () {
var putControls = this.metadata.controls || (this.metadata.controls === undefined);
var putProgress = this.metadata.progress || (this.metadata.progress === undefined);

// Render the slides in a template (maybe as specified by the user)
var slideshow = mustache.render(this.templates.loaded.slides, {
slides: this.slides,
controls: putControls,
progress: putProgress,
// TODO: uglify navigation.js?
navigation: this.resources.loaded.navigation
});
Expand Down
12 changes: 12 additions & 0 deletions resources/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,15 @@ pre > code {
display: none;
}

.progress {
position: fixed;
top: 0; left: 0; right: 0;
height: 5px;
background-color: #bbb;
}

.progress-bar {
width: 0%;
height: 5px;
background-color: #eee;
}
17 changes: 17 additions & 0 deletions resources/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function goBack() {
wrapper.removeChild(lastSlide);
wrapper.insertBefore(lastSlide, wrapper.firstChild);

setCurrentProgress();
updateURL();
}

Expand All @@ -27,6 +28,7 @@ function goForward() {
wrapper.removeChild(firstSlide);
wrapper.appendChild(firstSlide);

setCurrentProgress();
updateURL();
}

Expand Down Expand Up @@ -65,6 +67,21 @@ function setPageNumbers() {
}
}

/**
* Set the current progress indicator.
*/
function setCurrentProgress() {
var wrapper = document.querySelector('#wrapper');
var progressBar = document.querySelector('.progress-bar');

if (progressBar !== null) {
var pagesNumber = wrapper.querySelectorAll('section').length;
var currentNumber = parseInt(currentPage());
var currentPercent = pagesNumber === 1 ? 100 : 100 * currentNumber / (pagesNumber - 1);
progressBar.style.width = currentPercent.toString() + '%';
}
}

/**
* Go to the specified page of content.
*/
Expand Down
6 changes: 6 additions & 0 deletions templates/default.mustache
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{{#progress}}
<div class="progress">
<div class="progress-bar"></div>
</div>
{{/progress}}

<div id="wrapper">
{{#slides}}
<section class="slide">{{{.}}}</section>
Expand Down

0 comments on commit 7bb714c

Please sign in to comment.