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
|
|
|
*
|
2014-12-21 18:27:43 +00:00
|
|
|
* Copyright 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
|
|
|
*/
|
2014-10-30 19:55:08 +00:00
|
|
|
|
|
|
|
//>>label: Progressbar
|
|
|
|
//>>group: Widgets
|
|
|
|
//>>description: Displays a status indicator for loading state, standard percentage, and other progress indicators.
|
|
|
|
//>>docs: http://api.jqueryui.com/progressbar/
|
|
|
|
//>>demos: http://jqueryui.com/progressbar/
|
2014-04-15 14:45:46 +00:00
|
|
|
//>>css.structure: ../themes/base/core.css
|
|
|
|
//>>css.structure: ../themes/base/progressbar.css
|
|
|
|
//>>css.theme: ../themes/base/theme.css
|
2014-10-30 19:55:08 +00:00
|
|
|
|
2013-07-12 16:40:48 +00:00
|
|
|
(function( factory ) {
|
|
|
|
if ( typeof define === "function" && define.amd ) {
|
|
|
|
|
|
|
|
// AMD. Register as an anonymous module.
|
|
|
|
define([
|
|
|
|
"jquery",
|
2013-12-02 18:36:12 +00:00
|
|
|
"./core",
|
|
|
|
"./widget"
|
2013-07-12 16:40:48 +00:00
|
|
|
], factory );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Browser globals
|
|
|
|
factory( jQuery );
|
|
|
|
}
|
|
|
|
}(function( $ ) {
|
2008-09-19 17:21:45 +00:00
|
|
|
|
2013-07-12 16:40:48 +00:00
|
|
|
return $.widget( "ui.progressbar", {
|
2011-05-28 19:39:55 +00:00
|
|
|
version: "@VERSION",
|
2010-01-07 03:19:50 +00:00
|
|
|
options: {
|
2014-12-03 16:25:32 +00:00
|
|
|
classes: {
|
|
|
|
"ui-progressbar": "ui-corner-all",
|
|
|
|
"ui-progressbar-value": "ui-corner-left",
|
|
|
|
"ui-progressbar-complete": "ui-corner-right"
|
|
|
|
},
|
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() {
|
2014-12-03 16:25:32 +00:00
|
|
|
|
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
|
|
|
|
2014-12-03 16:25:32 +00:00
|
|
|
this.element.attr({
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2014-12-03 16:25:32 +00:00
|
|
|
// Only set static values; aria-valuenow and aria-valuemax are
|
|
|
|
// set inside _refreshValue()
|
|
|
|
role: "progressbar",
|
|
|
|
"aria-valuemin": this.min
|
|
|
|
});
|
|
|
|
this._addClass( "ui-progressbar", "ui-widget ui-widget-content" );
|
2008-12-05 13:35:11 +00:00
|
|
|
|
2014-12-03 16:25:32 +00:00
|
|
|
this.valueDiv = $( "<div>" ).appendTo( this.element );
|
|
|
|
this._addClass( this.valueDiv, "ui-progressbar-value", "ui-widget-header" );
|
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
|
|
|
.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
|
|
|
}
|
2013-03-14 23:08:21 +00:00
|
|
|
if ( key === "disabled" ) {
|
2014-12-03 16:25:32 +00:00
|
|
|
this.element.attr( "aria-disabled", value );
|
|
|
|
this._toggleClass( null, "ui-state-disabled", !!value );
|
2013-03-14 23:08:21 +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 )
|
|
|
|
.width( percentage.toFixed(0) + "%" );
|
|
|
|
|
2014-12-03 16:25:32 +00:00
|
|
|
this
|
|
|
|
._toggleClass( this.valueDiv, "ui-progressbar-complete", null,
|
|
|
|
value === this.options.max )
|
|
|
|
._toggleClass( "ui-progressbar-indeterminate", null, this.indeterminate );
|
2012-12-12 16:21:49 +00:00
|
|
|
|
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 ) {
|
2014-12-03 16:25:32 +00:00
|
|
|
this.overlayDiv = $( "<div>" ).appendTo( this.valueDiv );
|
|
|
|
this._addClass( this.overlayDiv, "ui-progressbar-overlay" );
|
2012-11-30 04:12:02 +00:00
|
|
|
}
|
|
|
|
} 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
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-07-12 16:40:48 +00:00
|
|
|
}));
|