2008-07-09 11:09:40 +00:00
|
|
|
/*
|
|
|
|
* jQuery UI ProgressBar
|
|
|
|
*
|
2008-08-09 23:06:18 +00:00
|
|
|
* Copyright (c) 2008 Eduardo Lundgren
|
2008-07-09 11:09:40 +00:00
|
|
|
* Dual licensed under the MIT (MIT-LICENSE.txt)
|
|
|
|
* and GPL (GPL-LICENSE.txt) licenses.
|
2008-08-08 05:56:57 +00:00
|
|
|
*
|
2008-07-09 11:09:40 +00:00
|
|
|
* http://docs.jquery.com/UI/ProgressBar
|
|
|
|
*
|
|
|
|
* Depends:
|
2008-07-10 02:50:51 +00:00
|
|
|
* ui.core.js
|
2008-07-09 11:09:40 +00:00
|
|
|
*/
|
2008-07-10 02:50:51 +00:00
|
|
|
(function($) {
|
2008-07-09 11:09:40 +00:00
|
|
|
|
2008-07-10 02:50:51 +00:00
|
|
|
$.widget("ui.progressbar", {
|
2008-08-16 14:45:28 +00:00
|
|
|
_init: function() {
|
2008-07-09 11:09:40 +00:00
|
|
|
|
2008-08-09 23:06:18 +00:00
|
|
|
$.extend(this.options, {
|
|
|
|
_interval: this.options.interval
|
2008-07-10 02:50:51 +00:00
|
|
|
});
|
2008-08-08 05:56:57 +00:00
|
|
|
|
2008-08-09 23:06:18 +00:00
|
|
|
var self = this,
|
|
|
|
options = this.options,
|
|
|
|
id = (new Date()).getTime()+Math.random(),
|
|
|
|
text = options.text || '0%';
|
2008-08-08 05:56:57 +00:00
|
|
|
|
2008-08-09 23:06:18 +00:00
|
|
|
this.element.addClass("ui-progressbar").width(options.width);
|
|
|
|
|
|
|
|
$.extend(this, {
|
|
|
|
active: false,
|
|
|
|
pixelState: 0,
|
|
|
|
percentState: 0,
|
|
|
|
identifier: id,
|
2008-08-07 20:17:02 +00:00
|
|
|
bar: $('<div class="ui-progressbar-bar ui-hidden"></div>').css({
|
2008-07-10 02:50:51 +00:00
|
|
|
width: '0px', overflow: 'hidden', zIndex: 100
|
|
|
|
}),
|
2008-08-07 20:17:02 +00:00
|
|
|
textElement: $('<div class="ui-progressbar-text"></div>').html(text).css({
|
2008-07-10 02:50:51 +00:00
|
|
|
width: '0px', overflow: 'hidden'
|
|
|
|
}),
|
2008-08-07 20:17:02 +00:00
|
|
|
textBg: $('<div class="ui-progressbar-text ui-progressbar-text-back"></div>').html(text).css({
|
2008-08-09 23:06:18 +00:00
|
|
|
width: this.element.width()
|
|
|
|
}),
|
|
|
|
wrapper: $('<div class="ui-progressbar-wrap"></div>')
|
2008-07-10 02:50:51 +00:00
|
|
|
});
|
2008-08-08 05:56:57 +00:00
|
|
|
|
2008-07-10 02:50:51 +00:00
|
|
|
this.wrapper
|
2008-08-09 23:06:18 +00:00
|
|
|
.append(this.bar.append(this.textElement.addClass(options.textClass)), this.textBg)
|
2008-07-10 02:50:51 +00:00
|
|
|
.appendTo(this.element);
|
2008-07-09 11:09:40 +00:00
|
|
|
|
2008-08-09 23:51:46 +00:00
|
|
|
jQuery.easing[this.identifier] = function (x, t, b, c, d) {
|
|
|
|
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-07-10 02:50:51 +00:00
|
|
|
},
|
2008-08-08 05:56:57 +00:00
|
|
|
|
2008-07-10 02:50:51 +00:00
|
|
|
plugins: {},
|
|
|
|
ui: function(e) {
|
|
|
|
return {
|
|
|
|
instance: this,
|
2008-08-09 23:06:18 +00:00
|
|
|
identifier: this.identifier,
|
2008-07-10 02:50:51 +00:00
|
|
|
options: this.options,
|
2008-08-09 23:06:18 +00:00
|
|
|
element: this.bar,
|
|
|
|
textElement: this.textElement,
|
|
|
|
pixelState: this.pixelState,
|
|
|
|
percentState: this.percentState
|
2008-07-10 02:50:51 +00:00
|
|
|
};
|
|
|
|
},
|
2008-08-16 06:00:46 +00:00
|
|
|
_propagate: function(n,e) {
|
2008-07-10 02:50:51 +00:00
|
|
|
$.ui.plugin.call(this, n, [e, this.ui()]);
|
|
|
|
this.element.triggerHandler(n == "progressbar" ? n : ["progressbar", n].join(""), [e, this.ui()], this.options[n]);
|
|
|
|
},
|
|
|
|
destroy: function() {
|
2008-08-09 23:51:46 +00:00
|
|
|
this.stop();
|
2008-08-08 05:56:57 +00:00
|
|
|
|
2008-07-10 02:50:51 +00:00
|
|
|
this.element
|
|
|
|
.removeClass("ui-progressbar ui-progressbar-disabled")
|
|
|
|
.removeData("progressbar").unbind(".progressbar")
|
|
|
|
.find('.ui-progressbar-wrap').remove();
|
2008-08-09 23:06:18 +00:00
|
|
|
|
|
|
|
delete jQuery.easing[this.identifier];
|
2008-07-10 02:50:51 +00:00
|
|
|
},
|
|
|
|
enable: function() {
|
|
|
|
this.element.removeClass("ui-progressbar-disabled");
|
|
|
|
this.disabled = false;
|
|
|
|
},
|
|
|
|
disable: function() {
|
|
|
|
this.element.addClass("ui-progressbar-disabled");
|
|
|
|
this.disabled = true;
|
|
|
|
},
|
|
|
|
start: function() {
|
2008-08-09 23:06:18 +00:00
|
|
|
var self = this, options = this.options;
|
2008-08-08 05:56:57 +00:00
|
|
|
|
2008-08-09 23:51:46 +00:00
|
|
|
if (this.disabled) {
|
|
|
|
return;
|
2008-08-23 02:38:28 +00:00
|
|
|
}
|
2008-08-09 23:51:46 +00:00
|
|
|
|
|
|
|
self.active = true;
|
|
|
|
|
|
|
|
setTimeout(
|
|
|
|
function() {
|
|
|
|
self.active = false;
|
|
|
|
},
|
|
|
|
options.duration
|
|
|
|
);
|
|
|
|
|
2008-08-16 06:00:46 +00:00
|
|
|
this._animate();
|
2008-08-09 23:51:46 +00:00
|
|
|
|
2008-08-16 06:00:46 +00:00
|
|
|
this._propagate('start', this.ui());
|
2008-08-09 23:51:46 +00:00
|
|
|
return false;
|
|
|
|
},
|
2008-08-16 06:00:46 +00:00
|
|
|
_animate: function() {
|
2008-08-09 23:51:46 +00:00
|
|
|
var self = this,
|
|
|
|
options = this.options,
|
|
|
|
interval = options.interval;
|
2008-07-09 11:09:40 +00:00
|
|
|
|
2008-08-09 23:06:18 +00:00
|
|
|
this.bar.animate(
|
|
|
|
{
|
|
|
|
width: options.width
|
|
|
|
},
|
|
|
|
{
|
2008-08-09 23:51:46 +00:00
|
|
|
duration: interval,
|
2008-08-09 23:06:18 +00:00
|
|
|
easing: this.identifier,
|
|
|
|
step: function(step, b) {
|
|
|
|
self.progress((step/options.width)*100);
|
2008-08-09 23:51:46 +00:00
|
|
|
var elapsedTime = ((new Date().getTime()) - b.startTime);
|
|
|
|
options.interval = interval - elapsedTime;
|
2008-08-09 23:06:18 +00:00
|
|
|
},
|
|
|
|
complete: function() {
|
|
|
|
delete jQuery.easing[self.identifier];
|
2008-08-09 23:51:46 +00:00
|
|
|
self.pause();
|
|
|
|
|
|
|
|
if (self.active) {
|
|
|
|
/*TODO*/
|
|
|
|
self.stop();
|
2008-08-16 06:00:46 +00:00
|
|
|
self._animate();
|
2008-08-09 23:51:46 +00:00
|
|
|
}
|
2008-07-09 11:09:40 +00:00
|
|
|
}
|
2008-07-10 02:50:51 +00:00
|
|
|
}
|
2008-08-09 23:06:18 +00:00
|
|
|
);
|
2008-07-10 02:50:51 +00:00
|
|
|
},
|
2008-08-09 23:51:46 +00:00
|
|
|
pause: function() {
|
2008-08-09 23:06:18 +00:00
|
|
|
if (this.disabled) return;
|
|
|
|
this.bar.stop();
|
2008-08-16 06:00:46 +00:00
|
|
|
this._propagate('pause', this.ui());
|
2008-07-10 02:50:51 +00:00
|
|
|
},
|
2008-08-09 23:51:46 +00:00
|
|
|
stop: function() {
|
2008-08-09 23:06:18 +00:00
|
|
|
this.bar.stop();
|
|
|
|
this.bar.width(0);
|
|
|
|
this.textElement.width(0);
|
2008-07-10 02:50:51 +00:00
|
|
|
this.bar.addClass('ui-hidden');
|
2008-08-09 23:06:18 +00:00
|
|
|
this.options.interval = this.options._interval;
|
2008-08-16 06:00:46 +00:00
|
|
|
this._propagate('stop', this.ui());
|
2008-07-10 02:50:51 +00:00
|
|
|
},
|
2008-08-09 23:06:18 +00:00
|
|
|
progress: function(percentState) {
|
|
|
|
if (this.bar.is('.ui-hidden')) {
|
|
|
|
this.bar.removeClass('ui-hidden');
|
|
|
|
}
|
|
|
|
|
|
|
|
this.percentState = percentState > 100 ? 100 : percentState;
|
|
|
|
this.pixelState = (this.percentState/100)*this.options.width;
|
|
|
|
this.bar.width(this.pixelState);
|
|
|
|
this.textElement.width(this.pixelState);
|
|
|
|
|
|
|
|
if (this.options.range && !this.options.text) {
|
|
|
|
this.textElement.html(Math.round(this.percentState) + '%');
|
|
|
|
}
|
2008-08-16 06:00:46 +00:00
|
|
|
this._propagate('progress', this.ui());
|
2008-07-10 02:50:51 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$.ui.progressbar.defaults = {
|
2008-08-09 23:06:18 +00:00
|
|
|
width: 300,
|
2008-07-10 02:50:51 +00:00
|
|
|
duration: 3000,
|
2008-08-09 23:06:18 +00:00
|
|
|
interval: 200,
|
|
|
|
increment: 1,
|
2008-08-07 20:17:02 +00:00
|
|
|
range: true,
|
2008-07-10 02:50:51 +00:00
|
|
|
text: '',
|
2008-08-09 23:06:18 +00:00
|
|
|
addClass: '',
|
2008-07-10 02:50:51 +00:00
|
|
|
textClass: ''
|
|
|
|
};
|
2008-07-09 11:09:40 +00:00
|
|
|
|
2008-08-09 23:06:18 +00:00
|
|
|
})(jQuery);
|