-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.expectr.js
70 lines (63 loc) · 1.47 KB
/
jquery.expectr.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
var expectr = {
json : {
fn: $.getJSON,
calls: []
},
get : {
fn: $.get,
calls: []
},
post : {
fn: $.post,
calls: []
},
fnExpectr: function(url, json, delay, fnDef){
if (fnDef.calls === undefined){
fnDef.calls = [];
}
fnDef.calls[url] = {
json: json,
delay: delay
};
},
fnRouter: function(url, options, callback, fnDef){
if (fnDef.calls === undefined || fnDef.calls[url] == null){
fnDef.fn(url, options, callback);
return;
}
var _fn;
if (options != null && options instanceof Function){
_fn = options;
}
if (callback != null && callback instanceof Function){
_fn = callback;
}
if (_fn != null){
var _delay = 0;
if (fnDef.calls[url].delay != null && typeof(fnDef.calls[url].delay*1) == "number"){
_delay = fnDef.calls[url].delay*1;
}
setTimeout(function(){
_fn(fnDef.calls[url].json)
}, _delay);
}
}
};
$.expectJSON = function(url, json, delay){
expectr.fnExpectr(url, json, delay, expectr.json);
};
$.getJSON = function(url, options, callback){
expectr.fnRouter(url, options, callback, expectr.json);
};
$.expectGet = function(url, json, delay){
expectr.fnExpectr(url, json, delay, expectr.get);
};
$.get = function(url, options, callback){
expectr.fnRouter(url, options, callback, expectr.get);
};
$.expectPost = function(url, json, delay){
expectr.fnExpectr(url, json, delay, expectr.post);
};
$.post = function(url, options, callback){
expectr.fnRouter(url, options, callback, expectr.post);
};