-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.js
75 lines (69 loc) · 1.92 KB
/
api.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
if (typeof qbb == "undefined"){
var qbb = {};
}
(function($) {
if(typeof qbb.inf == "undefined") {
qbb.inf = {
annotator: 'pubUser',
service_url: "https://napeasy.org/napeasy_api/api",
saveAnn: function(url, anns, searchCB){
var apiName = "saveNapEasyAnnotation";
var sendObject={
r:apiName,
annotator: qbb.inf.annotator,
url: url,
anns: anns
};
qbb.inf.callAPI(sendObject, searchCB);
},
loadAnn: function(url, searchCB){
var apiName = "loadNapEasyAnnotation";
var sendObject={
r:apiName,
annotator: qbb.inf.annotator,
url: url
};
qbb.inf.callAPI(sendObject, searchCB);
},
callAPI: function(sendObject, cb){
qbb.inf.ajax.doPost(sendObject, function(s){
var ret = s;
if (ret && ret.status == "200" && ret.data)
{
if (typeof cb == 'function')
cb(ret.data);
}else
{
if (typeof cb == 'function')
cb();
}
}, function(){
if (typeof checkOutDataCB == 'function')checkOutDataCB();
});
},
ajax: {
doGet:function(sendData,success,error){
qbb.inf.ajax.doSend("Get",null,sendData,success,error);
},
doPost:function(sendData,success,error){
qbb.inf.ajax.doSend("Post",null,sendData,success,error);
},
doSend:function(method,url,sendData,success,error){
dataSuccess = function(data){
(success)(eval(data));
};
if (sendData) sendData.token = "";
jQuery.ajax({
type: method || "Get",
url: url || qbb.inf.service_url,
data: sendData || [],
cache: false,
dataType: "json", /* use "html" for HTML, use "json" for non-HTML */
success: dataSuccess /* (data, textStatus, jqXHR) */ || null,
error: error /* (jqXHR, textStatus, errorThrown) */ || null
});
}
}
};
}
})(jQuery);