progressbar: Removed all progressbar options except value. Added visual test for disabled progressbar.

This commit is contained in:
Richard Worth 2008-12-10 05:12:08 +00:00
parent 38e2135472
commit c95e3b27a4
2 changed files with 13 additions and 119 deletions

View File

@ -1,33 +1,21 @@
<!doctype html> <!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
<meta http-equiv="Content-Language" content="en" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery UI Progressbar Visual Tests</title> <title>jQuery UI Progressbar Visual Tests</title>
<link rel="stylesheet" href="../../themes/base/ui.all.css" type="text/css" />
<script type="text/javascript" src="../../jquery-1.2.6.js"></script> <script type="text/javascript" src="../../jquery-1.2.6.js"></script>
<script type="text/javascript" src="../../ui/ui.core.js"></script> <script type="text/javascript" src="../../ui/ui.core.js"></script>
<script type="text/javascript" src="../../ui/ui.progressbar.js"></script> <script type="text/javascript" src="../../ui/ui.progressbar.js"></script>
<style type="text/css">
.ui-progressbar { position: relative; height: 22px; border: 1px solid black; }
.ui-progressbar-labelalign-left { text-align: left; }
.ui-progressbar-labelalign-center { text-align: center; }
.ui-progressbar-labelalign-right { text-align: right; }
.ui-progressbar-label { color: black; }
.ui-progressbar-labelalign-left .ui-progressbar-label div { padding-left: 0.5em; }
.ui-progressbar-labelalign-right .ui-progressbar-label div { padding-right: 0.5em; }
.ui-progressbar-value { position: absolute; top: 0; background: gray; overflow: hidden; height: 100%; white-space: nowrap; }
.ui-progressbar-value .ui-progressbar-label { color: white; }
</style>
<script type="text/javascript"> <script type="text/javascript">
$(function() { $(function() {
$("#progressbar1").progressbar({ value: 6 }); $("#progressbar1").progressbar({ value: 6 });
$("#progressbar2").progressbar({ labelAlign: 'center', label: 'center' }).progressbar("option", "value", 50); $("#progressbar2").progressbar({ labelAlign: 'center', label: 'center' }).progressbar("option", "value", 50);
$("#progressbar3").progressbar().progressbar("option", "labelAlign", "right").progressbar("value", 90.73).data("label.progressbar", "right").progressbar("option", "label", true); $("#progressbar3").progressbar().progressbar("option", "labelAlign", "right").progressbar("value", 90.73).data("label.progressbar", "right").progressbar("option", "label", true);
$("#progressbar4").progressbar().progressbar("destroy"); $("#progressbar4").progressbar().progressbar("disable");
$("#progressbar5").progressbar({ value: -10 }); $("#progressbar5").progressbar().progressbar("disable").progressbar("destroy");
$("#progressbar6").progressbar().progressbar("value", 200); $("#progressbar6").progressbar({ value: -10 });
$("#progressbar7").progressbar().progressbar("value", 200);
}); });
</script> </script>
</head> </head>
@ -45,6 +33,8 @@
<div id="progressbar5"></div> <div id="progressbar5"></div>
<br> <br>
<div id="progressbar6"></div> <div id="progressbar6"></div>
<br>
<div id="progressbar7"></div>
</body> </body>
</html> </html>

View File

