Project

General

Profile

1
/*
2
 * jQuery UI Progressbar 1.8.6
3
 *
4
 * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about)
5
 * Dual licensed under the MIT or GPL Version 2 licenses.
6
 * http://jquery.org/license
7
 *
8
 * http://docs.jquery.com/UI/Progressbar
9
 *
10
 * Depends:
11
 *   jquery.ui.core.js
12
 *   jquery.ui.widget.js
13
 */
14
(function( $, undefined ) {
15

    
16
$.widget( "ui.progressbar", {
17
	options: {
18
		value: 0
19
	},
20

    
21
	min: 0,
22
	max: 100,
23

    
24
	_create: function() {
25
		this.element
26
			.addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
27
			.attr({
28
				role: "progressbar",
29
				"aria-valuemin": this.min,
30
				"aria-valuemax": this.max,
31
				"aria-valuenow": this._value()
32
			});
33

    
34
		this.valueDiv = $( "<div class='ui-progressbar-value ui-widget-header ui-corner-left'></div>" )
35
			.appendTo( this.element );
36

    
37
		this._refreshValue();
38
	},
39

    
40
	destroy: function() {
41
		this.element
42
			.removeClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
43
			.removeAttr( "role" )
44
			.removeAttr( "aria-valuemin" )
45
			.removeAttr( "aria-valuemax" )
46
			.removeAttr( "aria-valuenow" );
47

    
48
		this.valueDiv.remove();
49

    
50
		$.Widget.prototype.destroy.apply( this, arguments );
51
	},
52

    
53
	value: function( newValue ) {
54
		if ( newValue === undefined ) {
55
			return this._value();
56
		}
57

    
58
		this._setOption( "value", newValue );
59
		return this;
60
	},
61

    
62
	_setOption: function( key, value ) {
63
		if ( key === "value" ) {
64
			this.options.value = value;
65
			this._refreshValue();
66
			this._trigger( "change" );
67
			if ( this._value() === this.max ) {
68
				this._trigger( "complete" );
69
			}
70
		}
71

    
72
		$.Widget.prototype._setOption.apply( this, arguments );
73
	},
74

    
75
	_value: function() {
76
		var val = this.options.value;
77
		// normalize invalid value
78
		if ( typeof val !== "number" ) {
79
			val = 0;
80
		}
81
		return Math.min( this.max, Math.max( this.min, val ) );
82
	},
83

    
84
	_refreshValue: function() {
85
		var value = this.value();
86
		this.valueDiv
87
			.toggleClass( "ui-corner-right", value === this.max )
88
			.width( value + "%" );
89
		this.element.attr( "aria-valuenow", value );
90
	}
91
});
92

    
93
$.extend( $.ui.progressbar, {
94
	version: "1.8.6"
95
});
96

    
97
})( jQuery );
(26-26/32)