|
1 IriSP.Widgets.Trace = function(player, config) { |
|
2 IriSP.Widgets.Widget.call(this, player, config); |
|
3 |
|
4 } |
|
5 |
|
6 IriSP.Widgets.Trace.prototype = new IriSP.Widgets.Widget(); |
|
7 |
|
8 IriSP.Widgets.Trace.prototype.defaults = { |
|
9 js_console : false, |
|
10 url: "http://traces.advene.org:5000/", |
|
11 requestmode: 'GET', |
|
12 syncmode: "sync", |
|
13 default_subject: "IRI", |
|
14 tracer: null, |
|
15 extend: false |
|
16 } |
|
17 |
|
18 IriSP.Widgets.Trace.prototype.draw = function() { |
|
19 this.lastEvent = ""; |
|
20 if (typeof window.tracemanager === "undefined") { |
|
21 console.log("Tracemanager not found"); |
|
22 return; |
|
23 } |
|
24 var _this = this, |
|
25 _listeners = { |
|
26 "IriSP.search.open" : 0, |
|
27 "IriSP.search.closed" : 0, |
|
28 "IriSP.search" : 0, |
|
29 "IriSP.search.cleared" : 0, |
|
30 "IriSP.search.matchFound" : 0, |
|
31 "IriSP.search.noMatchFound" : 0, |
|
32 "IriSP.search.triggeredSearch" : 0, |
|
33 "IriSP.TraceWidget.MouseEvents" : 0, |
|
34 "play" : 0, |
|
35 "pause" : 0, |
|
36 "volumechange" : 0, |
|
37 "seeked" : 0, |
|
38 "play" : 0, |
|
39 "pause" : 0, |
|
40 "timeupdate" : 2000 |
|
41 }; |
|
42 IriSP._(_listeners).each(function(_ms, _listener) { |
|
43 var _f = function(_arg) { |
|
44 _this.eventHandler(_listener, _arg); |
|
45 } |
|
46 if (_ms) { |
|
47 _f = IriSP._.throttle(_f, _ms); |
|
48 } |
|
49 _this.player.popcorn.listen(_listener, _f); |
|
50 }); |
|
51 |
|
52 if (!this.tracer) { |
|
53 |
|
54 this.tracer = window.tracemanager.init_trace("test", { |
|
55 url: this.url, |
|
56 requestmode: this.requestmode, |
|
57 syncmode: this.syncmode, |
|
58 default_subject: this.default_subject |
|
59 }); |
|
60 |
|
61 } |
|
62 |
|
63 this.tracer.trace("TraceWidgetInit", {}); |
|
64 |
|
65 this.mouseLocation = ''; |
|
66 IriSP.jQuery(".Ldt-Widget").bind("click mouseover mouseout", function(_e) { |
|
67 var _target = IriSP.jQuery(_e.target); |
|
68 |
|
69 while (!_target.hasClass("Ldt-TraceMe") && !_target.hasClass("Ldt-Widget") && _target.length) { |
|
70 _target = _target.parent(); |
|
71 } |
|
72 |
|
73 var _widget = IriSP.jQuery(this).attr("widget-type"), |
|
74 _data = { |
|
75 "type": _e.type, |
|
76 "x": _e.clientX, |
|
77 "y": _e.clientY, |
|
78 "widget": _widget |
|
79 }, |
|
80 _targetEl = _target[0], |
|
81 _class = _targetEl.className, |
|
82 _name = _targetEl.localName, |
|
83 _id = _targetEl.id, |
|
84 _value = _targetEl.value, |
|
85 _traceInfo = _target.attr("trace-info"), |
|
86 _lastTarget = _name + (_id && _id.length ? '#' + IriSP.jqEscape(_id) : '') + (_class && _class.length ? ('.' + IriSP.jqEscape(_class).replace(/\s/g,'.')).replace(/\.Ldt-(Widget|TraceMe)/g,'') : ''); |
|
87 _data.target = _lastTarget |
|
88 if (typeof _traceInfo == "string" && _traceInfo.length) { |
|
89 _data.traceInfo = _traceInfo; |
|
90 _lastTarget += ( ";" + _traceInfo ); |
|
91 } |
|
92 if (typeof _value == "string" && _value.length) { |
|
93 _data.value = _value; |
|
94 } |
|
95 switch(_e.type) { |
|
96 case "mouseover": |
|
97 if (_this.lastTarget != _lastTarget) { |
|
98 _this.player.popcorn.trigger('IriSP.TraceWidget.MouseEvents', _data); |
|
99 } else { |
|
100 if (typeof _this.moTimeout != "undefined") { |
|
101 clearTimeout(_this.moTimeout); |
|
102 _this.moTimeout = undefined; |
|
103 } |
|
104 } |
|
105 break; |
|
106 case "mouseout": |
|
107 if (typeof _this.moTimeout != "undefined") { |
|
108 clearTimeout(_this.moTimeout); |
|
109 } |
|
110 _this.moTimeout = setTimeout(function() { |
|
111 if (_lastTarget != _this.lastTarget) { |
|
112 _this.player.popcorn.trigger('IriSP.TraceWidget.MouseEvents', _data); |
|
113 } |
|
114 },100); |
|
115 break; |
|
116 default: |
|
117 _this.player.popcorn.trigger('IriSP.TraceWidget.MouseEvents', _data); |
|
118 } |
|
119 _this.lastTarget = _lastTarget; |
|
120 }); |
|
121 } |
|
122 |
|
123 IriSP.Widgets.Trace.prototype.eventHandler = function(_listener, _arg) { |
|
124 var _traceName = 'Mdp_'; |
|
125 if (typeof _arg == "string" || typeof _arg == "number") { |
|
126 _arg = { "value" : _arg } |
|
127 } |
|
128 if (typeof _arg == "undefined") { |
|
129 _arg = {} |
|
130 } |
|
131 switch(_listener) { |
|
132 case 'IriSP.TraceWidget.MouseEvents': |
|
133 _traceName += _arg.widget + '_' + _arg.type; |
|
134 delete _arg.widget; |
|
135 delete _arg.type; |
|
136 break; |
|
137 case 'timeupdate': |
|
138 case 'play': |
|
139 case 'pause': |
|
140 _arg.time = this.player.popcorn.currentTime() * 1000; |
|
141 case 'seeked': |
|
142 case 'volumechange': |
|
143 _traceName += 'Popcorn_' + _listener; |
|
144 break; |
|
145 default: |
|
146 _traceName += _listener.replace('IriSP.','').replace('.','_'); |
|
147 } |
|
148 this.lastEvent = _traceName; |
|
149 if (typeof this.extend === "object" && this.extend) { |
|
150 IriSP._(_arg).extend(this.extend); |
|
151 } |
|
152 this.tracer.trace(_traceName, _arg); |
|
153 if (this.js_console && typeof window.console !== "undefined" && typeof console.log !== "undefined") { |
|
154 console.log("tracer.trace('" + _traceName + "', " + JSON.stringify(_arg) + ");"); |
|
155 } |
|
156 } |