forked from ibm-js/dworklight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactivity.js
106 lines (94 loc) · 2.48 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
define([
"module",
"dojo/_base/array",
"dojo/_base/lang",
"dojo/_base/window",
"dojo/has",
"dojo/topic",
"dojox/mobile/ProgressIndicator",
], function(array, lang, win, has, topic, ProgressIndicator) {
var MODULE = module.id;
var a = {};
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,
//--------------------------------------------------------------------
start : function( args ) {
var F = MODULE+":start:";
//console.log(F,"Input args:", args);
if ( a._busy ) {
a.stop();
}
if( a.useNative ) {
var opts;
if ( has("worklight-ios") ) {
opts = lang.clone( a.iosOptions );
if (lang.isString(args) ) {
opts.text = args;
} else {
//-- WL is WAAAY picky about what arguments it gets
opts.text = args.text || args.message || a.defaultMessage;
array.forEach(["bounceAnimation", "textColor", "fullScreen", "duration", "minDuration"], function(o) {
if ( typeof args[o] !== "undefined") {
opts[o] = args[o];
}
});
}
} else {
// Anything else
opts = {
text : lang.isString(args) ? args : (args.text || args.message || "Loading")
};
}
var target = args.target || a.containerId;
//console.log(F,"WL BusyIndicator args:", target, opts);
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 );
if( WL.mock || !has("worklight-hybrid") ) {
a.useNative = false;
}
}
};
a._init();
return a;
});