Projet

Général

Profil

Révision 503b3f7b

Ajouté par Assos Assos il y a environ 10 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/jquery_update/replace/ui/ui/jquery.ui.progressbar.js
1
/*
2
 * jQuery UI Progressbar 1.8.11
1
/*!
2
 * jQuery UI Progressbar 1.10.2
3
 * http://jqueryui.com
3 4
 *
4
 * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
5
 * Dual licensed under the MIT or GPL Version 2 licenses.
5
 * Copyright 2013 jQuery Foundation and other contributors
6
 * Released under the MIT license.
6 7
 * http://jquery.org/license
7 8
 *
8
 * http://docs.jquery.com/UI/Progressbar
9
 * http://api.jqueryui.com/progressbar/
9 10
 *
10 11
 * Depends:
11 12
 *   jquery.ui.core.js
......
14 15
(function( $, undefined ) {
15 16

  
16 17
$.widget( "ui.progressbar", {
18
	version: "1.10.2",
17 19
	options: {
20
		max: 100,
18 21
		value: 0,
19
		max: 100
22

  
23
		change: null,
24
		complete: null
20 25
	},
21 26

  
22 27
	min: 0,
23 28

  
24 29
	_create: function() {
30
		// Constrain initial value
31
		this.oldValue = this.options.value = this._constrainedValue();
32

  
25 33
		this.element
26 34
			.addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
27 35
			.attr({
36
				// Only set static values, aria-valuenow and aria-valuemax are
37
				// set inside _refreshValue()
28 38
				role: "progressbar",
29
				"aria-valuemin": this.min,
30
				"aria-valuemax": this.options.max,
31
				"aria-valuenow": this._value()
39
				"aria-valuemin": this.min
32 40
			});
33 41

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

  
37
		this.oldValue = this._value();
38 45
		this._refreshValue();
39 46
	},
40 47

  
41
	destroy: function() {
48
	_destroy: function() {
42 49
		this.element
43 50
			.removeClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
44 51
			.removeAttr( "role" )
......
47 54
			.removeAttr( "aria-valuenow" );
48 55

  
49 56
		this.valueDiv.remove();
50

  
51
		$.Widget.prototype.destroy.apply( this, arguments );
52 57
	},
53 58

  
54 59
	value: function( newValue ) {
55 60
		if ( newValue === undefined ) {
56
			return this._value();
61
			return this.options.value;
57 62
		}
58 63

  
59
		this._setOption( "value", newValue );
60
		return this;
64
		this.options.value = this._constrainedValue( newValue );
65
		this._refreshValue();
61 66
	},
62 67

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

  
73
		this.indeterminate = newValue === false;
74

  
75
		// sanitize value
76
		if ( typeof newValue !== "number" ) {
77
			newValue = 0;
70 78
		}
71 79

  
72
		$.Widget.prototype._setOption.apply( this, arguments );
80
		return this.indeterminate ? false :
81
			Math.min( this.options.max, Math.max( this.min, newValue ) );
73 82
	},
74 83

  
75
	_value: function() {
76
		var val = this.options.value;
77
		// normalize invalid value
78
		if ( typeof val !== "number" ) {
79
			val = 0;
84
	_setOptions: function( options ) {
85
		// Ensure "value" option is set after other values (like max)
86
		var value = options.value;
87
		delete options.value;
88

  
89
		this._super( options );
90

  
91
		this.options.value = this._constrainedValue( value );
92
		this._refreshValue();
93
	},
94

  
95
	_setOption: function( key, value ) {
96
		if ( key === "max" ) {
97
			// Don't allow a max less than min
98
			value = Math.max( this.min, value );
80 99
		}
81
		return Math.min( this.options.max, Math.max( this.min, val ) );
100

  
101
		this._super( key, value );
82 102
	},
83 103

  
84 104
	_percentage: function() {
85
		return 100 * this._value() / this.options.max;
105
		return this.indeterminate ? 100 : 100 * ( this.options.value - this.min ) / ( this.options.max - this.min );
86 106
	},
87 107

  
88 108
	_refreshValue: function() {
89
		var value = this.value();
90
		var percentage = this._percentage();
109
		var value = this.options.value,
110
			percentage = this._percentage();
111

  
112
		this.valueDiv
113
			.toggle( this.indeterminate || value > this.min )
114
			.toggleClass( "ui-corner-right", value === this.options.max )
115
			.width( percentage.toFixed(0) + "%" );
116

  
117
		this.element.toggleClass( "ui-progressbar-indeterminate", this.indeterminate );
118

  
119
		if ( this.indeterminate ) {
120
			this.element.removeAttr( "aria-valuenow" );
121
			if ( !this.overlayDiv ) {
122
				this.overlayDiv = $( "<div class='ui-progressbar-overlay'></div>" ).appendTo( this.valueDiv );
123
			}
124
		} else {
125
			this.element.attr({
126
				"aria-valuemax": this.options.max,
127
				"aria-valuenow": value
128
			});
129
			if ( this.overlayDiv ) {
130
				this.overlayDiv.remove();
131
				this.overlayDiv = null;
132
			}
133
		}
91 134

  
92 135
		if ( this.oldValue !== value ) {
93 136
			this.oldValue = value;
94 137
			this._trigger( "change" );
95 138
		}
96

  
97
		this.valueDiv
98
			.toggleClass( "ui-corner-right", value === this.options.max )
99
			.width( percentage.toFixed(0) + "%" );
100
		this.element.attr( "aria-valuenow", value );
139
		if ( value === this.options.max ) {
140
			this._trigger( "complete" );
141
		}
101 142
	}
102 143
});
103 144

  
104
$.extend( $.ui.progressbar, {
105
	version: "1.8.11"
106
});
107

  
108 145
})( jQuery );

Formats disponibles : Unified diff