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
|
|
|
*
|
2013-01-10 13:52:20 +00:00
|
|
|
* Copyright 2013 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: {
|
2012-12-06 14:21:25 +00:00
|
|
|
max: 100,
|
2010-11-22 13:49:47 +00:00
|
|
|
value: 0,
|
2012-12-06 14:21:25 +00:00
|
|
|
|
|
|
|
change: null,
|
|
|
|
complete: null
|
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
|
2012-12-06 15:10:07 +00:00
|
|
|
this.oldValue = this.options.value = this._constrainedValue();
|
2012-11-08 18:02:25 +00:00
|
|
|
|
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({
|
2012-12-06 14:35:41 +00:00
|
|
|
// Only set static values, aria-valuenow and aria-valuemax are
|
|
|
|
// set inside _refreshValue()
|
2009-01-16 02:09:45 +00:00
|
|
|
role: "progressbar",
|
2012-12-06 14:35:41 +00:00
|
|
|
"aria-valuemin": this.min
|
2008-11-07 13:57:31 +00:00
|
|
|
});
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2012-11-30 04:12:02 +00:00
|
|
|
this.valueDiv = $( "<div class='ui-progressbar-value ui-widget-header ui-corner-left'></div>" )
|
2010-02-07 03:40:13 +00:00
|
|
|
.appendTo( this.element );
|
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-12-06 15:10:07 +00:00
|
|
|
this.options.value = this._constrainedValue( newValue );
|
|
|
|
this._refreshValue();
|
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 ) {
|
|
|
|
if ( newValue === undefined ) {
|
2012-12-06 15:10:07 +00:00
|
|
|
newValue = this.options.value;
|
2008-09-20 11:22:54 +00:00
|
|
|
}
|
2008-12-05 13:35:11 +00:00
|
|
|
|
2012-12-06 15:10:07 +00:00
|
|
|
this.indeterminate = newValue === false;
|
2012-03-27 02:51:16 +00:00
|
|
|
|
2012-11-08 18:02:25 +00:00
|
|
|
// sanitize value
|
2012-12-06 15:10:07 +00:00
|
|
|
if ( typeof newValue !== "number" ) {
|
|
|
|
newValue = 0;
|
2010-02-07 03:40:13 +00:00
|
|
|
}
|
2012-12-06 15:10:07 +00:00
|
|
|
|
|
|
|
return this.indeterminate ? false :
|
|
|
|
Math.min( this.options.max, Math.max( this.min, newValue ) );
|
2010-11-22 13:49:47 +00:00
|
|
|
},
|
|
|
|
|
2012-11-08 18:02:25 +00:00
|
|
|
_setOptions: function( options ) {
|
2012-03-27 02:51:16 +00:00
|
|
|
// Ensure "value" option is set after other values (like max)
|
2012-12-06 15:10:07 +00:00
|
|
|
var value = options.value;
|
2012-11-11 07:52:02 +00:00
|
|
|
delete options.value;
|
2012-12-06 15:10:07 +00:00
|
|
|
|
2012-11-11 07:52:02 +00:00
|
|
|
this._super( options );
|
2012-11-08 18:02:25 +00:00
|
|
|
|
2012-12-06 15:10:07 +00:00
|
|
|
this.options.value = this._constrainedValue( value );
|
|
|
|
this._refreshValue();
|
2012-11-08 18:02:25 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_setOption: function( key, value ) {
|
|
|
|
if ( key === "max" ) {
|
|
|
|
// Don't allow a max less than min
|
2012-12-06 15:10:07 +00:00
|
|
|
value = Math.max( this.min, value );
|
2012-11-08 18:02:25 +00:00
|
|
|
}
|
|
|
|
|
2012-12-06 15:10:07 +00:00
|
|
|
this._super( key, value );
|
2012-11-08 18:02:25 +00:00
|
|
|
},
|
|
|
|
|
2010-11-22 13:49:47 +00:00
|
|
|
_percentage: function() {
|
2012-12-06 17:07:07 +00:00
|
|
|
return this.indeterminate ? 100 : 100 * ( this.options.value - this.min ) / ( this.options.max - this.min );
|
2008-12-05 15:42:46 +00:00
|
|
|
},
|
|
|
|
|
2008-12-05 13:35:11 +00:00
|
|
|
_refreshValue: function() {
|
2012-03-27 02:51:16 +00:00
|
|
|
var value = this.options.value,
|
2012-11-30 04:12:02 +00:00
|
|
|
percentage = this._percentage();
|
2012-03-27 02:51:16 +00:00
|
|
|
|
2012-11-30 04:12:02 +00:00
|
|
|
this.valueDiv
|
|
|
|
.toggle( this.indeterminate || value > this.min )
|
|
|
|
.toggleClass( "ui-corner-right", value === this.options.max )
|
|
|
|
.width( percentage.toFixed(0) + "%" );
|
|
|
|
|
2012-12-12 16:21:49 +00:00
|
|
|
this.element.toggleClass( "ui-progressbar-indeterminate", this.indeterminate );
|
|
|
|
|
2012-11-30 04:12:02 +00:00
|
|
|
if ( this.indeterminate ) {
|
2012-12-06 14:35:41 +00:00
|
|
|
this.element.removeAttr( "aria-valuenow" );
|
2012-11-30 04:12:02 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2010-11-22 13:49:47 +00:00
|
|
|
|
2012-03-27 02:51:16 +00:00
|
|
|
if ( this.oldValue !== value ) {
|
|
|
|
this.oldValue = value;
|
2010-11-22 13:49:47 +00:00
|
|
|
this._trigger( "change" );
|
|
|
|
}
|
2012-03-27 02:51:16 +00:00
|
|
|
if ( value === this.options.max ) {
|
2012-11-08 18:02:25 +00:00
|
|
|
this._trigger( "complete" );
|
|
|
|
}
|
2008-11-17 00:21:36 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2010-02-07 03:40:13 +00:00
|
|
|
})( jQuery );
|