| 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 |
|
| 17 |
|
| 18 |
|
| 19 |
var cls = declare("dojox.mobile.ProgressIndicator", [WidgetBase, Contained], { |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
interval: 100, |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
size: 40, |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
removeOnStop: true, |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
startSpinning: false, |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
center: true, |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
colors: null, |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
baseClass: "mblProgressIndicator", |
| 61 |
|
| 62 |
constructor: function(){ |
| 63 |
|
| 64 |
|
| 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(size){ |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 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 |
|
| 102 |
|
| 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 |
|
| 132 |
|
| 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(file){ |
| 143 |
|
| 144 |
|
| 145 |
|
| 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 |
}); |