src/js/widgets/traceWidget.js
branchpopcorn-port
changeset 835 a8af9da7c622
parent 830 18ca612e9ff0
child 841 8da49ff273e0
equal deleted inserted replaced
834:573c7ca752e0 835:a8af9da7c622
     1 IriSP.TraceWidget = function(Popcorn, config, Serializer) {
     1 IriSP.TraceWidget = function(Popcorn, config, Serializer) {
     2   IriSP.Widget.call(this, Popcorn, config, Serializer);
     2   IriSP.Widget.call(this, Popcorn, config, Serializer);
     3   this.lastEvent = "";
     3   this.lastEvent = "";
     4   var _this = this,
     4   var _this = this,
     5     _listeners = [
     5     _listeners = {
     6         "IriSP.ArrowWidget.releaseArrow",
     6         "IriSP.createAnnotationWidget.addedAnnotation" : 0,
     7         "IriSP.SliceWidget.hide",
     7         "IriSP.search.open" : 0,
     8         "IriSP.AnnotationsWidget.show",
     8         "IriSP.search.closed" : 0,
     9         "IriSP.AnnotationsWidget.hide",
     9         "IriSP.search" : 0,
    10         "IriSP.ArrowWidget.blockArrow",
    10         "IriSP.search.cleared" : 0,
    11         "IriSP.SliceWidget.position",
    11         "IriSP.search.matchFound" : 0,
    12         "IriSP.SliceWidget.show",
    12         "IriSP.search.noMatchFound" : 0,
    13         "IriSP.SliceWidget.hide",
    13         "IriSP.search.triggeredSearch" : 0,
    14         "IriSP.createAnnotationWidget.addedAnnotation",
    14         "IriSP.TraceWidget.MouseEvents" : 0,
    15         "IriSP.search.open",
    15         "play" : 0,
    16         "IriSP.search.closed",
    16         "pause" : 0,
    17         "IriSP.search",
    17         "volumechange" : 0,
    18         "IriSP.search.cleared",
    18         "seeked" : 0,
    19         "IriSP.search.matchFound",
    19         "play" : 0,
    20         "IriSP.search.noMatchFound",
    20         "pause" : 0,
    21         "IriSP.search.triggeredSearch",
    21         "timeupdate" : 2000
    22         "IriSP.TraceWidget.MouseEvents",
    22     };
    23         "play",
    23     IriSP._(_listeners).each(function(_ms, _listener) {
    24         "pause",
    24         var _f = function(_arg) {
    25         "volumechange",
    25             _this.eventHandler(_listener, _arg);
    26         "timeupdate",
    26         }
    27         "seeked",
    27         if (_ms) {
    28         "play",
    28             _f = IriSP.underscore.throttle(_f, _ms);
    29         "pause"
    29         }
    30     ];
    30         _this._Popcorn.listen(_listener, _f);
    31     IriSP._(_listeners).each(function(_listener) {
       
    32       _this._Popcorn.listen(_listener, function(_arg) {
       
    33           _this.eventHandler(_listener, _arg);
       
    34       });
       
    35     });
    31     });
    36   
    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     
    37 }
    40 }
    38 
    41 
    39 IriSP.TraceWidget.prototype = new IriSP.Widget();
    42 IriSP.TraceWidget.prototype = new IriSP.Widget();
    40 
    43 
    41 IriSP.TraceWidget.prototype.draw = function() {
    44 IriSP.TraceWidget.prototype.draw = function() {
    42     this.mouseLocation = '';
    45     this.mouseLocation = '';
    43     var _this = this;
    46     var _this = this;
    44     IriSP.jQuery(".Ldt-Widget").bind("click mouseover mouseout dragstart dragstop", function(_e) {
    47     IriSP.jQuery(".Ldt-Widget").bind("click mouseover mouseout dragstart dragstop", function(_e) {
    45         var _widget = this.id.match('LdtPlayer_widget_([^_]+)')[1],
    48         var _widget = IriSP.jQuery(this).attr("widget-type"),
    46             _class = _e.target.className;
    49             _class = _e.target.className;
    47         var _data = {
    50         var _data = {
    48             "type": _e.type,
    51             "type": _e.type,
    49             "x": _e.clientX,
    52             "x": _e.clientX,
    50             "y": _e.clientY,
    53             "y": _e.clientY,
    54             var _name = _e.target.localName,
    57             var _name = _e.target.localName,
    55                 _id = _e.target.id,
    58                 _id = _e.target.id,
    56                 _text = _e.target.textContent.trim(),
    59                 _text = _e.target.textContent.trim(),
    57                 _title = _e.target.title,
    60                 _title = _e.target.title,
    58                 _value = _e.target.value;
    61                 _value = _e.target.value;
    59             _data.target = _name + (_id.length ? '#' + _id : '') + (_class.length ? '.' + _class.replace(/\s/g,'.').replace(/\.Ldt-(Widget|TraceMe)/g,'') : '');
    62             _data.target = _name + (_id.length ? '#' + IriSP.jqEscape(_id) : '') + (_class.length ? ('.' + IriSP.jqEscape(_class).replace(/\s/g,'.')).replace(/\.Ldt-(Widget|TraceMe)/g,'') : '');
    60             if (typeof _title == "string" && _title.length && _title.length < 140) {
    63             if (typeof _title == "string" && _title.length && _title.length < 140) {
    61                 _data.title = _title;
    64                 _data.title = _title;
    62             }
    65             }
    63             if (typeof _text == "string" && _text.length && _text.length < 140) {
    66             if (typeof _text == "string" && _text.length && _text.length < 140) {
    64                 _data.text = _text;
    67                 _data.text = _text;
   121         break;
   124         break;
   122         default:
   125         default:
   123             _traceName += _listener.replace('IriSP.','').replace('.','_');
   126             _traceName += _listener.replace('IriSP.','').replace('.','_');
   124     }
   127     }
   125     this.lastEvent = _traceName;
   128     this.lastEvent = _traceName;
       
   129     this.tracer.trace(_traceName, _arg);
   126     console.log("trace('" + _traceName + "', " + JSON.stringify(_arg) + ");");
   130     console.log("trace('" + _traceName + "', " + JSON.stringify(_arg) + ");");
       
   131     
   127 }
   132 }