src/js/widgets/segmentsWidget.js
author hamidouk
Wed, 26 Oct 2011 12:40:24 +0200
branchpopcorn-port
changeset 148 5e877acd85ca
parent 139 ba2b3c15bd47
child 152 5950ab2855a8
permissions -rw-r--r--
added a function to handle search messages.
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
139
ba2b3c15bd47 fixing prototype bug.
hamidouk
parents: 132
diff changeset
     5
IriSP.SegmentsWidget.prototype = new IriSP.Widget();
100
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
148
5e877acd85ca added a function to handle search messages.
hamidouk
parents: 139
diff changeset
     9
  var self = this;
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    10
  var annotations = this._serializer._data.annotations;
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    11
  
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    12
  var i = 0;
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    13
	for (i = 0; i < annotations.length; i++) {    
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    14
    var annotation = annotations[i];
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    15
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    16
    var begin = Math.round((+ annotation.begin) / 1000);
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    17
    var end = Math.round((+ annotation.end) / 1000);
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    18
    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
    19
    var id = annotation.id;    
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    20
    var startPourcent 	= IriSP.timeToPourcent(begin, duration);
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    21
    var endPourcent 	= IriSP.timeToPourcent(end, duration) - startPourcent;
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    22
    var divTitle		= annotation.content.title.substr(0,55);
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    23
    var color = annotation.content.color
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    24
    
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    25
    
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    26
    var annotationTemplate = Mustache.to_html(IriSP.annotation_template,
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    27
        {"divTitle" : divTitle, "id" : id, "startPourcent" : startPourcent,
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    28
        "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
    29
        "seekPlace" : Math.round(begin/1000)});
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    30
    
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    31
    
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    32
    var toolTipTemplate = Mustache.to_html(IriSP.tooltip_template, 
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    33
          {"title" : divTitle, "begin" : begin, "end" : end,
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    34
          "description": annotation.content.description});
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    35
    
121
607f481ef4c3 some refactoring to use this.selector instead of directly using jquery.
hamidouk
parents: 108
diff changeset
    36
    IriSP.jQuery("#Ldt-Annotations").append(annotationTemplate);    
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    37
    
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    38
    IriSP.jQuery("#" + id).tooltip({ effect: 'slide'});
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    39
    
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    40
    IriSP.jQuery("#" + id).fadeTo(0,0.3);
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    41
    
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    42
    IriSP.jQuery("#" + id).mouseover(function() {
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    43
      IriSP.jQuery("#" + id).animate({opacity: 0.6}, 5);
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    44
    }).mouseout(function(){		
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    45
      IriSP.jQuery("#" + id).animate({opacity: 0.3}, 5);
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    46
    });
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    47
    
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    48
    IriSP.jQuery("#" + id).click(function(_this, annotation) { 
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    49
                                    return function() { _this.clickHandler(annotation)};
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    50
                                 }(this, annotation));
126
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    51
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    52
    // also add an handler to move the arrow.
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    53
    // FIXME: make it work - the arrow swings wildly atm.
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    54
    var middle = IriSP.timeToPourcent(begin + (end - begin)/ 2, duration);
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    55
    var arrow_div_width = IriSP.jQuery("#Ldt-Show-Arrow").width();
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    56
    
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    57
    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
    58
    var conf = {start: begin, end: end, 
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    59
                onStart: 
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    60
                       function(middle) {                         
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    61
                        return function() { 
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    62
                          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
    63
                };
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    64
    this._Popcorn = this._Popcorn.code(conf);
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    65
  }
148
5e877acd85ca added a function to handle search messages.
hamidouk
parents: 139
diff changeset
    66
  
5e877acd85ca added a function to handle search messages.
hamidouk
parents: 139
diff changeset
    67
  this._Popcorn.listen("IriSP.search", function(searchWord) { self.searchHandler.call(self, searchWord); });
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    68
};
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    69
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    70
IriSP.SegmentsWidget.prototype.clickHandler = function(annotation) {
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    71
  var begin = Math.round((+ annotation.begin) / 1000);
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    72
  this._Popcorn.currentTime(begin)
108
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents: 104
diff changeset
    73
};
148
5e877acd85ca added a function to handle search messages.
hamidouk
parents: 139
diff changeset
    74
5e877acd85ca added a function to handle search messages.
hamidouk
parents: 139
diff changeset
    75
IriSP.SegmentsWidget.prototype.searchHandler = function(searchWord) {
5e877acd85ca added a function to handle search messages.
hamidouk
parents: 139
diff changeset
    76
  console.log("received" + searchWord);
5e877acd85ca added a function to handle search messages.
hamidouk
parents: 139
diff changeset
    77
};