oxjs/demos/progress/js/progress.js

57 lines
1.9 KiB
JavaScript
Raw Normal View History

2011-09-01 13:13:47 +00:00
Ox.load('UI', {debug: true}, function() {
2011-09-01 21:38:57 +00:00
2011-09-01 13:13:47 +00:00
var paused = false,
width = 384,
$progressbar = Ox.Progressbar({
showCancelButton: true,
showPauseButton: true,
showPercent: true,
showTime: true,
width: width
})
2011-09-01 21:38:57 +00:00
.css({margin: '16px'})
.appendTo(Ox.UI.$body)
2011-09-01 13:13:47 +00:00
.bindEvent({
pause: function() {
paused = true;
},
resume: function() {
paused = false;
},
cancel: function() {
clearInterval(interval);
}
}),
2011-09-01 21:38:57 +00:00
$status = Ox.Label({
2011-09-01 13:13:47 +00:00
width: width
2011-09-01 21:38:57 +00:00
})
.css({marginLeft: '16px'})
.appendTo(Ox.UI.$body);
$percent = $('<div>')
2011-09-01 13:13:47 +00:00
.css({float: 'left', width: '64px', fontWeight: 'bold'})
2011-09-01 21:38:57 +00:00
.appendTo($status);
$remaining = $('<div>')
2011-09-01 13:13:47 +00:00
.css({float: 'left', width: width - 64 - 16 + 'px', textAlign: 'right'})
2011-09-01 21:38:57 +00:00
.appendTo($status);
progress = 0,
i = 0,
interval = setInterval(function() {
2011-09-01 13:13:47 +00:00
if (!paused) {
if (Math.random() < 0.25) {
progress += 0.01;
$progressbar.options({progress: progress});
}
if (i % 10 == 0 || progress >= 1) {
var status = $progressbar.status();
$percent.html(Math.round(progress * 100) + '%');
$remaining.html('Remaining: ' + status.remaining == Infinity
? 'unknown' : Ox.formatDuration(status.remaining, 'long'));
}
if (progress >= 1) {
clearInterval(interval);
}
i++;
2011-09-01 21:38:57 +00:00
}
}, 25);
});