forked from casatwy/CTJSBridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCTJSBridge.js
More file actions
45 lines (38 loc) · 1.29 KB
/
CTJSBridge.js
File metadata and controls
45 lines (38 loc) · 1.29 KB
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
window.CTCallBackList = {};
String.prototype.hashCode = function() {
var hash = 0;
if (this.length == 0) return hash;
for (var index = 0; index < this.length; index++) {
var charactor = this.charCodeAt(index);
hash = ((hash<<5)-hash)+charactor;
hash = hash & hash;
}
return hash;
};
function LoadMethod(methodName, data, callback) {
dataString = JSON.stringify(data);
identifier = (methodName+dataString).hashCode().toString();
window.CTCallBackList[identifier] = callback;
url = "casa://nativeapi?callbackIdentifier="+identifier+"&data="+dataString+"&methodName="+methodName;
window.location = url;
}
window.Callback = function(identifier, resultStatus, resultData) {
callBackDict = window.CTCallBackList[identifier];
if (callBackDict) {
isFinished = true;
if (resultStatus == "success") {
callBackDict.success(resultData);
}
if (resultStatus == "fail") {
callBackDict.fail(resultData);
}
if (resultStatus == "progress") {
isFinished = false;
callBackDict.progress(resultData);
}
if (isFinished) {
window.CTCallBackList[identifier] = NULL;
delete window.CTCallBackList[identifier];
}
}
}