2008-09-19 17:21:45 +00:00
|
|
|
/*
|
2008-09-20 13:11:01 +00:00
|
|
|
* jQuery UI Progressbar @VERSION
|
2008-09-19 17:21:45 +00:00
|
|
|
*
|
|
|
|
* Copyright (c) 2008 Eduardo Lundgren
|
|
|
|
* Dual licensed under the MIT (MIT-LICENSE.txt)
|
|
|
|
* and GPL (GPL-LICENSE.txt) licenses.
|
|
|
|
*
|
2008-09-20 13:11:01 +00:00
|
|
|
* http://docs.jquery.com/UI/Progressbar
|
2008-09-19 17:21:45 +00:00
|
|
|
*
|
|
|
|
* Depends:
|
|
|
|
* ui.core.js
|
|
|
|
*/
|
|
|
|
(function($) {
|
|
|
|
|
|
|
|
$.widget("ui.progressbar", {
|
|
|
|
_init: function() {
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-09-19 17:21:45 +00:00
|
|
|
this._interval = this.options.interval;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-09-19 17:21:45 +00:00
|
|
|
var self = this,
|
|
|
|
options = this.options,
|
2008-11-17 00:21:36 +00:00
|
|
|
identifier = 'progressbar' + (++$.ui.progressbar.uuid),
|
2008-09-19 17:21:45 +00:00
|
|
|
text = options.text || '0%';
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-10-29 16:57:04 +00:00
|
|
|
this.element
|
|
|
|
.addClass("ui-progressbar")
|
|
|
|
.width(options.width)
|
2008-11-07 13:57:31 +00:00
|
|
|
.attr({
|
|
|
|
role: "progressbar",
|
|
|
|
"aria-valuemin": 0,
|
|
|
|
"aria-valuemax": 100,
|
|
|
|
"aria-valuenow": 0
|
|
|
|
});
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-09-19 17:21:45 +00:00
|
|
|
$.extend(this, {
|
|
|
|
active: false,
|
|
|
|
pixelState: 0,
|
|
|
|
percentState: 0,
|
2008-11-17 00:21:36 +00:00
|
|
|
identifier: identifier
|
2008-09-19 17:21:45 +00:00
|
|
|
});
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-11-17 00:21:36 +00:00
|
|
|
this.wrapper = $('<div class="ui-progressbar-wrap"></div>')
|
2008-09-19 17:21:45 +00:00
|
|
|
.appendTo(this.element);
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-11-17 00:21:36 +00:00
|
|
|
this.bar = $('<div class="ui-progressbar-bar ui-hidden"></div>')
|
|
|
|
.css({
|
|
|
|
width: 0,
|
|
|
|
overflow: 'hidden',
|
|
|
|
zIndex: 100
|
|
|
|
})
|
|
|
|
.appendTo(this.wrapper);
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-11-17 00:21:36 +00:00
|
|
|
this.textElement = $('<div class="ui-progressbar-text"></div>')
|
|
|
|
.html(text)
|
|
|
|
.css({
|
|
|
|
width: 0,
|
|
|
|
overflow: 'hidden'
|
|
|
|
})
|
|
|
|
.appendTo(this.bar);
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-11-17 00:21:36 +00:00
|
|
|
this.textBg = $('<div class="ui-progressbar-text ui-progressbar-text-back"></div>')
|
|
|
|
.html(text)
|
|
|
|
.css({
|
|
|
|
width: this.element.width()
|
|
|
|
})
|
|
|
|
.appendTo(this.bar);
|
2008-09-19 17:21:45 +00:00
|
|
|
},
|
2008-09-20 11:22:54 +00:00
|
|
|
|
|
|
|
_animate: function() {
|
|
|
|
var self = this,
|
|
|
|
options = this.options,
|
|
|
|
interval = options.interval;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-09-20 11:22:54 +00:00
|
|
|
this.bar.animate(
|
|
|
|
{
|
|
|
|
width: options.width
|
|
|
|
},
|
|
|
|
{
|
|
|
|
duration: interval,
|
|
|
|
easing: options.equation || this.identifier,
|
|
|
|
step: function(step, b) {
|
|
|
|
var timestamp = new Date().getTime(), elapsedTime = (timestamp - b.startTime);
|
|
|
|
self.progress( (step/options.width) * 100 );
|
|
|
|
options.interval = interval - elapsedTime;
|
|
|
|
},
|
|
|
|
complete: function() {
|
|
|
|
if (self.active) {
|
|
|
|
options.interval = self._interval;
|
|
|
|
self.bar.width(0);
|
|
|
|
self.textElement.width(0);
|
|
|
|
self._animate();
|
|
|
|
}
|
|
|
|
else {
|
2008-11-17 01:16:34 +00:00
|
|
|
delete $.easing[self.identifier];
|
2008-09-20 11:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2008-09-19 17:21:45 +00:00
|
|
|
},
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-09-19 17:21:45 +00:00
|
|
|
destroy: function() {
|
|
|
|
this.stop();
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-09-19 17:21:45 +00:00
|
|
|
this.element
|
|
|
|
.removeClass("ui-progressbar ui-progressbar-disabled")
|
|
|
|
.removeData("progressbar").unbind(".progressbar")
|
|
|
|
.find('.ui-progressbar-wrap').remove();
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-11-17 01:16:34 +00:00
|
|
|
delete $.easing[this.identifier];
|
2008-09-19 17:21:45 +00:00
|
|
|
},
|
2008-09-20 11:22:54 +00:00
|
|
|
|
|
|
|
disable: function() {
|
|
|
|
this.element.addClass("ui-progressbar-disabled");
|
|
|
|
this.disabled = true;
|
2008-11-05 19:43:21 +00:00
|
|
|
this.element.attr("aria-disabled", true);
|
2008-09-20 11:22:54 +00:00
|
|
|
},
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-09-19 17:21:45 +00:00
|
|
|
enable: function() {
|
|
|
|
this.element.removeClass("ui-progressbar-disabled");
|
|
|
|
this.disabled = false;
|
2008-11-05 19:43:21 +00:00
|
|
|
this.element.attr("aria-disabled", false);
|
2008-09-19 17:21:45 +00:00
|
|
|
},
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-09-20 11:22:54 +00:00
|
|
|
pause: function() {
|
|
|
|
if (this.disabled) return;
|
|
|
|
this.bar.stop();
|
2008-11-17 00:21:36 +00:00
|
|
|
this._trigger('pause', null, this.ui());
|
2008-09-20 11:22:54 +00:00
|
|
|
},
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-09-20 11:22:54 +00:00
|
|
|
progress: function(percentState) {
|
2008-11-17 00:21:36 +00:00
|
|
|
this.bar.removeClass('ui-hidden');
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-09-20 11:22:54 +00:00
|
|
|
this.percentState = percentState > 100 ? 100 : percentState;
|
|
|
|
this.pixelState = (this.percentState/100) * this.options.width;
|
|
|
|
this.bar.width(this.pixelState);
|
|
|
|
this.textElement.width(this.pixelState);
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-10-29 16:57:04 +00:00
|
|
|
var percent = Math.round(this.percentState);
|
2008-09-20 11:22:54 +00:00
|
|
|
if (this.options.range && !this.options.text) {
|
2008-11-18 02:22:30 +00:00
|
|
|
this._setText(percent + '%');
|
2008-09-20 11:22:54 +00:00
|
|
|
}
|
2008-11-05 19:43:21 +00:00
|
|
|
this.element.attr("aria-valuenow", percent);
|
2008-11-17 00:21:36 +00:00
|
|
|
this._trigger('progress', null, this.ui());
|
2008-09-19 17:21:45 +00:00
|
|
|
},
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-09-19 17:21:45 +00:00
|
|
|
start: function() {
|
|
|
|
var self = this, options = this.options;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-09-19 17:21:45 +00:00
|
|
|
if (this.disabled) {
|
|
|
|
return;
|
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-11-17 01:16:34 +00:00
|
|
|
$.easing[this.identifier] = function (x, t, b, c, d) {
|
2008-09-19 17:21:45 +00:00
|
|
|
var inc = options.increment,
|
|
|
|
width = options.width,
|
|
|
|
step = ((inc > width ? width : inc)/width),
|
|
|
|
state = Math.round(x/step)*step;
|
|
|
|
return state > 1 ? 1 : state;
|
|
|
|
};
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-09-19 17:21:45 +00:00
|
|
|
self.active = true;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-09-20 04:09:27 +00:00
|
|
|
if (options.duration < options.interval) {
|
|
|
|
options.duration = options.interval;
|
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-09-19 17:21:45 +00:00
|
|
|
setTimeout(
|
|
|
|
function() {
|
|
|
|
self.active = false;
|
|
|
|
},
|
|
|
|
options.duration
|
|
|
|
);
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-09-19 17:21:45 +00:00
|
|
|
this._animate();
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-11-17 00:21:36 +00:00
|
|
|
this._trigger('start', null, this.ui());
|
2008-09-19 17:21:45 +00:00
|
|
|
return false;
|
|
|
|
},
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-09-19 17:21:45 +00:00
|
|
|
stop: function() {
|
|
|
|
this.bar.stop();
|
|
|
|
this.bar.width(0);
|
|
|
|
this.textElement.width(0);
|
|
|
|
this.bar.addClass('ui-hidden');
|
|
|
|
this.options.interval = this._interval;
|
2008-11-17 00:21:36 +00:00
|
|
|
this._trigger('stop', null, this.ui());
|
2008-09-19 17:21:45 +00:00
|
|
|
},
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-11-17 01:16:34 +00:00
|
|
|
ui: function() {
|
2008-09-20 11:22:54 +00:00
|
|
|
return {
|
|
|
|
options: this.options,
|
|
|
|
pixelState: this.pixelState,
|
|
|
|
percentState: this.percentState
|
|
|
|
};
|
2008-11-18 02:22:30 +00:00
|
|
|
},
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-11-18 02:22:30 +00:00
|
|
|
_setData: function(key, value){
|
|
|
|
switch (key) {
|
|
|
|
case 'text':
|
|
|
|
this._setText(value);
|
|
|
|
break;
|
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-11-18 02:22:30 +00:00
|
|
|
$.widget.prototype._setData.apply(this, arguments);
|
|
|
|
},
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-11-18 02:22:30 +00:00
|
|
|
_setText: function(text){
|
|
|
|
this.textElement.add(this.textBg).html(text);
|
2008-11-17 00:21:36 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$.extend($.ui.progressbar, {
|
|
|
|
version: "@VERSION",
|
|
|
|
defaults: {
|
|
|
|
width: 300,
|
|
|
|
duration: 1000,
|
|
|
|
interval: 1000,
|
|
|
|
increment: 1,
|
|
|
|
range: true,
|
2008-11-17 13:58:53 +00:00
|
|
|
text: ''
|
2008-09-20 11:22:54 +00:00
|
|
|
},
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-11-17 00:21:36 +00:00
|
|
|
uuid: 0
|
2008-09-19 17:21:45 +00:00
|
|
|
});
|
|
|
|
|
2008-09-20 01:48:18 +00:00
|
|
|
})(jQuery);
|