src/js/widgets/segmentsWidget.js
author hamidouk
Mon, 24 Oct 2011 17:27:13 +0200
branchpopcorn-port
changeset 132 e56122a14240
parent 126 e007a7ad66b8
child 139 ba2b3c15bd47
permissions -rw-r--r--
removed debug printf.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
     1
IriSP.SegmentsWidget = function(Popcorn, config, Serializer) {
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
     2
  IriSP.Widget.call(this, Popcorn, config, Serializer);  
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
     3
};
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
     4
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
     5
IriSP.SegmentsWidget.prototype = new IriSP.Widget;
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
     6
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
     7
IriSP.SegmentsWidget.prototype.draw = function() {
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
     8
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
     9
  var annotations = this._serializer._data.annotations;
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    10
  
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    11
  var i = 0;
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    12
	for (i = 0; i < annotations.length; i++) {    
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    13
    var annotation = annotations[i];
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    14
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    15
    var begin = Math.round((+ annotation.begin) / 1000);
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    16
    var end = Math.round((+ annotation.end) / 1000);
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    17
    var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000;
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    18
    var id = annotation.id;    
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    19
    var startPourcent 	= IriSP.timeToPourcent(begin, duration);
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    20
    var endPourcent 	= IriSP.timeToPourcent(end, duration) - startPourcent;
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    21
    var divTitle		= annotation.content.title.substr(0,55);
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    22
    var color = annotation.content.color
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    23
    
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    24
    
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    25
    var annotationTemplate = Mustache.to_html(IriSP.annotation_template,
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    26
        {"divTitle" : divTitle, "id" : id, "startPourcent" : startPourcent,
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    27
        "endPourcent" : endPourcent, "hexa_color" : IriSP.DEC_HEXA_COLOR(color),
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    28
        "seekPlace" : Math.round(begin/1000)});
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    29
    
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    30
    
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    31
    var toolTipTemplate = Mustache.to_html(IriSP.tooltip_template, 
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    32
          {"title" : divTitle, "begin" : begin, "end" : end,
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    33
          "description": annotation.content.description});
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    34
    
121
607f481ef4c3 some refactoring to use this.selector instead of directly using jquery.
hamidouk
parents: 108
diff changeset
    35
    IriSP.jQuery("#Ldt-Annotations").append(annotationTemplate);    
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    36
    
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    37
    IriSP.jQuery("#" + id).tooltip({ effect: 'slide'});
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    38
    
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    39
    IriSP.jQuery("#" + id).fadeTo(0,0.3);
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    40
    
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    41
    IriSP.jQuery("#" + id).mouseover(function() {
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    42
      IriSP.jQuery("#" + id).animate({opacity: 0.6}, 5);
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    43
    }).mouseout(function(){		
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    44
      IriSP.jQuery("#" + id).animate({opacity: 0.3}, 5);
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    45
    });
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    46
    
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    47
    IriSP.jQuery("#" + id).click(function(_this, annotation) { 
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    48
                                    return function() { _this.clickHandler(annotation)};
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    49
                                 }(this, annotation));
126
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    50
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    51
    // also add an handler to move the arrow.
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    52
    // FIXME: make it work - the arrow swings wildly atm.
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    53
    var middle = IriSP.timeToPourcent(begin + (end - begin)/ 2, duration);
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    54
    var arrow_div_width = IriSP.jQuery("#Ldt-Show-Arrow").width();
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    55
    
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    56
    var real_middle = middle - (middle * (1 - this.width/arrow_div_width));
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    57
    var conf = {start: begin, end: end, 
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    58
                onStart: 
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    59
                       function(middle) {                         
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    60
                        return function() { 
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    61
                          IriSP.jQuery("#Ldt-Show-Arrow").animate({left: real_middle + '%'}, 1000); }}(middle)                
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    62
                };
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    63
    this._Popcorn = this._Popcorn.code(conf);
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    64
  }
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    65
};
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    66
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    67
IriSP.SegmentsWidget.prototype.clickHandler = function(annotation) {
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    68
  var begin = Math.round((+ annotation.begin) / 1000);
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    69
  this._Popcorn.currentTime(begin)
108
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents: 104
diff changeset
    70
};