@ -21,7 +21,6 @@ $.widget("ui.progressbar", {
this.element this.element
.addClass("ui-progressbar" .addClass("ui-progressbar"
+ " ui-progressbar-labelalign-" + this._labelAlign()
+ " ui-widget-content" + " ui-widget-content"
+ " ui-corner-all") + " ui-corner-all")
.attr({ .attr({
@ -31,21 +30,9 @@ $.widget("ui.progressbar", {
"aria-valuenow": this._value() "aria-valuenow": this._value()
}); });
this.element this.valueDiv = $('<div class="ui-progressbar-value ui-state-default ui-corner-left"></div>').appendTo(this.element);
.append('<div class="ui-progressbar-label"></div>')
.append('<div class="ui-progressbar-value ui-state-default ui-corner-left">'
+ '<div class="ui-progressbar-label"></div>'
+ '</div>'
);
this.valueDiv = this.element.find(".ui-progressbar-value");
this.valueLabel = this.valueDiv.find(".ui-progressbar-label");
this.labels = this.element.find(".ui-progressbar-label");
this._refreshLabel();
this._refreshValue(); this._refreshValue();
this._refreshWidth();
this._refreshHeight();
}, },
@ -53,10 +40,6 @@ $.widget("ui.progressbar", {
this.element this.element
.removeClass("ui-progressbar" .removeClass("ui-progressbar"
+ " ui-progressbar-disabled"
+ " ui-progressbar-labelalign-left"
+ " ui-progressbar-labelalign-center"
+ " ui-progressbar-labelalign-right"
+ " ui-widget-content" + " ui-widget-content"
+ " ui-corner-all") + " ui-corner-all")
.removeAttr("role") .removeAttr("role")
@ -66,81 +49,30 @@ $.widget("ui.progressbar", {
.removeData("progressbar") .removeData("progressbar")
.unbind(".progressbar"); .unbind(".progressbar");
this.labels.remove();
this.valueDiv.remove(); this.valueDiv.remove();
}, $.widget.prototype.destroy.apply(this, arguments);
disable: function() {
this.element.attr("aria-disabled", true);
},
enable: function() {
this.element.attr("aria-disabled", false);
}, },
value: function(newValue) { value: function(newValue) {
arguments.length && this._setData("value", newValue); arguments.length && this._setData("value", newValue);
return this._value(); return this._value();
}, },
_setData: function(key, value){ _setData: function(key, value){
switch (key) { switch (key) {
case 'height':
this.options.height = value;
this._refreshHeight();
break;
case 'label':
this.options.label = value;
this._refreshLabel();
break;
case 'labelAlign':
this.options.labelAlign = value;
this._refreshLabelAlign();
break;
case 'value': case 'value':
this.options.value = value; this.options.value = value;
this._refreshLabel();
this._refreshValue(); this._refreshValue();
this._trigger('change', null, {}); this._trigger('change', null, {});
break; break;
case 'width':
this.options.width = value;
break;
} }
$.widget.prototype._setData.apply(this, arguments); $.widget.prototype._setData.apply(this, arguments);
}, },
//Property Getters - these return valid property values without modifying options
_labelText: function() {
var labelText;
if (this.options.label === true) {
labelText = this.value() + '%';
} else {
labelText = this.options.label;
}
return labelText;
},
_labelAlign: function() {
var labelAlign;
switch (this.options.labelAlign.toLowerCase()) {
case 'left':
case 'center':
case 'right':
labelAlign = this.options.labelAlign;
break;
default:
labelAlign = 'left';
}
return labelAlign.toLowerCase();
},
_value: function() { _value: function() {
var val = this.options.value; var val = this.options.value;
if (val < this._valueMin()) val = this._valueMin(); if (val < this._valueMin()) val = this._valueMin();
@ -161,35 +93,11 @@ $.widget("ui.progressbar", {
return valueMax; return valueMax;
}, },
//Refresh Methods - these refresh parts of the widget to match its current state
_refreshHeight: function() {
this.element.height(this.options.height);
},
_refreshLabel: function() {
var labelText = this._labelText();
// this extra wrapper div is required for padding to work with labelAlign: left and labelAlign: right
this.labels.html("<div>" + labelText + "</div>");
},
_refreshLabelAlign: function() {
var labelAlign = this._labelAlign();
this.element
.removeClass("ui-progressbar-labelalign-left"
+ " ui-progressbar-labelalign-center"
+ " ui-progressbar-labelalign-right")
.addClass("ui-progressbar-labelalign-" + labelAlign);
},
_refreshValue: function() { _refreshValue: function() {
var value = this.value(); var value = this.value();
this.valueDiv[value == this._valueMax() ? 'addClass' : 'removeClass']("ui-corner-right");
this.valueDiv.width(value + '%'); this.valueDiv.width(value + '%');
this.element.attr("aria-valuenow", value); this.element.attr("aria-valuenow", value);
},
_refreshWidth: function() {
this.element.add(this.valueLabel).width(this.options.width);
} }
}); });
@ -197,11 +105,7 @@ $.widget("ui.progressbar", {
$.extend($.ui.progressbar, { $.extend($.ui.progressbar, {
version: "@VERSION", version: "@VERSION",
defaults: { defaults: {
height: 20, value: 0
label: true,
labelAlign: 'left',
value: 0,
width: 300
} }
}); });