forked from webmademovies/popcorn-js
/
popcorn.ramp.bubblewrap.js
48 lines (40 loc) · 2.33 KB
/
popcorn.ramp.bubblewrap.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
document.addEventListener("DOMContentLoaded", function () {
if (Popcorn) {
//intercept all existing plugins
var instances = new Array(Popcorn.instances);
for (var i=0; i < instances.length; i++) {
console.log(instances);
var inst = instances[i];
console.log(inst);
inst.bubbleWrap = {};
inst.bubbleWrap.createObserver = function(plugin,evt_name) {
var name = plugin.type;
var old_fn = plugin[evt_name];
if (!plugin._bubblewrap) {
plugin[evt_name] = function(a,b) {
console.log("TRIGGER - " + name + "_" + evt_name, a, b);
this.trigger(name + "_" + evt_name, [a,b]);
old_fn(a,b);
};
plugin.bubblewrap = true;
};
};
//this will wrap the base for new plugin instances added later
for (var r=0; r < Popcorn.registry.length; r++) {
Popcorn.registry[r].base.type = Popcorn.registry[r].type;
inst.bubbleWrap.createObserver(Popcorn.registry[r].base,"start");
inst.bubbleWrap.createObserver(Popcorn.registry[r].base,"end");
inst.bubbleWrap.createObserver(Popcorn.registry[r].base,"_setup");
inst.bubbleWrap.createObserver(Popcorn.registry[r].base,"_teardown");
}
//this will capture plugins already loaded
var trackEvents = inst.getTrackEvents();
for (var it=0; it < trackEvents.length; it++) {
inst.bubbleWrap.createObserver(trackEvents[it]._natives,"start");
inst.bubbleWrap.createObserver(trackEvents[it]._natives,"end");
inst.bubbleWrap.createObserver(trackEvents[it]._natives,"_setup");
inst.bubbleWrap.createObserver(trackEvents[it]._natives,"_teardown");
}
}
};
});