src/js/widgets/segmentsWidget.js
author hamidouk
Fri, 21 Oct 2011 17:25:52 +0200
branchpopcorn-port
changeset 121 607f481ef4c3
parent 108 62da43e72e30
child 126 e007a7ad66b8
permissions -rw-r--r--
some refactoring to use this.selector instead of directly using jquery.
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));
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    50
  }
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    51
};
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    52
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    53
IriSP.SegmentsWidget.prototype.clickHandler = function(annotation) {
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    54
  var begin = Math.round((+ annotation.begin) / 1000);
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    55
  this._Popcorn.currentTime(begin)
108
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents: 104
diff changeset
    56
};