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
|
2021-06-06 22:58:12 +00:00
|
|
|
/* eslint-disable max-len */
|
2014-10-30 19:55:08 +00:00
|
|
|
//>>description: Displays a status indicator for loading state, standard percentage, and other progress indicators.
|
2021-06-06 22:58:12 +00:00
|
|
|
/* eslint-enable max-len */
|
2014-10-30 19:55:08 +00:00
|
|
|
//>>docs: http://api.jqueryui.com/progressbar/
|
|
|
|
//>>demos: http://jqueryui.com/progressbar/
|
2015-10-21 23:08:44 +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
|
|
|
|
2015-03-13 18:41:18 +00:00
|
|
|
( function( factory ) {
|
2021-06-06 22:58:12 +00:00
|
|
|
"use strict";
|
|
|
|
|
2013-07-12 16:40:48 +00:00
|
|
|
if ( typeof define === "function" && define.amd ) {
|
|
|
|
|
|
|
|
// AMD. Register as an anonymous module.
|
2015-03-13 18:41:18 +00:00
|
|
|
define( [
|
2013-07-12 16:40:48 +00:00
|
|
|
"jquery",
|
2015-07-15 02:04:22 +00:00
|
|
|
"../version",
|
|
|
|
"../widget"
|
2013-07-12 16:40:48 +00:00
|
|
|
], factory );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Browser globals
|
|
|
|
factory( jQuery );
|
|
|
|
}
|
2021-06-06 22:58:12 +00:00
|
|
|
} )( function( $ ) {
|
|
|
|
"use strict";
|
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
|
|
|
|
2015-03-13 18:41:18 +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
|
2015-03-13 18:41:18 +00:00
|
|
|
} );
|
2014-12-03 16:25:32 +00:00
|
|
|
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() {
|
2015-03-18 00:22:49 +00:00
|
|
|
this.element.removeAttr( "role aria-valuemin aria-valuemax 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
|
|
|
|
2015-08-21 04:07:48 +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 ) {
|
2015-08-24 12:58:48 +00:00
|
|
|
|
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" ) {
|
2015-08-24 12:58:48 +00:00
|
|
|
|
2012-11-08 18:02:25 +00:00
|
|
|
// 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
|
|
|
},
|
|
|
|
|
2015-09-21 10:55:33 +00:00
|
|
|
_setOptionDisabled: function( value ) {
|
|
|
|
this._super( value );
|
|
|
|
|
|
|
|
this.element.attr( "aria-disabled", value );
|
|
|
|
this._toggleClass( null, "ui-state-disabled", !!value );
|
|
|
|
},
|
|
|
|
|
2010-11-22 13:49:47 +00:00
|
|
|
_percentage: function() {
|
2016-03-31 02:52:49 +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 )
|
2015-03-13 18:41:18 +00:00
|
|
|
.width( percentage.toFixed( 0 ) + "%" );
|
2012-11-30 04:12:02 +00:00
|
|
|
|
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 {
|
2015-03-13 18:41:18 +00:00
|
|
|
this.element.attr( {
|
2012-11-30 04:12:02 +00:00
|
|
|
"aria-valuemax": this.options.max,
|
|
|
|
"aria-valuenow": value
|
2015-03-13 18:41:18 +00:00
|
|
|
} );
|
2012-11-30 04:12:02 +00:00
|
|
|
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
|
|
|
}
|
2015-03-13 18:41:18 +00:00
|
|
|
} );
|
2008-11-17 00:21:36 +00:00
|
|
|
|
2021-06-06 22:58:12 +00:00
|
|
|
} );
|