| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
(function( $, undefined ) { |
| 16 |
|
| 17 |
$.widget( "ui.progressbar", { |
| 18 |
version: "1.9.2", |
| 19 |
options: { |
| 20 |
value: 0, |
| 21 |
max: 100 |
| 22 |
}, |
| 23 |
|
| 24 |
min: 0, |
| 25 |
|
| 26 |
_create: function() { |
| 27 |
this.element |
| 28 |
.addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" ) |
| 29 |
.attr({ |
| 30 |
role: "progressbar", |
| 31 |
"aria-valuemin": this.min, |
| 32 |
"aria-valuemax": this.options.max, |
| 33 |
"aria-valuenow": this._value() |
| 34 |
}); |
| 35 |
|
| 36 |
this.valueDiv = $( "<div class='ui-progressbar-value ui-widget-header ui-corner-left'></div>" ) |
| 37 |
.appendTo( this.element ); |
| 38 |
|
| 39 |
this.oldValue = this._value(); |
| 40 |
this._refreshValue(); |
| 41 |
}, |
| 42 |
|
| 43 |
_destroy: function() { |
| 44 |
this.element |
| 45 |
.removeClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" ) |
| 46 |
.removeAttr( "role" ) |
| 47 |
.removeAttr( "aria-valuemin" ) |
| 48 |
.removeAttr( "aria-valuemax" ) |
| 49 |
.removeAttr( "aria-valuenow" ); |
| 50 |
|
| 51 |
this.valueDiv.remove(); |
| 52 |
}, |
| 53 |
|
| 54 |
value: function( newValue ) { |
| 55 |
if ( newValue === undefined ) { |
| 56 |
return this._value(); |
| 57 |
} |
| 58 |
|
| 59 |
this._setOption( "value", newValue ); |
| 60 |
return this; |
| 61 |
}, |
| 62 |
|
| 63 |
_setOption: function( key, value ) { |
| 64 |
if ( key === "value" ) { |
| 65 |
this.options.value = value; |
| 66 |
this._refreshValue(); |
| 67 |
if ( this._value() === this.options.max ) { |
| 68 |
this._trigger( "complete" ); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
this._super( key, value ); |
| 73 |
}, |
| 74 |
|
| 75 |
_value: function() { |
| 76 |
var val = this.options.value; |
| 77 |
|
| 78 |
if ( typeof val !== "number" ) { |
| 79 |
val = 0; |
| 80 |
} |
| 81 |
return Math.min( this.options.max, Math.max( this.min, val ) ); |
| 82 |
}, |
| 83 |
|
| 84 |
_percentage: function() { |
| 85 |
return 100 * this._value() / this.options.max; |
| 86 |
}, |
| 87 |
|
| 88 |
_refreshValue: function() { |
| 89 |
var value = this.value(), |
| 90 |
percentage = this._percentage(); |
| 91 |
|
| 92 |
if ( this.oldValue !== value ) { |
| 93 |
this.oldValue = value; |
| 94 |
this._trigger( "change" ); |
| 95 |
} |
| 96 |
|
| 97 |
this.valueDiv |
| 98 |
.toggle( value > this.min ) |
| 99 |
.toggleClass( "ui-corner-right", value === this.options.max ) |
| 100 |
.width( percentage.toFixed(0) + "%" ); |
| 101 |
this.element.attr( "aria-valuenow", value ); |
| 102 |
} |
| 103 |
}); |
| 104 |
|
| 105 |
})( jQuery ); |