-
Notifications
You must be signed in to change notification settings - Fork 2
/
activity.js
111 lines (98 loc) · 3.44 KB
/
activity.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
define([
"dojo/_base/lang",
"dojo/_base/window",
"dojo/has",
"dojo/topic",
"dojox/mobile/ProgressIndicator"
], function(lang, win, has, topic, ProgressIndicator) {
var a = {
defaultMessage : "Loading",
useNative : true,
iosOptions : {
"bounceAnimation" : false,
"textColor" : "#FFFFFF",
"fullScreen" : false,
"duration" : 0,
"minDuration" : 2
},
containerId : "",
topics : {
start : "activity/start",
stop : "activity/stop"
},
_busy : false,
//------------------------------------------------------------------------
init : function( /*Map*/config ) {
// summary:
// Initializer.
// config: Map
// Map of config settings
// {
// defaultMessage : "Loading...",
// useNative : true,
// iosOptions : {
// "bounceAnimation" : false,
// "textColor" : "#FFFFFF",
// "fullScreen" : false,
// "duration" : 0,
// "minDuration" : 2
// },
// containerId : "someNodeId"
// }
// tags:
// public
lang.mixin(a, config);
if( !has("worklight-hybrid") ) {
a.useNative = false;
}
},
//--------------------------------------------------------------------
start : function( args ) {
var opts = has("worklight-ios") ? lang.clone( a.iosOptions ) : {};
opts.text = lang.isString(args) ? args : (args.text || args.message || a.defaultMessage);
if( a._busy ) {
a.stop();
}
if( a.useNative ) {
//-- WL is WAAAY picky about what arguments it gets
["bounceAnimation", "textColor", "fullScreen", "duration", "minDuration"].forEach( function(o){
if( typeof args[o] !== "undefined"){
opts[o] = args[o];
}
});
var target = args.target || a.containerId;
a._busy = new WL.BusyIndicator( target, opts);
a._busy.show();
}else{
a._busy = ProgressIndicator.getInstance();
win.body().appendChild( a._busy.domNode );
a._busy.start();
}
},
//--------------------------------------------------------------------
stop : function(){
// Stop
if(a._busy ){
if( a.useNative ){
a._busy.hide();
}else{
a._busy.stop();
}
a._busy = null;
}
},
/////////////////// PRIVATE METHODS //////////////////
//------------------------------------------------------------------------
_init : function(){
// summary:
// Initializer.
// tags:
// private
topic.subscribe( a.topics.start, a.start );
topic.subscribe( a.topics.stop , a.stop );
a.init({});
}
};
a._init();
return a;
});