src/js/widgets/segmentsWidget.js
author hamidouk
Thu, 10 Nov 2011 11:00:28 +0100
branchpopcorn-port
changeset 220 6498b89eabcd
parent 218 079b745d0438
child 222 0f86664b470d
permissions -rw-r--r--
changed the widget to use a template for the segment marker.
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) {
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
     2
152
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 = [];
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
     6
152
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); });
154
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
    10
  this._Popcorn.listen("IriSP.search.cleared", function() { self.searchFieldClearedHandler.call(self); });
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    11
};
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    12
139
ba2b3c15bd47 fixing prototype bug.
hamidouk
parents: 132
diff changeset
    13
IriSP.SegmentsWidget.prototype = new IriSP.Widget();
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    14
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    15
IriSP.SegmentsWidget.prototype.draw = function() {
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    16
148
5e877acd85ca added a function to handle search messages.
hamidouk
parents: 139
diff changeset
    17
  var self = this;
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    18
  var annotations = this._serializer._data.annotations;
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    19
218
079b745d0438 fixed float collapsing bug.
hamidouk
parents: 217
diff changeset
    20
  this.selector.css("overflow", "auto"); // clear the floats - FIXME : to refactor ?
220
6498b89eabcd changed the widget to use a template for the segment marker.
hamidouk
parents: 218
diff changeset
    21
  this.selector.append(Mustache.to_html(IriSP.segment_marker_template));
6498b89eabcd changed the widget to use a template for the segment marker.
hamidouk
parents: 218
diff changeset
    22
  
217
ec3e6d34462c fixed css positioning bug.
hamidouk
parents: 214
diff changeset
    23
  this.positionMarker = this.selector.children(":first");
ec3e6d34462c fixed css positioning bug.
hamidouk
parents: 214
diff changeset
    24
  
214
50c4609e50f4 WIP - added a div that should move over the widget.
hamidouk
parents: 212
diff changeset
    25
  this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.positionUpdater));
212
3a6e4089eef0 fixed teh segments display bug and another bug related to float positioning.
hamidouk
parents: 210
diff changeset
    26
  
3a6e4089eef0 fixed teh segments display bug and another bug related to float positioning.
hamidouk
parents: 210
diff changeset
    27
  this.selector.after("<div class='cleaner'></div>"); // we need to do this because the segments are floated                                                      
3a6e4089eef0 fixed teh segments display bug and another bug related to float positioning.
hamidouk
parents: 210
diff changeset
    28
  
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    29
  var i = 0;
212
3a6e4089eef0 fixed teh segments display bug and another bug related to float positioning.
hamidouk
parents: 210
diff changeset
    30
  var totalWidth = this.selector.width();
3a6e4089eef0 fixed teh segments display bug and another bug related to float positioning.
hamidouk
parents: 210
diff changeset
    31
  var onePxPercent = 100 / totalWidth; /* the value of a pixel, in percents */
