-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.spy.js
38 lines (35 loc) · 974 Bytes
/
jquery.spy.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
(function (root, factory) {
if (typeof define === "function" && define.amd) {
define([], factory);
} else if (typeof module === "object" && module.exports) {
module.exports = factory();
} else {
root["mu-jquery-spy/jquery.spy"] = factory();
}
})(this, function () {
return function (selector, callback, type) {
var me = this;
var $ = me.constructor;
var cache = {};
return me
.find(selector)
.map(function (index, spy) {
var spies = callback.call(me, spy);
return spies
? {
spy: $(spy),
spies: cache[spies] || (cache[spies] = $(spies))
}
: undefined;
})
.map(function (index, op) {
var spy = op.spy;
var spies = op.spies;
return spies.length === 0
? spy.triggerHandler(type)
: $.map(spies, function (target) {
return spy.triggerHandler(type, target);
});
});
}
});