source: Dev/branches/jQueryUI/client/js/jquery/ui/jquery.ui.progressbar.js @ 249

Last change on this file since 249 was 249, checked in by hendrikvanantwerpen, 13 years ago

This one's for Subversion, because it's so close...

First widget (stripped down sequencer).
Seperated client and server code in two direcotry trees.

File size: 2.3 KB
Line 
1/*
2 * jQuery UI Progressbar 1.8.17
3 *
4 * Copyright 2011, 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                max: 100
20        },
21
22        min: 0,
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.options.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.oldValue = this._value();
38                this._refreshValue();
39        },
40
41        destroy: function() {
42                this.element
43                        .removeClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
44                        .removeAttr( "role" )
45                        .removeAttr( "aria-valuemin" )
46                        .removeAttr( "aria-valuemax" )
47                        .removeAttr( "aria-valuenow" );
48
49                this.valueDiv.remove();
50
51                $.Widget.prototype.destroy.apply( this, arguments );
52        },
53
54        value: function( newValue ) {
55                if ( newValue === undefined ) {
56                        return this._value();
57                }
58
59                this._setOption( "value", newValue );
60                return this;
61        },
62
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                        }
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.options.max, Math.max( this.min, val ) );
82        },
83
84        _percentage: function() {
85                return 100 * this._value() / this.options.max;
86        },
87
88        _refreshValue: function() {
89                var value = this.value();
90                var percentage = this._percentage();
91
92                if ( this.oldValue !== value ) {
93                        this.oldValue = value;
94                        this._trigger( "change" );
95                }
96
97                this.valueDiv
98                        .toggle( value > this.min )
99                        .toggleClass( "ui-corner-right", value === this.options.max )
100                        .width( percentage.toFixed(0) + "%" );
101                this.element.attr( "aria-valuenow", value );
102        }
103});
104
105$.extend( $.ui.progressbar, {
106        version: "1.8.17"
107});
108
109})( jQuery );
Note: See TracBrowser for help on using the repository browser.