3a6e4089eef0 fixed teh segments display bug and another bug related to float positioning.
hamidouk
parents: 210
diff changeset
    32
  
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    33
  for (i = 0; i < annotations.length; i++) {
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    34
    var annotation = annotations[i];
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    35
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    36
    var begin = Math.round((+ annotation.begin) / 1000);
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    37
    var end = Math.round((+ annotation.end) / 1000);
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    38
    var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000;
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    39
    var id = annotation.id;
212
3a6e4089eef0 fixed teh segments display bug and another bug related to float positioning.
hamidouk
parents: 210
diff changeset
    40
    var startPourcent 	= IriSP.timeToPourcent(begin, duration) + onePxPercent * annotations.length * 2;
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    41
    var endPourcent 	= IriSP.timeToPourcent(end, duration) - startPourcent;
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    42
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    43
    var divTitle		= annotation.content.title.substr(0,55);
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    44
    var color = annotation.content.color
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    45
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    46
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    47
    var annotationTemplate = Mustache.to_html(IriSP.annotation_template,
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    48
        {"divTitle" : divTitle, "id" : id, "startPourcent" : startPourcent,
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    49
        "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
    50
        "seekPlace" : Math.round(begin/1000)});
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    51
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    52
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    53
    var toolTipTemplate = Mustache.to_html(IriSP.tooltip_template,
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    54
          {"title" : divTitle, "begin" : begin, "end" : end,
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    55
          "description": annotation.content.description});
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    56
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    57
    this.selector.append(annotationTemplate);
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    58
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    59
    IriSP.jQuery("#" + id).tooltip({ effect: 'slide'});
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    60
212
3a6e4089eef0 fixed teh segments display bug and another bug related to float positioning.
hamidouk
parents: 210
diff changeset
    61
    IriSP.jQuery("#" + id).fadeTo(0, 0.3);
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    62
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    63
    IriSP.jQuery("#" + id).mouseover(function() {
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    64
      IriSP.jQuery("#" + id).animate({opacity: 0.6}, 5);
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    65
    }).mouseout(function(){
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    66
      IriSP.jQuery("#" + id).animate({opacity: 0.3}, 5);
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    67
    });
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    68
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    69
    IriSP.jQuery("#" + id).click(function(_this, annotation) {
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    70
                                    return function() { _this.clickHandler(annotation)};
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    71
                                 }(this, annotation));
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
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
154
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
    75
/* restores the view after a search */
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
    76
IriSP.SegmentsWidget.prototype.clear = function() {
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
    77
  // reinit the fields
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    78
  for (var id in this.oldSearchMatches) {
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    79
154
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
    80
      IriSP.jQuery("#"+id).dequeue();
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    81
			IriSP.jQuery("#"+id).animate({height:0},100);
154
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
    82
			IriSP.jQuery("#"+id).css('border','0px');
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
    83
			IriSP.jQuery("#"+id).css('border-color','red');
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
    84
			IriSP.jQuery("#"+id).animate({opacity:0.3},100);
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    85
  }
154
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
    86
};
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
    87
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    88
IriSP.SegmentsWidget.prototype.clickHandler = function(annotation) {
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    89
  var begin = Math.round((+ annotation.begin) / 1000);
217
ec3e6d34462c fixed css positioning bug.
hamidouk
parents: 214
diff changeset
    90
  this._Popcorn.currentTime(begin);
108
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents: 104
diff changeset
    91
};
148
5e877acd85ca added a function to handle search messages.
hamidouk
parents: 139
diff changeset
    92
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
    93
IriSP.SegmentsWidget.prototype.searchHandler = function(searchString) {
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
    94
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
    95
  if (searchString == "")
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
    96
    return;
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    97
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
    98
  console.log(searchString);
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
    99
  var matches = this._serializer.searchOccurences(searchString);
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
   100
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   101
  for (var id in matches) {
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   102
    var factor = matches[id] * 8;
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   103
    IriSP.jQuery("#"+id).dequeue();
157
73bce42a3ed3 added a basic test for segmentsWidget.js search.
hamidouk
parents: 154
diff changeset
   104
    IriSP.jQuery("#"+id).animate({height: factor}, 200);
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   105
    IriSP.jQuery("#"+id).css('border','2px');
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   106
    IriSP.jQuery("#"+id).css('border-color','red');
157
73bce42a3ed3 added a basic test for segmentsWidget.js search.
hamidouk
parents: 154
diff changeset
   107
    IriSP.jQuery("#"+id).animate({opacity:0.6}, 200);
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   108
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   109
    //IriSP.jQuery("#LdtSearchInput").css('background-color','#e1ffe1');
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   110
  }
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
   111
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   112
  // clean up the blocks that were in the previous search
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   113
  // but who aren't in the current one.
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
   114
  for (var id in this.oldSearchMatches) {
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   115
    if (!matches.hasOwnProperty(id)) {
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   116
        IriSP.jQuery("#"+id).dequeue();
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   117
				IriSP.jQuery("#"+id).animate({height:0},250);
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   118
				IriSP.jQuery("#"+id).animate({opacity:0.3},200);
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   119
    }
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   120
  }
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   121
  this.oldSearchMatches = matches;
148
5e877acd85ca added a function to handle search messages.
hamidouk
parents: 139
diff changeset
   122
};
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   123
154
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
   124
IriSP.SegmentsWidget.prototype.searchFieldClearedHandler = function() {
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
   125
  this.clear();
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
   126
};
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
   127
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   128
IriSP.SegmentsWidget.prototype.searchFieldClosedHandler = function() {
154
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
   129
  this.clear();
214
50c4609e50f4 WIP - added a div that should move over the widget.
hamidouk
parents: 212
diff changeset
   130
};
50c4609e50f4 WIP - added a div that should move over the widget.
hamidouk
parents: 212
diff changeset
   131
50c4609e50f4 WIP - added a div that should move over the widget.
hamidouk
parents: 212
diff changeset
   132
IriSP.SegmentsWidget.prototype.positionUpdater = function() {  
50c4609e50f4 WIP - added a div that should move over the widget.
hamidouk
parents: 212
diff changeset
   133
  var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000;
50c4609e50f4 WIP - added a div that should move over the widget.
hamidouk
parents: 212
diff changeset
   134
  var time = this._Popcorn.currentTime();
217
ec3e6d34462c fixed css positioning bug.
hamidouk
parents: 214
diff changeset
   135
  var position 	= ((time / duration) * 100).toFixed(2);
ec3e6d34462c fixed css positioning bug.
hamidouk
parents: 214
diff changeset
   136
ec3e6d34462c fixed css positioning bug.
hamidouk
parents: 214
diff changeset
   137
  this.positionMarker.css("left", position + "%");  
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   138
};