Projet

Général

Profil

Paste
Télécharger (3,29 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / jquery_update / replace / ui / ui / jquery.ui.progressbar.js @ 503b3f7b

1 503b3f7b Assos Assos
/*!
2
 * jQuery UI Progressbar 1.10.2
3
 * http://jqueryui.com
4 85ad3d82 Assos Assos
 *
5 503b3f7b Assos Assos
 * Copyright 2013 jQuery Foundation and other contributors
6
 * Released under the MIT license.
7 85ad3d82 Assos Assos
 * http://jquery.org/license
8
 *
9 503b3f7b Assos Assos
 * http://api.jqueryui.com/progressbar/
10 85ad3d82 Assos Assos
 *
11
 * Depends:
12
 *   jquery.ui.core.js
13
 *   jquery.ui.widget.js
14
 */
15
(function( $, undefined ) {
16
17
$.widget( "ui.progressbar", {
18 503b3f7b Assos Assos
        version: "1.10.2",
19 85ad3d82 Assos Assos
        options: {
20 503b3f7b Assos Assos
                max: 100,
21 85ad3d82 Assos Assos
                value: 0,
22 503b3f7b Assos Assos
23
                change: null,
24
                complete: null
25 85ad3d82 Assos Assos
        },
26
27
        min: 0,
28
29
        _create: function() {
30 503b3f7b Assos Assos
                // Constrain initial value
31
                this.oldValue = this.options.value = this._constrainedValue();
32
33 85ad3d82 Assos Assos
                this.element
34
                        .addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
35
                        .attr({
36 503b3f7b Assos Assos
                                // Only set static values, aria-valuenow and aria-valuemax are
37
                                // set inside _refreshValue()
38 85ad3d82 Assos Assos
                                role: "progressbar",
39 503b3f7b Assos Assos
                                "aria-valuemin": this.min
40 85ad3d82 Assos Assos
                        });
41
42
                this.valueDiv = $( "<div class='ui-progressbar-value ui-widget-header ui-corner-left'></div>" )
43
                        .appendTo( this.element );
44
45
                this._refreshValue();
46
        },
47
48 503b3f7b Assos Assos
        _destroy: function() {
49 85ad3d82 Assos Assos
                this.element
50
                        .removeClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
51
                        .removeAttr( "role" )
52
                        .removeAttr( "aria-valuemin" )
53
                        .removeAttr( "aria-valuemax" )
54
                        .removeAttr( "aria-valuenow" );
55
56
                this.valueDiv.remove();
57
        },
58
59
        value: function( newValue ) {
60
                if ( newValue === undefined ) {
61 503b3f7b Assos Assos
                        return this.options.value;
62 85ad3d82 Assos Assos
                }
63
64 503b3f7b Assos Assos
                this.options.value = this._constrainedValue( newValue );
65
                this._refreshValue();
66 85ad3d82 Assos Assos
        },
67
68 503b3f7b Assos Assos
        _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;
78 85ad3d82 Assos Assos
                }
79
80 503b3f7b Assos Assos
                return this.indeterminate ? false :
81
                        Math.min( this.options.max, Math.max( this.min, newValue ) );
82 85ad3d82 Assos Assos
        },
83
84 503b3f7b Assos Assos
        _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 );
99 85ad3d82 Assos Assos
                }
100 503b3f7b Assos Assos
101
                this._super( key, value );
102 85ad3d82 Assos Assos
        },
103
104
        _percentage: function() {
105 503b3f7b Assos Assos
                return this.indeterminate ? 100 : 100 * ( this.options.value - this.min ) / ( this.options.max - this.min );
106 85ad3d82 Assos Assos
        },
107
108
        _refreshValue: function() {
109 503b3f7b Assos Assos
                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
                }
134 85ad3d82 Assos Assos
135
                if ( this.oldValue !== value ) {
136
                        this.oldValue = value;
137
                        this._trigger( "change" );
138
                }
139 503b3f7b Assos Assos
                if ( value === this.options.max ) {
140
                        this._trigger( "complete" );
141
                }
142 85ad3d82 Assos Assos
        }
143
});
144
145
})( jQuery );