Skip to content

Commit

Permalink
Progressbar: Create and destroy indeterminate overlay as needed and c…
Browse files Browse the repository at this point in the history
…ode cleanup.
  • Loading branch information
kborchers committed Nov 30, 2012
1 parent d7bff01 commit f2ee4c5
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions ui/jquery.ui.progressbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ $.widget( "ui.progressbar", {
"aria-valuenow": this.options.value
});

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

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

_refreshValue: function() {
var value = this.options.value,
percentage = this._percentage(),
overlay = this.valueDiv.children().eq( 0 );
percentage = this._percentage();

overlay.toggleClass( "ui-progressbar-overlay", this.indeterminate );
this.valueDiv.toggleClass( "ui-progressbar-indeterminate", this.indeterminate );
this.valueDiv
.toggle( this.indeterminate || value > this.min )
.toggleClass( "ui-corner-right", value === this.options.max )
.toggleClass( "ui-progressbar-indeterminate", this.indeterminate )
.width( percentage.toFixed(0) + "%" );

if ( this.indeterminate ) {
this.element.removeAttr( "aria-valuemax" ).removeAttr( "aria-valuenow" );
if ( !this.overlayDiv ) {
this.overlayDiv = $( "<div class='ui-progressbar-overlay'></div>" ).appendTo( this.valueDiv );
}
} else {
this.element.attr({
"aria-valuemax": this.options.max,
"aria-valuenow": value
});
if ( this.overlayDiv ) {
this.overlayDiv.remove();
this.overlayDiv = null;
}
}

if ( this.oldValue !== value ) {
this.oldValue = value;
Expand All @@ -127,18 +145,6 @@ $.widget( "ui.progressbar", {
if ( value === this.options.max ) {
this._trigger( "complete" );
}

this.valueDiv
.toggle( this.indeterminate || value > this.min )
.toggleClass( "ui-corner-right", value === this.options.max )
.width( percentage.toFixed(0) + "%" );
if ( this.indeterminate ) {
this.element.removeAttr( "aria-valuemax" );
this.element.removeAttr( "aria-valuenow" );
} else {
this.element.attr( "aria-valuemax", this.options.max );
this.element.attr( "aria-valuenow", value );
}
}
});

Expand Down

0 comments on commit f2ee4c5

Please sign in to comment.