2008-09-19 17:21:45 +00:00
|
|
|
/*
|
2008-09-20 13:11:01 +00:00
|
|
|
* jQuery UI Progressbar @VERSION
|
2008-09-19 17:21:45 +00:00
|
|
|
*
|
2012-03-19 13:25:07 +00:00
|
|
|
* Copyright 2012, AUTHORS.txt (http://jqueryui.com/about)
|
2010-07-09 13:01:04 +00:00
|
|
|
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
|
|
* http://jquery.org/license
|
2008-09-19 17:21:45 +00:00
|
|
|
*
|
2008-09-20 13:11:01 +00:00
|
|
|
* http://docs.jquery.com/UI/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", {
|
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() {
|
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,
|
2008-12-05 15:42:46 +00:00
|
|
|
"aria-valuenow": this._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
|
|
|
|
2010-11-22 13:49:47 +00:00
|
|
|
this.oldValue = this._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
|
|
|
|
2008-11-21 04:12:18 +00:00
|
|
|
destroy: function() {
|
|
|
|
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-11-21 04:12:18 +00:00
|
|
|
|
2010-02-07 03:40:13 +00:00
|
|
|
$.Widget.prototype.destroy.apply( this, arguments );
|
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 ) {
|
2009-04-16 01:57:56 +00:00
|
|
|
return this._value();
|
|
|
|
}
|
2010-02-07 03:40:13 +00:00
|
|
|
|
|
|
|
this._setOption( "value", 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
|
|
|
|
2010-02-07 03:40:13 +00:00
|
|
|
_setOption: function( key, value ) {
|
2010-07-29 09:38:24 +00:00
|
|
|
if ( key === "value" ) {
|
|
|
|
this.options.value = value;
|
|
|
|
this._refreshValue();
|
2010-11-22 13:49:47 +00:00
|
|
|
if ( this._value() === this.options.max ) {
|
2010-09-27 14:44:04 +00:00
|
|
|
this._trigger( "complete" );
|
|
|
|
}
|
2008-09-20 11:22:54 +00:00
|
|
|
}
|
2008-12-05 13:35:11 +00:00
|
|
|
|
2010-02-07 03:40:13 +00:00
|
|
|
$.Widget.prototype._setOption.apply( this, arguments );
|
2008-09-19 17:21:45 +00:00
|
|
|
},
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-12-05 15:42:46 +00:00
|
|
|
_value: function() {
|
|
|
|
var val = this.options.value;
|
2009-09-15 08:38:11 +00:00
|
|
|
// normalize invalid 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 ) );
|
|
|
|
},
|
|
|
|
|
|
|
|
_percentage: function() {
|
|
|
|
return 100 * this._value() / this.options.max;
|
2008-12-05 15:42:46 +00:00
|
|
|
},
|
|
|
|
|
2008-12-05 13:35:11 +00:00
|
|
|
_refreshValue: function() {
|
2008-12-05 15:42:46 +00:00
|
|
|
var value = this.value();
|
2010-11-22 13:49:47 +00:00
|
|
|
var percentage = this._percentage();
|
|
|
|
|
|
|
|
if ( this.oldValue !== value ) {
|
|
|
|
this.oldValue = value;
|
|
|
|
this._trigger( "change" );
|
|
|
|
}
|
|
|
|
|
2010-02-07 03:40:13 +00:00
|
|
|
this.valueDiv
|
2011-04-08 23:55:14 +00:00
|
|
|
.toggle( value > this.min )
|
2010-11-22 13:49:47 +00:00
|
|
|
.toggleClass( "ui-corner-right", value === this.options.max )
|
|
|
|
.width( percentage.toFixed(0) + "%" );
|
2010-02-07 03:40:13 +00:00
|
|
|
this.element.attr( "aria-valuenow", value );
|
2008-11-17 00:21:36 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2010-02-07 03:40:13 +00:00
|
|
|
$.extend( $.ui.progressbar, {
|
2010-01-07 03:19:50 +00:00
|
|
|
version: "@VERSION"
|
2008-09-19 17:21:45 +00:00
|
|
|
});
|
|
|
|
|
2010-02-07 03:40:13 +00:00
|
|
|
})( jQuery );
|