1 | define([ |
---|
2 | "dojo/_base/config", |
---|
3 | "dojo/_base/declare", |
---|
4 | "dojo/dom-construct", |
---|
5 | "dojo/dom-style", |
---|
6 | "dojo/has" |
---|
7 | ], function(config, declare, domConstruct, domStyle, has){ |
---|
8 | |
---|
9 | // module: |
---|
10 | // dojox/mobile/ProgressIndicator |
---|
11 | // summary: |
---|
12 | // A progress indication widget. |
---|
13 | |
---|
14 | var cls = declare("dojox.mobile.ProgressIndicator", null, { |
---|
15 | // summary: |
---|
16 | // A progress indication widget. |
---|
17 | // description: |
---|
18 | // ProgressIndicator is a round spinning graphical representation |
---|
19 | // that indicates the current task is on-going. |
---|
20 | |
---|
21 | // interval: Number |
---|
22 | // The time interval in milliseconds for updating the spinning |
---|
23 | // indicator. |
---|
24 | interval: 100, |
---|
25 | |
---|
26 | // colors: Array |
---|
27 | // An array of indicator colors. |
---|
28 | colors: [ |
---|
29 | "#C0C0C0", "#C0C0C0", "#C0C0C0", "#C0C0C0", |
---|
30 | "#C0C0C0", "#C0C0C0", "#B8B9B8", "#AEAFAE", |
---|
31 | "#A4A5A4", "#9A9A9A", "#8E8E8E", "#838383" |
---|
32 | ], |
---|
33 | |
---|
34 | constructor: function(){ |
---|
35 | this._bars = []; |
---|
36 | this.domNode = domConstruct.create("DIV"); |
---|
37 | this.domNode.className = "mblProgContainer"; |
---|
38 | if(config["mblAndroidWorkaround"] !== false && has('android') >= 2.2 && has('android') < 3){ |
---|
39 | // workaround to avoid the side effects of the fixes for android screen flicker problem |
---|
40 | domStyle.set(this.domNode, "webkitTransform", "translate3d(0,0,0)"); |
---|
41 | } |
---|
42 | this.spinnerNode = domConstruct.create("DIV", null, this.domNode); |
---|
43 | for(var i = 0; i < this.colors.length; i++){ |
---|
44 | var div = domConstruct.create("DIV", {className:"mblProg mblProg"+i}, this.spinnerNode); |
---|
45 | this._bars.push(div); |
---|
46 | } |
---|
47 | }, |
---|
48 | |
---|
49 | start: function(){ |
---|
50 | // summary: |
---|
51 | // Starts the ProgressIndicator spinning. |
---|
52 | if(this.imageNode){ |
---|
53 | var img = this.imageNode; |
---|
54 | var l = Math.round((this.domNode.offsetWidth - img.offsetWidth) / 2); |
---|
55 | var t = Math.round((this.domNode.offsetHeight - img.offsetHeight) / 2); |
---|
56 | img.style.margin = t+"px "+l+"px"; |
---|
57 | return; |
---|
58 | } |
---|
59 | var cntr = 0; |
---|
60 | var _this = this; |
---|
61 | var n = this.colors.length; |
---|
62 | this.timer = setInterval(function(){ |
---|
63 | cntr--; |
---|
64 | cntr = cntr < 0 ? n - 1 : cntr; |
---|
65 | var c = _this.colors; |
---|
66 | for(var i = 0; i < n; i++){ |
---|
67 | var idx = (cntr + i) % n; |
---|
68 | _this._bars[i].style.backgroundColor = c[idx]; |
---|
69 | } |
---|
70 | }, this.interval); |
---|
71 | }, |
---|
72 | |
---|
73 | stop: function(){ |
---|
74 | // summary: |
---|
75 | // Stops the ProgressIndicator spinning. |
---|
76 | if(this.timer){ |
---|
77 | clearInterval(this.timer); |
---|
78 | } |
---|
79 | this.timer = null; |
---|
80 | if(this.domNode.parentNode){ |
---|
81 | this.domNode.parentNode.removeChild(this.domNode); |
---|
82 | } |
---|
83 | }, |
---|
84 | |
---|
85 | setImage: function(/*String*/file){ |
---|
86 | // summary: |
---|
87 | // Sets an indicator icon image file (typically animated GIF). |
---|
88 | // If null is specified, restores the default spinner. |
---|
89 | if(file){ |
---|
90 | this.imageNode = domConstruct.create("IMG", {src:file}, this.domNode); |
---|
91 | this.spinnerNode.style.display = "none"; |
---|
92 | }else{ |
---|
93 | if(this.imageNode){ |
---|
94 | this.domNode.removeChild(this.imageNode); |
---|
95 | this.imageNode = null; |
---|
96 | } |
---|
97 | this.spinnerNode.style.display = ""; |
---|
98 | } |
---|
99 | } |
---|
100 | }); |
---|
101 | |
---|
102 | cls._instance = null; |
---|
103 | cls.getInstance = function(){ |
---|
104 | if(!cls._instance){ |
---|
105 | cls._instance = new cls(); |
---|
106 | } |
---|
107 | return cls._instance; |
---|
108 | }; |
---|
109 | |
---|
110 | return cls; |
---|
111 | }); |
---|