/* * jQuery UI Progressbar @VERSION * * Copyright 2012, AUTHORS.txt (http://jqueryui.com/about) * Dual licensed under the MIT or GPL Version 2 licenses. * http://jquery.org/license * * http://docs.jquery.com/UI/Progressbar * * Depends: * jquery.ui.core.js * jquery.ui.widget.js */ (function( $, undefined ) { $.widget( "ui.progressbar", { version: "@VERSION", options: { value: 0, max: 100 }, min: 0, _create: function() { var val = this._value(); this.element .addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" ) .attr({ role: "progressbar", "aria-valuemin": this.min, "aria-valuemax": this.options.max }); this.valueDiv = $( "
" ) .appendTo( this.element ); this.oldValue = this._value(); this._refreshValue(); }, _destroy: function() { this.element .removeClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" ) .removeAttr( "role" ) .removeAttr( "aria-valuemin" ) .removeAttr( "aria-valuemax" ) .removeAttr( "aria-valuenow" ); this.valueDiv.remove(); }, value: function( newValue ) { if ( newValue === undefined ) { return this._value(); } this._setOption( "value", newValue ); return this; }, _setOption: function( key, value ) { if ( key === "value" ) { this.options.value = value; this._refreshValue(); if ( this._value() === this.options.max ) { this._trigger( "complete" ); } } this._super( key, value ); }, _value: function() { var val = this.options.value; // normalize invalid value if ( typeof val !== "number" && val !== false ) { val = 0; } else if( val === false ) { val = NaN; } return Math.min( this.options.max, Math.max( this.min, val ) ); }, _percentage: function() { var val = this._value(); return isNaN( val ) ? 100 : 100 * val / this.options.max; }, _refreshValue: function() { var value = this.value(); var percentage = this._percentage(); this.valueDiv.toggleClass( "ui-progressbar-indeterminate", isNaN( value ) ); if ( this.oldValue !== value && ( !isNaN( this.oldValue ) || !isNaN( value ) ) ) { this.oldValue = value; this._trigger( "change" ); } this.valueDiv .toggle( isNaN( value ) || value > this.min ) .toggleClass( "ui-corner-right", value === this.options.max ) .width( percentage.toFixed(0) + "%" ); if ( isNaN( value ) ) { this.element.removeAttr( "aria-valuenow" ); } else { this.element.attr( "aria-valuenow", value ); } } }); })( jQuery );