jquery-ui/ui/ui.progressbar.js

115 lines
2.2 KiB
JavaScript
Raw Normal View History

/*
* jQuery UI Progressbar @VERSION
*
* Copyright (c) 2008 AUTHORS.txt (http://ui.jquery.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() {
var self = this,
2008-12-05 13:35:11 +00:00
options = this.options;
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")
2008-12-05 13:35:11 +00:00
.removeData("progressbar")
.unbind(".progressbar");
this.valueDiv.remove();
2008-11-21 04:12:18 +00:00
$.widget.prototype.destroy.apply(this, arguments);
},
2008-12-05 13:35:11 +00:00
value: function(newValue) {
arguments.length && this._setData("value", newValue);
return this._value();
2008-12-05 13:35:11 +00:00
},
2008-12-05 13:35:11 +00:00
_setData: function(key, value){
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;
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
2008-12-05 13:35:11 +00:00
}
});
2008-09-20 01:48:18 +00:00
})(jQuery);