src/js/widgets/segmentsWidget.js
author hamidouk
Wed, 26 Oct 2011 15:19:40 +0200
branchpopcorn-port
changeset 152 5950ab2855a8
parent 148 5e877acd85ca
child 154 6e115a094858
permissions -rw-r--r--
added a comment.
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) {
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
     2
  
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
     3
  var self = this;
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
     4
  IriSP.Widget.call(this, Popcorn, config, Serializer);
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
     5
  this.oldSearchMatches = [];
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
     6
  
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
     7
  // event handlers
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
     8
  this._Popcorn.listen("IriSP.search", function(searchString) { self.searchHandler.call(self, searchString); });
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
     9
  this._Popcorn.listen("IriSP.search.closed", function() { self.searchFieldClosedHandler.call(self); });
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    10
};
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    11
139
ba2b3c15bd47 fixing prototype bug.
hamidouk
parents: 132
diff changeset
    12
IriSP.SegmentsWidget.prototype = new IriSP.Widget();
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    13
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    14
IriSP.SegmentsWidget.prototype.draw = function() {
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    15
148
5e877acd85ca added a function to handle search messages.
hamidouk
parents: 139
diff changeset
    16
  var self = this;
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    17
  var annotations = this._serializer._data.annotations;
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    18
  
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    19
  var i = 0;
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    20
	for (i = 0; i < annotations.length; i++) {    
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    21
    var annotation = annotations[i];
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    22
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    23
    var begin = Math.round((+ annotation.begin) / 1000);
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    24
    var end = Math.round((+ annotation.end) / 1000);
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    25
    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
    26
    var id = annotation.id;    
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    27
    var startPourcent 	= IriSP.timeToPourcent(begin, duration);
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    28
    var endPourcent 	= IriSP.timeToPourcent(end, duration) - startPourcent;
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    29
    var divTitle		= annotation.content.title.substr(0,55);
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    30
    var color = annotation.content.color
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    31
    
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    32
    
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    33
    var annotationTemplate = Mustache.to_html(IriSP.annotation_template,
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    34
        {"divTitle" : divTitle, "id" : id, "startPourcent" : startPourcent,
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    35
        "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
    36
        "seekPlace" : Math.round(begin/1000)});
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    37
    
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    38
    
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    39
    var toolTipTemplate = Mustache.to_html(IriSP.tooltip_template, 
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    40
          {"title" : divTitle, "begin" : begin, "end" : end,
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    41
          "description": annotation.content.description});
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    42
    
121
607f481ef4c3 some refactoring to use this.selector instead of directly using jquery.
hamidouk
parents: 108
diff changeset
    43
    IriSP.jQuery("#Ldt-Annotations").append(annotationTemplate);    
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    44
    
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    45
    IriSP.jQuery("#" + id).tooltip({ effect: 'slide'});
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    46
    
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    47
    IriSP.jQuery("#" + id).fadeTo(0,0.3);
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    48
    
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    49
    IriSP.jQuery("#" + id).mouseover(function() {
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    50
      IriSP.jQuery("#" + id).animate({opacity: 0.6}, 5);
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    51
    }).mouseout(function(){		
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    52
      IriSP.jQuery("#" + id).animate({opacity: 0.3}, 5);
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    53
    });
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    54
    
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    55
    IriSP.jQuery("#" + id).click(function(_this, annotation) { 
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    56
                                    return function() { _this.clickHandler(annotation)};
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    57
                                 }(this, annotation));
126
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    58
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    59
    // also add an handler to move the arrow.
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    60
    // FIXME: make it work - the arrow swings wildly atm.
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    61
    var middle = IriSP.timeToPourcent(begin + (end - begin)/ 2, duration);
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    62
    var arrow_div_width = IriSP.jQuery("#Ldt-Show-Arrow").width();
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
    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
    65
    var conf = {start: begin, end: end, 
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    66
                onStart: 
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    67
                       function(middle) {                         
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    68
                        return function() { 
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    69
                          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
    70
                };
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    71
    this._Popcorn = this._Popcorn.code(conf);
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
    72
  } 
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    73
};
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    74
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    75
IriSP.SegmentsWidget.prototype.clickHandler = function(annotation) {
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    76
  var begin = Math.round((+ annotation.begin) / 1000);
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    77
  this._Popcorn.currentTime(begin)
108
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents: 104
diff changeset
    78
};
148
5e877acd85ca added a function to handle search messages.
hamidouk
parents: 139
diff changeset
    79
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
    80
IriSP.SegmentsWidget.prototype.searchHandler = function(searchString) {
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
    81
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
    82
  if (searchString == "")
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
    83
    return;
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
    84
  
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
    85
  console.log(searchString);
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
    86
  var matches = this._serializer.searchOccurences(searchString);
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
    87
  
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
    88
  for (var id in matches) {
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
    89
    var factor = matches[id] * 8;
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
    90
    IriSP.jQuery("#"+id).dequeue();
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
    91
    IriSP.jQuery("#"+id).animate({height: factor},200);
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
    92
    IriSP.jQuery("#"+id).css('border','2px');
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
    93
    IriSP.jQuery("#"+id).css('border-color','red');
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
    94
    IriSP.jQuery("#"+id).animate({opacity:0.6},200);
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
    95
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
    96
    //IriSP.jQuery("#LdtSearchInput").css('background-color','#e1ffe1');
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
    97
  }
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
    98
  
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
    99
  // clean up the blocks that were in the previous search
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   100
  // but who aren't in the current one.
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   101
  for (var id in this.oldSearchMatches) { 
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   102
    if (!matches.hasOwnProperty(id)) {
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   103
        IriSP.jQuery("#"+id).dequeue();
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   104
				IriSP.jQuery("#"+id).animate({height:0},250);
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   105
				IriSP.jQuery("#"+id).animate({opacity:0.3},200);
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   106
    }
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   107
  }
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   108
  this.oldSearchMatches = matches;
148
5e877acd85ca added a function to handle search messages.
hamidouk
parents: 139
diff changeset
   109
};
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   110
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   111
IriSP.SegmentsWidget.prototype.searchFieldClosedHandler = function() {
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   112
  // reinit the fields
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   113
  for (var id in this.oldSearchMatches) {     
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   114
      
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   115
      IriSP.jQuery("#"+id).dequeue();
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   116
			IriSP.jQuery("#"+id).animate({height:0},100);	
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   117
			IriSP.jQuery("#"+id).css('border','0px');
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   118
			IriSP.jQuery("#"+id).css('border-color','red');
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   119
			IriSP.jQuery("#"+id).animate({opacity:0.3},100);
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   120
  }
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   121
  
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   122
  
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   123
};