2011-09-01 09:35:45 +00:00
|
|
|
Ox.Progressbar = function(options, self) {
|
|
|
|
|
|
|
|
self = self || {};
|
|
|
|
var that = Ox.Element({}, self)
|
|
|
|
.defaults({
|
|
|
|
progress: 0,
|
|
|
|
width: 256
|
|
|
|
})
|
|
|
|
.options(options || {})
|
|
|
|
.addClass('OxProgressbar')
|
2011-09-01 21:38:57 +00:00
|
|
|
.css({width: self.options.width - 2 + 'px'});
|
2011-09-01 09:35:45 +00:00
|
|
|
|
|
|
|
self.$progress = $('<div>').appendTo(that);
|
|
|
|
|
2011-09-01 21:38:57 +00:00
|
|
|
//setProgress();
|
2011-09-01 09:35:45 +00:00
|
|
|
|
|
|
|
function setProgress() {
|
2011-09-01 21:38:57 +00:00
|
|
|
self.$progress.stop().animate({
|
|
|
|
width: Math.round(14 + self.options.progress * (self.options.width - 16)) + 'px'
|
|
|
|
}, 250);
|
|
|
|
if (self.options.progress == 1) {
|
|
|
|
self.$progress.removeClass('OxAnimate');
|
|
|
|
$.browser.mozilla && clearInterval(self.interval);
|
|
|
|
}
|
2011-09-01 09:35:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self.setOption = function(key, value) {
|
|
|
|
if (key == 'progress') {
|
2011-09-01 21:38:57 +00:00
|
|
|
self.options.progress = Ox.limit(self.options.progress, 0, 1);
|
2011-09-01 09:35:45 +00:00
|
|
|
setProgress();
|
|
|
|
}
|
2011-09-01 21:38:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
that.start = function() {
|
|
|
|
self.startTime = +new Date();
|
|
|
|
self.$progress.addClass('OxAnimate');
|
|
|
|
if ($.browser.mozilla) {
|
|
|
|
self.offset = 0;
|
|
|
|
self.interval = setInterval(function() {
|
|
|
|
self.$progress.css({backgroundPosition: --self.offset + 'px 0, 0 0'})
|
|
|
|
}, 1000 / 32);
|
|
|
|
}
|
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
|
|
|
that.status = function() {
|
|
|
|
var elapsed = +new Date() - self.startTime;
|
|
|
|
return {
|
|
|
|
elapsed: Ox.formatDuration(Math.floor(
|
|
|
|
elapsed / 1000
|
|
|
|
), 'long'),
|
|
|
|
percent: Math.round(self.options.progress * 100) + '%',
|
|
|
|
remaining: progress ? Ox.formatDuration(Math.ceil(
|
|
|
|
elapsed / progress * (1 - progress) / 1000
|
|
|
|
), 'long') : 'unknown'
|
|
|
|
};
|
|
|
|
};
|
2011-09-01 09:35:45 +00:00
|
|
|
|
|
|
|
return that;
|
|
|
|
|
|
|
|
};
|