Skip to content

Commit 6f54938

Browse files
committed
Progressbar: Add indeterminate checks and proper overlay handling
1 parent dc6e692 commit 6f54938

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

ui/jquery.ui.progressbar.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ $.widget( "ui.progressbar", {
7171
val = newValue;
7272
}
7373

74+
this.indeterminate = val === false;
75+
7476
// sanitize value
7577
if ( typeof val !== "number" ) {
7678
val = 0;
@@ -107,26 +109,33 @@ $.widget( "ui.progressbar", {
107109
},
108110

109111
_percentage: function() {
110-
return 100 * this.options.value / this.options.max;
112+
return this.indeterminate ? 100 : 100 * this.options.value / this.options.max;
111113
},
112114

113115
_refreshValue: function() {
114-
var percentage = this._percentage();
116+
var value = this.value(),
117+
percentage = this._percentage(),
118+
overlay = this.valueDiv.children().eq( 0 );
119+
120+
overlay.toggleClass( "ui-progressbar-overlay", this.indeterminate );
121+
this.valueDiv.toggleClass( "ui-progressbar-indeterminate", this.indeterminate );
115122

116-
if ( this.oldValue !== this.options.value ) {
117-
this.oldValue = this.options.value;
123+
if ( this.oldValue !== value ) {
124+
this.oldValue = value;
118125
this._trigger( "change" );
119126
}
120-
if ( this.options.value === this.options.max ) {
121-
this._trigger( "complete" );
122-
}
123127

124128
this.valueDiv
125-
.toggle( this.options.value > this.min )
126-
.toggleClass( "ui-corner-right", this.options.value === this.options.max )
129+
.toggle( this.indeterminate || value > this.min )
130+
.toggleClass( "ui-corner-right", value === this.options.max )
127131
.width( percentage.toFixed(0) + "%" );
128-
this.element.attr( "aria-valuemax", this.options.max );
129-
this.element.attr( "aria-valuenow", this.options.value );
132+
if ( this.indeterminate ) {
133+
this.element.removeAttr( "aria-valuemax" );
134+
this.element.removeAttr( "aria-valuenow" );
135+
} else {
136+
this.element.attr( "aria-valuemax", this.options.max );
137+
this.element.attr( "aria-valuenow", value );
138+
}
130139
}
131140
});
132141

0 commit comments

Comments
 (0)