~jstys-z/helioviewer.org/timeline

« back to all changes in this revision

Viewing changes to lib/jquery/jquery.ui-1.6rc2/ui/ui.progressbar.js

  • Committer: V. Keith Hughitt
  • Date: 2009-03-26 19:20:57 UTC
  • Revision ID: hughitt1@kore-20090326192057-u0x8rf8sf5lmmnwh
nightly build 03-26-2009: Using alpha-channel JPEG 2000 dataset

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * jQuery UI ProgressBar @VERSION
3
 
 *
4
 
 * Copyright (c) 2008 Eduardo Lundgren
5
 
 * Dual licensed under the MIT (MIT-LICENSE.txt)
6
 
 * and GPL (GPL-LICENSE.txt) licenses.
7
 
 *
8
 
 * http://docs.jquery.com/UI/ProgressBar
9
 
 *
10
 
 * Depends:
11
 
 *   ui.core.js
12
 
 */
13
 
(function($) {
14
 
 
15
 
$.widget("ui.progressbar", {
16
 
        _init: function() {
17
 
 
18
 
                this._interval = this.options.interval;
19
 
 
20
 
                var self = this,
21
 
                        options = this.options,
22
 
                        id = (new Date()).getTime()+Math.random(),
23
 
                        text = options.text || '0%';
24
 
 
25
 
                this.element.addClass("ui-progressbar").width(options.width);
26
 
 
27
 
                $.extend(this, {
28
 
                        active: false,
29
 
                        pixelState: 0,
30
 
                        percentState: 0,
31
 
                        identifier: id,
32
 
                        bar: $('<div class="ui-progressbar-bar ui-hidden"></div>').css({
33
 
                                width: '0px', overflow: 'hidden', zIndex: 100
34
 
                        }),
35
 
                        textElement: $('<div class="ui-progressbar-text"></div>').html(text).css({
36
 
                                width: '0px', overflow: 'hidden'
37
 
                        }),
38
 
                        textBg: $('<div class="ui-progressbar-text ui-progressbar-text-back"></div>').html(text).css({
39
 
                                        width: this.element.width()
40
 
                        }),
41
 
                        wrapper: $('<div class="ui-progressbar-wrap"></div>')
42
 
                });
43
 
 
44
 
                this.wrapper
45
 
                        .append(this.bar.append(this.textElement.addClass(options.textClass)), this.textBg)
46
 
                        .appendTo(this.element);
47
 
        },
48
 
 
49
 
        plugins: {},
50
 
        ui: function(e) {
51
 
                return {
52
 
                        instance: this,
53
 
                        identifier: this.identifier,
54
 
                        options: this.options,
55
 
                        element: this.bar,
56
 
                        textElement: this.textElement,
57
 
                        pixelState: this.pixelState,
58
 
                        percentState: this.percentState
59
 
                };
60
 
        },
61
 
 
62
 
        _propagate: function(n,e) {
63
 
                $.ui.plugin.call(this, n, [e, this.ui()]);
64
 
                this.element.triggerHandler(n == "progressbar" ? n : ["progressbar", n].join(""), [e, this.ui()], this.options[n]);
65
 
        },
66
 
 
67
 
        destroy: function() {
68
 
                this.stop();
69
 
 
70
 
                this.element
71
 
                        .removeClass("ui-progressbar ui-progressbar-disabled")
72
 
                        .removeData("progressbar").unbind(".progressbar")
73
 
                        .find('.ui-progressbar-wrap').remove();
74
 
 
75
 
                delete jQuery.easing[this.identifier];
76
 
        },
77
 
 
78
 
        enable: function() {
79
 
                this.element.removeClass("ui-progressbar-disabled");
80
 
                this.disabled = false;
81
 
        },
82
 
 
83
 
        disable: function() {
84
 
                this.element.addClass("ui-progressbar-disabled");
85
 
                this.disabled = true;
86
 
        },
87
 
 
88
 
        start: function() {
89
 
                var self = this, options = this.options;
90
 
 
91
 
                if (this.disabled) {
92
 
                        return;
93
 
                }
94
 
 
95
 
                jQuery.easing[this.identifier] = function (x, t, b, c, d) {
96
 
                        var inc = options.increment,
97
 
                                width = options.width,
98
 
                                step = ((inc > width ? width : inc)/width),
99
 
                                state = Math.round(x/step)*step;
100
 
                        return state > 1 ? 1 : state;
101
 
                };
102
 
 
103
 
                self.active = true;
104
 
 
105
 
                setTimeout(
106
 
                        function() {
107
 
                                self.active = false;
108
 
                        },
109
 
                        options.duration
110
 
                );
111
 
 
112
 
                this._animate();
113
 
 
114
 
                this._propagate('start', this.ui());
115
 
                return false;
116
 
        },
117
 
 
118
 
        _animate: function() {
119
 
                var self = this,
120
 
                        options = this.options,
121
 
                        interval = options.interval;
122
 
 
123
 
                this.bar.animate(
124
 
                        {
125
 
                                width: options.width
126
 
                        },
127
 
                        {
128
 
                                duration: interval,
129
 
                                easing: this.identifier,
130
 
                                step: function(step, b) {
131
 
                                        self.progress((step/options.width)*100);
132
 
                                        var timestamp = new Date().getTime(), elapsedTime  = (timestamp - b.startTime);
133
 
                                        options.interval = interval - elapsedTime;
134
 
                                },
135
 
                                complete: function() {
136
 
                                        delete jQuery.easing[self.identifier];
137
 
                                        self.pause();
138
 
 
139
 
                                        if (self.active) {
140
 
                                                /*TODO*/
141
 
                                        }
142
 
                                }
143
 
                        }
144
 
                );
145
 
        },
146
 
 
147
 
        pause: function() {
148
 
                if (this.disabled) return;
149
 
                this.bar.stop();
150
 
                this._propagate('pause', this.ui());
151
 
        },
152
 
 
153
 
        stop: function() {
154
 
                this.bar.stop();
155
 
                this.bar.width(0);
156
 
                this.textElement.width(0);
157
 
                this.bar.addClass('ui-hidden');
158
 
                this.options.interval = this._interval;
159
 
                this._propagate('stop', this.ui());
160
 
        },
161
 
 
162
 
        text: function(text){
163
 
                this.textElement.html(text);
164
 
                this.textBg.html(text);
165
 
        },
166
 
 
167
 
        progress: function(percentState) {
168
 
                if (this.bar.is('.ui-hidden')) {
169
 
                        this.bar.removeClass('ui-hidden');
170
 
                }
171
 
 
172
 
                this.percentState = percentState > 100 ? 100 : percentState;
173
 
                this.pixelState = (this.percentState/100)*this.options.width;
174
 
                this.bar.width(this.pixelState);
175
 
                this.textElement.width(this.pixelState);
176
 
 
177
 
                if (this.options.range && !this.options.text) {
178
 
                        this.textElement.html(Math.round(this.percentState) + '%');
179
 
                }
180
 
                this._propagate('progress', this.ui());
181
 
        }
182
 
});
183
 
 
184
 
$.ui.progressbar.defaults = {
185
 
        width: 300,
186
 
        duration: 3000,
187
 
        interval: 200,
188
 
        increment: 1,
189
 
        range: true,
190
 
        text: '',
191
 
        addClass: '',
192
 
        textClass: ''
193
 
};
194
 
 
195
 
})(jQuery);
 
 
b'\\ No newline at end of file'