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
|
|
|
*
|
2010-07-14 19:45:45 +00:00
|
|
|
* Copyright 2010, 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: {
|
|
|
|
value: 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",
|
2008-12-05 15:42:46 +00:00
|
|
|
"aria-valuemin": this._valueMin(),
|
|
|
|
"aria-valuemax": this._valueMax(),
|
|
|
|
"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
|
|
|
|
|
|
|
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 ) {
|
|
|
|
switch ( key ) {
|
|
|
|
case "value":
|
2008-12-05 15:42:46 +00:00
|
|
|
this.options.value = value;
|
|
|
|
this._refreshValue();
|
2010-02-07 03:40:13 +00:00
|
|
|
this._trigger( "change" );
|
2008-12-05 13:35:11 +00:00
|
|
|
break;
|
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
|
|
|
}
|
|
|
|
if ( val < this._valueMin() ) {
|
|
|
|
val = this._valueMin();
|
|
|
|
}
|
|
|
|
if ( val > this._valueMax() ) {
|
|
|
|
val = this._valueMax();
|
|
|
|
}
|
2008-12-05 15:42:46 +00:00
|
|
|
|
|
|
|
return val;
|
|
|
|
},
|
|
|
|
|
|
|
|
_valueMin: function() {
|
2010-02-07 03:40:13 +00:00
|
|
|
return 0;
|
2008-12-05 15:42:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_valueMax: function() {
|
2010-02-07 03:40:13 +00:00
|
|
|
return 100;
|
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-02-07 03:40:13 +00:00
|
|
|
this.valueDiv
|
|
|
|
[ value === this._valueMax() ? "addClass" : "removeClass"]( "ui-corner-right" )
|
|
|
|
.width( value + "%" );
|
|
|
|
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 );
|