Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added some user interaction to the demo page. #7

Merged
merged 3 commits into from Feb 17, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions index.html
Expand Up @@ -40,6 +40,19 @@ <h2>Demos</h2>
</li>
</ul>

<h2>Dynamic demo</h2>
<ul>
<li id="dynamicProgress">
<label>Progress: <span class="percentage">0</span>%
<progress value="0" max="100"></progress>
</label>
</li>
</ul>
<p>
<button id="animateFully">Animate to 100%</button>
<button id="animateToUserInput">Animate to...</button>
</p>

<h2>Features</h2>
<ul>
<li>Accessible (WAI-ARIA-enabled)</li>
Expand Down Expand Up @@ -70,5 +83,6 @@ <h2>Unit tests</h2>

<script src="progress-polyfill.js"></script>
<script src="tests.js"></script>
<script src="user-interaction.js"></script>
</body>
</html>
44 changes: 44 additions & 0 deletions user-interaction.js
@@ -0,0 +1,44 @@
/*
* Interaction demos for the <progress> polyfill
* Demonstrates setting the progress value through Javascript
* @author Espen Hovlandsdal http://rexxars.com
*/
(function(d) {
var bind = function(el, event, fn) {
if (el.addEventListener) {
el.addEventListener(event, fn, false);
} else {
el.attachEvent('on' + event, fn)
}
};

var dyn = d.getElementById('dynamicProgress'), timer, progress = 0;
var el = dyn.getElementsByTagName('progress')[0];
var perc = dyn.getElementsByClassName('percentage')[0];

var progressTo = function(to) {
clearInterval(timer);
var inc = to < el.value ? -1 : 1;

timer = setInterval(function() {
progress += inc;
el.value = progress;

perc.innerHTML = progress;

if (progress == to) {
return clearInterval(timer);
}
}, 25);
};

bind(d.getElementById('animateFully'), 'click', function() {
progressTo(100);
});

bind(d.getElementById('animateToUserInput'), 'click', function() {
var to = parseInt(prompt('How many percent?', 50), 10);
progressTo(Math.max(0, Math.min(100, to)));
});

})(document);