2012-02-27 00:49:51 +00:00
|
|
|
/*!
|
2008-09-20 13:11:01 +00:00
|
|
|
* jQuery UI Progressbar @VERSION
|
2012-07-04 13:08:08 +00:00
|
|
|
* http://jqueryui.com
|
2008-09-19 17:21:45 +00:00
|
|
|
*
|
2012-07-04 13:08:08 +00:00
|
|
|
* Copyright 2012 jQuery Foundation and other contributors
|
2012-08-09 14:13:24 +00:00
|
|
|
* Released under the MIT license.
|
2010-07-09 13:01:04 +00:00
|
|
|
* http://jquery.org/license
|
2008-09-19 17:21:45 +00:00
|
|
|
*
|
2012-09-26 23:06:20 +00:00
|
|
|
* http://api.jqueryui.com/progressbar/
|
2008-09-19 17:21:45 +00:00
|
|
|
*
|
|
|
|
* Depends:
|
2009-09-17 10:39:12 +00:00
|
|
|
* jquery.ui.core.js
|
2009-12-22 19:51:24 +00:00
|
|
|
* jquery.ui.widget.js
|
2008-09-19 17:21:45 +00:00
|
|
|
*/
|
2010-07-13 13:57:58 +00:00
|
|
|
(function( $, undefined ) {
|
2008-09-19 17:21:45 +00:00
|
|
|
|
2010-02-07 03:40:13 +00:00
|
|
|
$.widget( "ui.progressbar", {
|
2011-05-28 19:39:55 +00:00
|
|
|
version: "@VERSION",
|
2010-01-07 03:19:50 +00:00
|
|
|
options: {
|
2010-11-22 13:49:47 +00:00
|
|
|
value: 0,
|
|
|
|
max: 100
|
2010-01-07 03:19:50 +00:00
|
|
|
},
|
2010-07-29 09:38:24 +00:00
|
|
|
|
|
|
|
min: 0,
|
|
|
|
|
2010-01-15 18:58:20 +00:00
|
|
|
_create: function() {
|
2012-11-08 18:02:25 +00:00
|
|
|
// Constrain initial value
|
|
|
|
this.options.value = this._constrainedValue();
|
|
|
|
|
2008-10-29 16:57:04 +00:00
|
|
|
this.element
|
2010-02-07 03:40:13 +00:00
|
|
|
.addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
|
2008-11-07 13:57:31 +00:00
|
|
|
.attr({
|
2009-01-16 02:09:45 +00:00
|
|
|
role: "progressbar",
|
2010-07-29 09:38:24 +00:00
|
|
|
"aria-valuemin": this.min,
|
2010-11-22 13:49:47 +00:00
|
|
|
"aria-valuemax": this.options.max,
|
2012-11-08 18:02:25 +00:00
|
|
|
"aria-valuenow": this.options.value
|
2008-11-07 13:57:31 +00:00
|
|
|
});
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2010-02-07 03:40:13 +00:00
|
|
|
this.valueDiv = $( "<div class='ui-progressbar-value ui-widget-header ui-corner-left'></div>" )
|
|
|
|
.appendTo( this.element );
|
2008-12-05 13:35:11 +00:00
|
|
|
|
2012-11-08 18:02:25 +00:00
|
|
|
this.oldValue = this.options.value;
|
2008-12-05 13:35:11 +00:00
|
|
|
this._refreshValue();
|
2008-09-19 17:21:45 +00:00
|
|
|
},
|
2008-09-20 11:22:54 +00:00
|
|
|
|
2011-01-14 22:11:22 +00:00
|
|
|
_destroy: function() {
|
2008-11-21 04:12:18 +00:00
|
|
|
this.element
|
2010-02-07 03:40:13 +00:00
|
|
|
.removeClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
|
|
|
|
.removeAttr( "role" )
|
|
|
|
.removeAttr( "aria-valuemin" )
|
|
|
|
.removeAttr( "aria-valuemax" )
|
|
|
|
.removeAttr( "aria-valuenow" );
|
2008-12-05 13:35:11 +00:00
|
|
|
|
|
|
|
this.valueDiv.remove();
|
2008-09-19 17:21:45 +00:00
|
|
|
},
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2010-02-07 03:40:13 +00:00
|
|
|
value: function( newValue ) {
|
|
|
|
if ( newValue === undefined ) {
|
2012-11-08 18:02:25 +00:00
|
|
|
return this.options.value;
|
2009-04-16 01:57:56 +00:00
|
|
|
}
|
2010-02-07 03:40:13 +00:00
|
|
|
|
2012-11-08 18:02:25 +00:00
|
|
|
this._setOption( "value", this._constrainedValue( newValue ) );
|
2009-04-16 01:57:56 +00:00
|
|
|
return this;
|
2008-12-05 13:35:11 +00:00
|
|
|
},
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2012-11-08 18:02:25 +00:00
|
|
|
_constrainedValue: function( newValue ) {
|
|
|
|
var val;
|
|
|
|
if ( newValue === undefined ) {
|
|
|
|
val = this.options.value;
|
|
|
|
} else {
|
|
|
|
val = newValue;
|
2008-09-20 11:22:54 +00:00
|
|
|
}
|
2008-12-05 13:35:11 +00:00
|
|
|
|
2012-11-08 18:02:25 +00:00
|
|
|
// sanitize value
|
2010-02-07 03:40:13 +00:00
|
|
|
if ( typeof val !== "number" ) {
|
2009-09-15 08:38:11 +00:00
|
|
|
val = 0;
|
2010-02-07 03:40:13 +00:00
|
|
|
}
|
2010-11-22 13:49:47 +00:00
|
|
|
return Math.min( this.options.max, Math.max( this.min, val ) );
|
|
|
|
},
|
|
|
|
|
2012-11-08 18:02:25 +00:00
|
|
|
_setOptions: function( options ) {
|
2012-11-11 07:52:02 +00:00
|
|
|
var val = options.value;
|
|
|
|
|
|
|
|
delete options.value;
|
|
|
|
this._super( options );
|
2012-11-08 18:02:25 +00:00
|
|
|
|
|
|
|
if ( val !== undefined ) {
|
|
|
|
this._setOption( "value", val );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_setOption: function( key, value ) {
|
|
|
|
if ( key === "max" ) {
|
|
|
|
// Don't allow a max less than min
|
|
|
|
this.options.max = Math.max( this.min, value );
|
|
|
|
this.options.value = this._constrainedValue();
|
|
|
|
}
|
|
|
|
if ( key === "value" ) {
|
|
|
|
this.options.value = this._constrainedValue( value );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this._super( key, value );
|
|
|
|
}
|
|
|
|
|
|
|
|
this._refreshValue();
|
|
|
|
},
|
|
|
|
|
2010-11-22 13:49:47 +00:00
|
|
|
_percentage: function() {
|
2012-11-08 18:02:25 +00:00
|
|
|
return 100 * this.options.value / this.options.max;
|
2008-12-05 15:42:46 +00:00
|
|
|
},
|
|
|
|
|
2008-12-05 13:35:11 +00:00
|
|
|
_refreshValue: function() {
|
2012-11-08 18:02:25 +00:00
|
|
|
var percentage = this._percentage();
|
2010-11-22 13:49:47 +00:00
|
|
|
|
2012-11-08 18:02:25 +00:00
|
|
|
if ( this.oldValue !== this.options.value ) {
|
|
|
|
this.oldValue = this.options.value;
|
2010-11-22 13:49:47 +00:00
|
|
|
this._trigger( "change" );
|
|
|
|
}
|
2012-11-08 18:02:25 +00:00
|
|
|
if ( this.options.value === this.options.max ) {
|
|
|
|
this._trigger( "complete" );
|
|
|
|
}
|
2010-11-22 13:49:47 +00:00
|
|
|
|
2010-02-07 03:40:13 +00:00
|
|
|
this.valueDiv
|
2012-11-08 18:02:25 +00:00
|
|
|
.toggle( this.options.value > this.min )
|
|
|
|
.toggleClass( "ui-corner-right", this.options.value === this.options.max )
|
2010-11-22 13:49:47 +00:00
|
|
|
.width( percentage.toFixed(0) + "%" );
|
2012-11-08 18:02:25 +00:00
|
|
|
this.element.attr( "aria-valuemax", this.options.max );
|
|
|
|
this.element.attr( "aria-valuenow", this.options.value );
|
2008-11-17 00:21:36 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2010-02-07 03:40:13 +00:00
|
|
|
})( jQuery );
|