jquery-ui/ui/ui.progressbar.js

120 lines
2.2 KiB
JavaScript
Raw Normal View History

/*
* jQuery UI Progressbar @VERSION
*
2009-02-27 11:41:40 +00:00
* Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* http://docs.jquery.com/UI/Progressbar
*
* Depends:
* ui.core.js
*/
(function($) {
$.widget("ui.progressbar", {
2008-11-21 04:12:18 +00:00
_init: function() {
this.element
.addClass("ui-progressbar"
+ " ui-widget"
+ " ui-widget-content"
+ " ui-corner-all")
.attr({
role: "progressbar",
"aria-valuemin": this._valueMin(),
"aria-valuemax": this._valueMax(),
"aria-valuenow": this._value()
});
this.valueDiv = $('<div class="ui-progressbar-value ui-widget-header ui-corner-left"></div>').appendTo(this.element);
2008-12-05 13:35:11 +00:00
this._refreshValue();
},
2008-09-20 11:22:54 +00:00
2008-11-21 04:12:18 +00:00
destroy: function() {
this.element
.removeClass("ui-progressbar"
+ " ui-widget"
+ " ui-widget-content"
+ " ui-corner-all")
.removeAttr("role")
.removeAttr("aria-valuemin")
.removeAttr("aria-valuemax")
.removeAttr("aria-valuenow")
.removeData("progressbar")
.unbind(".progressbar");
2008-12-05 13:35:11 +00:00
this.valueDiv.remove();
2008-11-21 04:12:18 +00:00
$.widget.prototype.destroy.apply(this, arguments);
return this;
},
2008-12-05 13:35:11 +00:00
value: function(newValue) {
if (newValue === undefined) {
return this._value();
}
this._setData('value', newValue);
return this;
2008-12-05 13:35:11 +00:00
},
_setData: function(key, value) {
2008-12-05 13:35:11 +00:00
switch (key) {
case 'value':
this.options.value = value;
this._refreshValue();
this._trigger('change', null, {});
2008-12-05 13:35:11 +00:00
break;
2008-09-20 11:22:54 +00:00
}
2008-12-05 13:35:11 +00:00
$.widget.prototype._setData.apply(this, arguments);
},
_value: function() {
var val = this.options.value;
// normalize invalid value
if (typeof val != "number")
val = 0;
if (val < this._valueMin()) val = this._valueMin();
if (val > this._valueMax()) val = this._valueMax();
return val;
},
_valueMin: function() {
var valueMin = 0;
return valueMin;
},
_valueMax: function() {
var valueMax = 100;
return valueMax;
},
2008-12-05 13:35:11 +00:00
_refreshValue: function() {
var value = this.value();
this.valueDiv[value == this._valueMax() ? 'addClass' : 'removeClass']("ui-corner-right");
this.valueDiv.width(value + '%');
this.element.attr("aria-valuenow", value);
}
2008-12-31 08:22:11 +00:00
});
$.extend($.ui.progressbar, {
version: "@VERSION",
defaults: {
value: 0
2009-04-18 14:34:20 +00:00
}
});
2008-09-20 01:48:18 +00:00
})(jQuery);