Debian Codegraph @

dojox/mobile/ProgressIndicator.js

raw symbols SCIP
1 define([
2 "dojo/_base/config",
3 "dojo/_base/declare",
4 "dojo/_base/lang",
5 "dojo/dom-class",
6 "dojo/dom-construct",
7 "dojo/dom-geometry",
8 "dojo/dom-style",
9 "dojo/has",
10 "dijit/_Contained",
11 "dijit/_WidgetBase",
12 "./_css3",
13 "dojo/has!dojo-bidi?dojox/mobile/bidi/ProgressIndicator"
14 ], function(config, declare, lang, domClass, domConstruct, domGeometry, domStyle, has, Contained, WidgetBase, css3, BidiProgressIndicator){
15
16 // module:
17 // dojox/mobile/ProgressIndicator
18
19 var cls = declare("dojox.mobile.ProgressIndicator", [WidgetBase, Contained], {
20 // summary:
21 // A progress indication widget.
22 // description:
23 // ProgressIndicator is a round spinning graphical representation
24 // that indicates the current task is ongoing.
25
26 // interval: Number
27 // The time interval in milliseconds for updating the spinning
28 // indicator.
29 interval: 100,
30
31 // size: [const] Number
32 // The size of the indicator in pixels.
33 // Note that changing the value of the property after the widget
34 // creation has no effect.
35 size: 40,
36
37 // removeOnStop: Boolean
38 // If true, this widget is removed from the parent node
39 // when stop() is called.
40 removeOnStop: true,
41
42 // startSpinning: Boolean
43 // If true, calls start() to run the indicator at startup.
44 startSpinning: false,
45
46 // center: Boolean
47 // If true, the indicator is displayed as center aligned.
48 center: true,
49
50 // colors: String[]
51 // An array of indicator colors. 12 colors have to be given.
52 // If colors are not specified, CSS styles
53 // (mblProg0Color - mblProg11Color) are used.
54 colors: null,
55
56 /* internal properties */
57
58 // baseClass: String
59 // The name of the CSS class of this widget.
60 baseClass: "mblProgressIndicator",
61
62 constructor: function(){
63 // summary:
64 // Creates a new instance of the class.
65 this.colors = [];
66 this._bars = [];
67 },
68
69 buildRendering: function(){
70 this.inherited(arguments);
71 if(this.center){
72 domClass.add(this.domNode, "mblProgressIndicatorCenter");
73 }
74 this.containerNode = domConstruct.create("div", {className:"mblProgContainer"}, this.domNode);
75 this.spinnerNode = domConstruct.create("div", null, this.containerNode);
76 for(var i = 0; i < 12; i++){
77 var div = domConstruct.create("div", {className:"mblProg mblProg"+i}, this.spinnerNode);
78 this._bars.push(div);
79 }
80 this.scale(this.size);
81 if(this.startSpinning){
82 this.start();
83 }
84 },
85
86 scale: function(/*Number*/size){
87 // summary:
88 // Changes the size of the indicator.
89 // size:
90 // The size of the indicator in pixels.
91 var scale = size / 40;
92 domStyle.set(this.containerNode, css3.add({}, {
93 transform: "scale(" + scale + ")",
94 transformOrigin: "0 0"
95 }));
96 domGeometry.setMarginBox(this.domNode, {w:size, h:size});
97 domGeometry.setMarginBox(this.containerNode, {w:size / scale, h:size / scale});
98 },
99
100 start: function(){
101 // summary:
102 // Starts the spinning of the ProgressIndicator.
103 if(this.imageNode){
104 var img = this.imageNode;
105 var l = Math.round((this.containerNode.offsetWidth - img.offsetWidth) / 2);
106 var t = Math.round((this.containerNode.offsetHeight - img.offsetHeight) / 2);
107 img.style.margin = t+"px "+l+"px";
108 return;
109 }
110 var cntr = 0;
111 var _this = this;
112 var n = 12;
113 this.timer = setInterval(function(){
114 cntr--;
115 cntr = cntr < 0 ? n - 1 : cntr;
116 var c = _this.colors;
117 for(var i = 0; i < n; i++){
118 var idx = (cntr + i) % n;
119 if(c[idx]){
120 _this._bars[i].style.backgroundColor = c[idx];
121 }else{
122 domClass.replace(_this._bars[i],
123 "mblProg" + idx + "Color",
124 "mblProg" + (idx === n - 1 ? 0 : idx + 1) + "Color");
125 }
126 }
127 }, this.interval);
128 },
129
130 stop: function(){
131 // summary:
132 // Stops the spinning of the ProgressIndicator.
133 if(this.timer){
134 clearInterval(this.timer);
135 }
136 this.timer = null;
137 if(this.removeOnStop && this.domNode && this.domNode.parentNode){
138 this.domNode.parentNode.removeChild(this.domNode);
139 }
140 },
141
142 setImage: function(/*String*/file){
143 // summary:
144 // Sets an indicator icon image file (typically animated GIF).
145 // If null is specified, restores the default spinner.
146 if(file){
147 this.imageNode = domConstruct.create("img", {src:file}, this.containerNode);
148 this.spinnerNode.style.display = "none";
149 }else{
150 if(this.imageNode){
151 this.containerNode.removeChild(this.imageNode);
152 this.imageNode = null;
153 }
154 this.spinnerNode.style.display = "";
155 }
156 },
157
158 destroy: function(){
159 this.inherited(arguments);
160 if(this === cls._instance){
161 cls._instance = null;
162 }
163 }
164 });
165 cls = has("dojo-bidi") ? declare("dojox.mobile.ProgressIndicator", [cls, BidiProgressIndicator]) : cls;
166 cls._instance = null;
167 cls.getInstance = function(props){
168 if(!cls._instance){
169 cls._instance = new cls(props);
170 }
171 return cls._instance;
172 };
173
174 return cls;
175 });