Skip to content

Commit f2ee4c5

Browse files
committed
Progressbar: Create and destroy indeterminate overlay as needed and code cleanup.
1 parent d7bff01 commit f2ee4c5

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

ui/jquery.ui.progressbar.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ $.widget( "ui.progressbar", {
3636
"aria-valuenow": this.options.value
3737
});
3838

39-
this.valueDiv = $( "<div class='ui-progressbar-value ui-widget-header ui-corner-left'><div></div></div>" )
39+
this.valueDiv = $( "<div class='ui-progressbar-value ui-widget-header ui-corner-left'></div>" )
4040
.appendTo( this.element );
4141

4242
this.oldValue = this.options.value;
@@ -114,11 +114,29 @@ $.widget( "ui.progressbar", {
114114

115115
_refreshValue: function() {
116116
var value = this.options.value,
117-
percentage = this._percentage(),
118-
overlay = this.valueDiv.children().eq( 0 );
117+
percentage = this._percentage();
119118

120-
overlay.toggleClass( "ui-progressbar-overlay", this.indeterminate );
121-
this.valueDiv.toggleClass( "ui-progressbar-indeterminate", this.indeterminate );
119+
this.valueDiv
120+
.toggle( this.indeterminate || value > this.min )
121+
.toggleClass( "ui-corner-right", value === this.options.max )
122+
.toggleClass( "ui-progressbar-indeterminate", this.indeterminate )
123+
.width( percentage.toFixed(0) + "%" );
124+
125+
if ( this.indeterminate ) {
126+
this.element.removeAttr( "aria-valuemax" ).removeAttr( "aria-valuenow" );
127+
if ( !this.overlayDiv ) {
128+
this.overlayDiv = $( "<div class='ui-progressbar-overlay'></div>" ).appendTo( this.valueDiv );
129+
}
130+
} else {
131+
this.element.attr({
132+
"aria-valuemax": this.options.max,
133+
"aria-valuenow": value
134+
});
135+
if ( this.overlayDiv ) {
136+
this.overlayDiv.remove();
137+
this.overlayDiv = null;
138+
}
139+
}
122140

123141
if ( this.oldValue !== value ) {
124142
this.oldValue = value;
@@ -127,18 +145,6 @@ $.widget( "ui.progressbar", {
127145
if ( value === this.options.max ) {
128146
this._trigger( "complete" );
129147
}
130-
131-
this.valueDiv
132-
.toggle( this.indeterminate || value > this.min )
133-
.toggleClass( "ui-corner-right", value === this.options.max )
134-
.width( percentage.toFixed(0) + "%" );
135-
if ( this.indeterminate ) {
136-
this.element.removeAttr( "aria-valuemax" );
137-
this.element.removeAttr( "aria-valuenow" );
138-
} else {
139-
this.element.attr( "aria-valuemax", this.options.max );
140-
this.element.attr( "aria-valuenow", value );
141-
}
142148
}
143149
});
144150

0 commit comments

Comments
 (0)