1 IriSP.TraceWidget = function(Popcorn, config, Serializer) { |
|
2 IriSP.Widget.call(this, Popcorn, config, Serializer); |
|
3 this.lastEvent = ""; |
|
4 var _this = this, |
|
5 _listeners = { |
|
6 "IriSP.createAnnotationWidget.addedAnnotation" : 0, |
|
7 "IriSP.search.open" : 0, |
|
8 "IriSP.search.closed" : 0, |
|
9 "IriSP.search" : 0, |
|
10 "IriSP.search.cleared" : 0, |
|
11 "IriSP.search.matchFound" : 0, |
|
12 "IriSP.search.noMatchFound" : 0, |
|
13 "IriSP.search.triggeredSearch" : 0, |
|
14 "IriSP.TraceWidget.MouseEvents" : 0, |
|
15 "play" : 0, |
|
16 "pause" : 0, |
|
17 "volumechange" : 0, |
|
18 "seeked" : 0, |
|
19 "play" : 0, |
|
20 "pause" : 0, |
|
21 "timeupdate" : 2000 |
|
22 }; |
|
23 IriSP._(_listeners).each(function(_ms, _listener) { |
|
24 var _f = function(_arg) { |
|
25 _this.eventHandler(_listener, _arg); |
|
26 } |
|
27 if (_ms) { |
|
28 _f = IriSP.underscore.throttle(_f, _ms); |
|
29 } |
|
30 _this._Popcorn.listen(_listener, _f); |
|
31 }); |
|
32 this._Popcorn.listen("timeupdate", IriSP.underscore.throttle(function(_arg) { |
|
33 _this.eventHandler(_listener, _arg); |
|
34 })); |
|
35 |
|
36 this.tracer = IriSP.TraceManager(IriSP.jQuery).init_trace("test", this._config); |
|
37 this.tracer.set_default_subject("default_subject"); |
|
38 this.tracer.trace("StartTracing", { "hello": "world" }); |
|
39 |
|
40 } |
|
41 |
|
42 IriSP.TraceWidget.prototype = new IriSP.Widget(); |
|
43 |
|
44 IriSP.TraceWidget.prototype.draw = function() { |
|
45 this.mouseLocation = ''; |
|
46 var _this = this; |
|
47 IriSP.jQuery(".Ldt-Widget").bind("click mouseover mouseout dragstart dragstop", function(_e) { |
|
48 var _widget = IriSP.jQuery(this).attr("widget-type"), |
|
49 _class = _e.target.className; |
|
50 var _data = { |
|
51 "type": _e.type, |
|
52 "x": _e.clientX, |
|
53 "y": _e.clientY, |
|
54 "widget": _widget |
|
55 } |
|
56 if (typeof _class == "string" && _class.indexOf('Ldt-TraceMe') != -1) { |
|
57 var _name = _e.target.localName, |
|
58 _id = _e.target.id, |
|
59 _text = _e.target.textContent.trim(), |
|
60 _title = _e.target.title, |
|
61 _value = _e.target.value; |
|
62 _data.target = _name + (_id.length ? '#' + IriSP.jqEscape(_id) : '') + (_class.length ? ('.' + IriSP.jqEscape(_class).replace(/\s/g,'.')).replace(/\.Ldt-(Widget|TraceMe)/g,'') : ''); |
|
63 if (typeof _title == "string" && _title.length && _title.length < 140) { |
|
64 _data.title = _title; |
|
65 } |
|
66 if (typeof _text == "string" && _text.length && _text.length < 140) { |
|
67 _data.text = _text; |
|
68 } |
|
69 if (typeof _value == "string" && _value.length) { |
|
70 _data.value = _value; |
|
71 } |
|
72 _this._Popcorn.trigger('IriSP.TraceWidget.MouseEvents', _data); |
|
73 } else { |
|
74 //console.log(_e.type+','+_this.mouseLocation+','+_widget); |
|
75 if (_e.type == "mouseover") { |
|
76 if (_this.mouseLocation != _widget) { |
|
77 _this._Popcorn.trigger('IriSP.TraceWidget.MouseEvents', _data); |
|
78 } else { |
|
79 if (typeof _this.moTimeout != "undefined") { |
|
80 clearTimeout(_this.moTimeout); |
|
81 delete _this.moTimeout; |
|
82 } |
|
83 } |
|
84 } |
|
85 if (_e.type == "click") { |
|
86 _this._Popcorn.trigger('IriSP.TraceWidget.MouseEvents', _data); |
|
87 } |
|
88 if (_e.type == "mouseout") { |
|
89 if (typeof _this.moTimeout != "undefined") { |
|
90 clearTimeout(_this.moTimeout); |
|
91 } |
|
92 _this.moTimeout = setTimeout(function() { |
|
93 if (_data.widget != _this.mouseLocation) { |
|
94 _this._Popcorn.trigger('IriSP.TraceWidget.MouseEvents', _data); |
|
95 } |
|
96 },100); |
|
97 } |
|
98 } |
|
99 _this.mouseLocation = _widget; |
|
100 }); |
|
101 } |
|
102 |
|
103 IriSP.TraceWidget.prototype.eventHandler = function(_listener, _arg) { |
|
104 var _traceName = 'Mdp_'; |
|
105 if (typeof _arg == "string" || typeof _arg == "number") { |
|
106 _arg = { "value" : _arg } |
|
107 } |
|
108 if (typeof _arg == "undefined") { |
|
109 _arg = {} |
|
110 } |
|
111 switch(_listener) { |
|
112 case 'IriSP.TraceWidget.MouseEvents': |
|
113 _traceName += _arg.widget + '_' + _arg.type; |
|
114 delete _arg.widget; |
|
115 delete _arg.type; |
|
116 break; |
|
117 case 'timeupdate': |
|
118 case 'play': |
|
119 case 'pause': |
|
120 _arg.time = this._Popcorn.currentTime() * 1000; |
|
121 case 'seeked': |
|
122 case 'volumechange': |
|
123 _traceName += 'Popcorn_' + _listener; |
|
124 break; |
|
125 default: |
|
126 _traceName += _listener.replace('IriSP.','').replace('.','_'); |
|
127 } |
|
128 this.lastEvent = _traceName; |
|
129 this.tracer.trace(_traceName, _arg); |
|
130 if (this._config.js_console) { |
|
131 console.log("tracer.trace('" + _traceName + "', " + JSON.stringify(_arg) + ");"); |
|
132 } |
|
133 } |
|