src/js/widgets/segmentsWidget.js
author hamidouk
Thu, 22 Dec 2011 16:10:15 +0100
branchcalage-segmentsWidget
changeset 514 f5865a99be69
parent 509 756ecd1645a5
child 515 54324c5d82ab
permissions -rw-r--r--
WIP - first version of the rounding algorithm.
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
509
756ecd1645a5 defined a func to compute the width in pixels of a segment.
hamidouk
parents: 508
diff changeset
    15
/* Get the width of a segment, in pixels. */
514
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    16
IriSP.SegmentsWidget.prototype.segmentToPixel = function(annotation) {  
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    17
  var begin = Math.round((+ annotation.begin) / 1000);
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    18
  var end = Math.round((+ annotation.end) / 1000);    
509
756ecd1645a5 defined a func to compute the width in pixels of a segment.
hamidouk
parents: 508
diff changeset
    19
  var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000;
514
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    20
  
509
756ecd1645a5 defined a func to compute the width in pixels of a segment.
hamidouk
parents: 508
diff changeset
    21
  var startPourcent 	= IriSP.timeToPourcent(begin, duration);
514
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    22
  var startPixel = Math.floor(this.selector.parent().width() * (startPourcent / 100));
509
756ecd1645a5 defined a func to compute the width in pixels of a segment.
hamidouk
parents: 508
diff changeset
    23
  
756ecd1645a5 defined a func to compute the width in pixels of a segment.
hamidouk
parents: 508
diff changeset
    24
  var endPourcent 	= Math.floor(IriSP.timeToPourcent(end, duration) - startPourcent);
756ecd1645a5 defined a func to compute the width in pixels of a segment.
hamidouk
parents: 508
diff changeset
    25
  var endPixel = Math.floor(this.selector.parent().width() * (endPourcent / 100));
514
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    26
  
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    27
  return endPixel;
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    28
};
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    29
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    30
/* compute the total length of a group of segments */
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    31
IriSP.SegmentsWidget.prototype.segmentsLength = function(segmentsList) {
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    32
  var self = this;
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    33
  var total = 0;
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    34
  
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    35
  for (var i = 0; i < segmentsList.length; i++)
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    36
    total += self.segmentToPixel(segmentsList[i].annotation);
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    37
  
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    38
  return total;  
509
756ecd1645a5 defined a func to compute the width in pixels of a segment.
hamidouk
parents: 508
diff changeset
    39
};
756ecd1645a5 defined a func to compute the width in pixels of a segment.
hamidouk
parents: 508
diff changeset
    40
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    41
IriSP.SegmentsWidget.prototype.draw = function() {
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    42
148
5e877acd85ca added a function to handle search messages.
hamidouk
parents: 139
diff changeset
    43
  var self = this;
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    44
  var annotations = this._serializer._data.annotations;
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    45
334
e20f97514d44 move the styling of a segment from the templates to the css.
hamidouk
parents: 321
diff changeset
    46
  this.selector.addClass("Ldt-SegmentsWidget");
229
808768eb5930 rewriting the slider-port to not use jquery ui slider.
hamidouk
parents: 223
diff changeset
    47
  this.selector.append(Mustache.to_html(IriSP.overlay_marker_template));
514
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    48
          
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    49
  var view_type = this._serializer.getNonTweetIds()[0];    
220
6498b89eabcd changed the widget to use a template for the segment marker.
hamidouk
parents: 218
diff changeset
    50
  
217
ec3e6d34462c fixed css positioning bug.
hamidouk
parents: 214
diff changeset
    51
  this.positionMarker = this.selector.children(":first");
ec3e6d34462c fixed css positioning bug.
hamidouk
parents: 214
diff changeset
    52
  
214
50c4609e50f4 WIP - added a div that should move over the widget.
hamidouk
parents: 212
diff changeset
    53
  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
    54
  
3a6e4089eef0 fixed teh segments display bug and another bug related to float positioning.
hamidouk
parents: 210
diff changeset
    55
  
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    56
  var i = 0;
514
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    57
  
508
00054959ee92 began working on pixel-precise segmentWidget positioning.
hamidouk
parents: 483
diff changeset
    58
  var segments_annotations = [];
00054959ee92 began working on pixel-precise segmentWidget positioning.
hamidouk
parents: 483
diff changeset
    59
  
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    60
  for (i = 0; i < annotations.length; i++) {
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    61
    var annotation = annotations[i];
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    62
300
a50aea26ec89 fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents: 229
diff changeset
    63
    /* filter the annotations whose type is not the one we want */
a50aea26ec89 fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents: 229
diff changeset
    64
    if (view_type != "" && typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined"
a50aea26ec89 fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents: 229
diff changeset
    65
          && annotation.meta["id-ref"] != view_type) {
a50aea26ec89 fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents: 229
diff changeset
    66
        continue;
a50aea26ec89 fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents: 229
diff changeset
    67
    }
a50aea26ec89 fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents: 229
diff changeset
    68
514
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    69
    segments_annotations.push({annotation: annotation, pixelValue: this.segmentToPixel(annotation)});
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    70
  }
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    71
    
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    72
  var totalWidth = this.selector.width() - segments_annotations.length;
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    73
  
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    74
  var currentWidth = IriSP.underscore.reduce(segments_annotations, function(memo, segment) { return memo + segment.pixelValue; }, 0);
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    75
  while(currentWidth > totalWidth) {
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    76
    var max = IriSP.underscore.max(segments_annotations, function(segment) { return segment.pixelValue; });
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    77
    max.pixelValue -= 1;
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    78
    currentWidth = IriSP.underscore.reduce(segments_annotations, function(memo, segment) { return memo + segment.pixelValue; }, 0);
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    79
  }
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    80
  
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    81
  console.log(currentWidth);
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    82
  for (i = 0; i < segments_annotations.length; i++) {
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    83
  
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    84
    var annotation = segments_annotations[i].annotation;
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    85
    var begin = Math.round((+ annotation.begin) / 1000);
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    86
    var end = Math.round((+ annotation.end) / 1000);
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    87
    var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000;
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    88
    var id = annotation.id;
483
0bb36c79836c fixed positioning bug.
hamidouk
parents: 479
diff changeset
    89
    var startPourcent 	= IriSP.timeToPourcent(begin, duration);
514
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    90
    var startPixel = Math.floor(this.selector.parent().width() * (startPourcent / 100));
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    91
514
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    92
    var pourcentWidth	= Math.floor(IriSP.timeToPourcent(end, duration) - startPourcent);
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    93
    //var pxWidth = Math.floor(this.selector.parent().width() * (pourcentWidth / 100));
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    94
    var pxWidth = segments_annotations[i].pixelValue;
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    95
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    96
    /* don't show annotation with an empty length */
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    97
    if (pxWidth === 0)
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    98
      continue;
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
    99
      
474
c1998d5d552e fixed a couple show-stoppers.
hamidouk
parents: 473
diff changeset
   100
    var divTitle = (annotation.content.title + " - " + annotation.content.description).substr(0,55);
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
   101
473
1a09ab7e7163 fixed display bugs in segmentsWidget
hamidouk
parents: 464
diff changeset
   102
    if (typeof(annotation.content.color) !== "undefined")
1a09ab7e7163 fixed display bugs in segmentsWidget
hamidouk
parents: 464
diff changeset
   103
      var color = annotation.content.color;
1a09ab7e7163 fixed display bugs in segmentsWidget
hamidouk
parents: 464
diff changeset
   104
    else
1a09ab7e7163 fixed display bugs in segmentsWidget
hamidouk
parents: 464
diff changeset
   105
      var color = annotation.color;
1a09ab7e7163 fixed display bugs in segmentsWidget
hamidouk
parents: 464
diff changeset
   106
    
1a09ab7e7163 fixed display bugs in segmentsWidget
hamidouk
parents: 464
diff changeset
   107
    var hexa_color = IriSP.DEC_HEXA_COLOR(color);
479
24308670f1bb fixed the display of colors.
hamidouk
parents: 477
diff changeset
   108
473
1a09ab7e7163 fixed display bugs in segmentsWidget
hamidouk
parents: 464
diff changeset
   109
    if (hexa_color === "FFCC00")
1a09ab7e7163 fixed display bugs in segmentsWidget
hamidouk
parents: 464
diff changeset
   110
      hexa_color = "333";
479
24308670f1bb fixed the display of colors.
hamidouk
parents: 477
diff changeset
   111
    if (hexa_color.length == 4)
24308670f1bb fixed the display of colors.
hamidouk
parents: 477
diff changeset
   112
      hexa_color = hexa_color + '00';
473
1a09ab7e7163 fixed display bugs in segmentsWidget
hamidouk
parents: 464
diff changeset
   113
    
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
   114
    var annotationTemplate = Mustache.to_html(IriSP.annotation_template,
514
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
   115
        {"divTitle" : divTitle, "id" : id, "startPixel" : startPixel,
f5865a99be69 WIP - first version of the rounding algorithm.
hamidouk
parents: 509
diff changeset
   116
        "pxWidth" : pxWidth, "hexa_color" : hexa_color,
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
   117
        "seekPlace" : Math.round(begin/1000)});
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
   118
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
   119
    this.selector.append(annotationTemplate);
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
   120
336
8da13562cfea segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents: 334
diff changeset
   121
//    IriSP.jQuery("#" + id).tooltip({ effect: 'slide'});
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
   122
212
3a6e4089eef0 fixed teh segments display bug and another bug related to float positioning.
hamidouk
parents: 210
diff changeset
   123
    IriSP.jQuery("#" + id).fadeTo(0, 0.3);
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
   124
336
8da13562cfea segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents: 334
diff changeset
   125
    IriSP.jQuery("#" + id).mouseover(
8da13562cfea segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents: 334
diff changeset
   126
    /* we wrap the handler in another function because js's scoping
8da13562cfea segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents: 334
diff changeset
   127
       rules are function-based - otherwise, the internal vars like
8da13562cfea segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents: 334
diff changeset
   128
       divTitle are preserved but they are looked-up from the draw
8da13562cfea segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents: 334
diff changeset
   129
       method scope, so after that the loop is run, so they're not
8da13562cfea segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents: 334
diff changeset
   130
       preserved */
8da13562cfea segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents: 334
diff changeset
   131
    (function(divTitle) { 
8da13562cfea segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents: 334
diff changeset
   132
     return function(event) {
8da13562cfea segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents: 334
diff changeset
   133
          IriSP.jQuery(this).animate({opacity: 0.6}, 5);
8da13562cfea segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents: 334
diff changeset
   134
          var offset = IriSP.jQuery(this).offset();
8da13562cfea segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents: 334
diff changeset
   135
          var correction = IriSP.jQuery(this).outerWidth() / 2;
8da13562cfea segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents: 334
diff changeset
   136
8da13562cfea segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents: 334
diff changeset
   137
          var offset_x = offset.left + correction - 106;
8da13562cfea segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents: 334
diff changeset
   138
          if (offset_x < 0)
8da13562cfea segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents: 334
diff changeset
   139
            offset_x = 0;
474
c1998d5d552e fixed a couple show-stoppers.
hamidouk
parents: 473
diff changeset
   140
                    
336
8da13562cfea segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents: 334
diff changeset
   141
          self.TooltipWidget.show(divTitle, color, offset_x, event.pageY - 160);
8da13562cfea segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents: 334
diff changeset
   142
    } })(divTitle)).mouseout(function(){
334
e20f97514d44 move the styling of a segment from the templates to the css.
hamidouk
parents: 321
diff changeset
   143
      IriSP.jQuery(this).animate({opacity: 0.3}, 5);
336
8da13562cfea segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents: 334
diff changeset
   144
      self.TooltipWidget.hide();
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
   145
    });
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
   146
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
   147
    IriSP.jQuery("#" + id).click(function(_this, annotation) {
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
   148
                                    return function() { _this.clickHandler(annotation)};
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
   149
                                 }(this, annotation));
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
   150
  }
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
   151
};
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
   152
154
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
   153
/* restores the view after a search */
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
   154
IriSP.SegmentsWidget.prototype.clear = function() {
397
eb54152c2cfa fixed search to follow samuel's directives.
hamidouk
parents: 380
diff changeset
   155
  this.selector.children(".Ldt-iri-chapter").css('border','none').animate({opacity:0.3}, 100);
154
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
   156
};
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
   157
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
   158
IriSP.SegmentsWidget.prototype.clickHandler = function(annotation) {
464
dd543fb9d38a trigger a signal when a segment is clicked.
hamidouk
parents: 418
diff changeset
   159
  this._Popcorn.trigger("IriSP.SegmentsWidget.click", annotation.id);
313
7df805ebb75e fixed some rounding errrors in segmentsWidget.js and animated the arrow and added
hamidouk
parents: 304
diff changeset
   160
  var begin = (+ annotation.begin) / 1000;
392
ef4e6b0fec17 fixed elusive bug.
hamidouk
parents: 380
diff changeset
   161
  this._Popcorn.currentTime(Math.round(begin));
108
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents: 104
diff changeset
   162
};
148
5e877acd85ca added a function to handle search messages.
hamidouk
parents: 139
diff changeset
   163
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   164
IriSP.SegmentsWidget.prototype.searchHandler = function(searchString) {
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   165
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   166
  if (searchString == "")
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   167
    return;
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
   168
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   169
  var matches = this._serializer.searchOccurences(searchString);
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
   170
355
d8df77c40676 fixed search field coloring.
hamidouk
parents: 353
diff changeset
   171
  if (IriSP.countProperties(matches) > 0) {
398
d1883378b822 renamed search signal.
hamidouk
parents: 397
diff changeset
   172
    this._Popcorn.trigger("IriSP.search.matchFound");
355
d8df77c40676 fixed search field coloring.
hamidouk
parents: 353
diff changeset
   173
  } else {
398
d1883378b822 renamed search signal.
hamidouk
parents: 397
diff changeset
   174
    this._Popcorn.trigger("IriSP.search.noMatchFound");
355
d8df77c40676 fixed search field coloring.
hamidouk
parents: 353
diff changeset
   175
  }
d8df77c40676 fixed search field coloring.
hamidouk
parents: 353
diff changeset
   176
397
eb54152c2cfa fixed search to follow samuel's directives.
hamidouk
parents: 380
diff changeset
   177
  // un-highlight all the blocks
eb54152c2cfa fixed search to follow samuel's directives.
hamidouk
parents: 380
diff changeset
   178
  this.selector.children(".Ldt-iri-chapter").css("opacity", 0.1);
eb54152c2cfa fixed search to follow samuel's directives.
hamidouk
parents: 380
diff changeset
   179
 
eb54152c2cfa fixed search to follow samuel's directives.
hamidouk
parents: 380
diff changeset
   180
  // then highlight the ones with matches.
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   181
  for (var id in matches) {
380
4b74494bd129 fixed highlighting factor. Removed printf.
hamidouk
parents: 355
diff changeset
   182
    var factor = 0.5 + matches[id] * 0.2;
223
f14172bdea28 fixed annoying search clear display bug.
hamidouk
parents: 222
diff changeset
   183
    this.selector.find("#"+id).dequeue();
353
21f3a1d501eb changed the way the segmentsWidget highlights the matching segments.
hamidouk
parents: 336
diff changeset
   184
    this.selector.find("#"+id).css('border','1px red');
21f3a1d501eb changed the way the segmentsWidget highlights the matching segments.
hamidouk
parents: 336
diff changeset
   185
    this.selector.find("#"+id).animate({opacity:factor}, 200);
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   186
  }
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
   187
397
eb54152c2cfa fixed search to follow samuel's directives.
hamidouk
parents: 380
diff changeset
   188
 
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   189
  this.oldSearchMatches = matches;
148
5e877acd85ca added a function to handle search messages.
hamidouk
parents: 139
diff changeset
   190
};
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   191
154
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
   192
IriSP.SegmentsWidget.prototype.searchFieldClearedHandler = function() {
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
   193
  this.clear();
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
   194
};
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
   195
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   196
IriSP.SegmentsWidget.prototype.searchFieldClosedHandler = function() {
154
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
   197
  this.clear();
214
50c4609e50f4 WIP - added a div that should move over the widget.
hamidouk
parents: 212
diff changeset
   198
};
50c4609e50f4 WIP - added a div that should move over the widget.
hamidouk
parents: 212
diff changeset
   199
50c4609e50f4 WIP - added a div that should move over the widget.
hamidouk
parents: 212
diff changeset
   200
IriSP.SegmentsWidget.prototype.positionUpdater = function() {  
50c4609e50f4 WIP - added a div that should move over the widget.
hamidouk
parents: 212
diff changeset
   201
  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
   202
  var time = this._Popcorn.currentTime();
483
0bb36c79836c fixed positioning bug.
hamidouk
parents: 479
diff changeset
   203
  //var position 	= ((time / duration) * 100).toFixed(2);
217
ec3e6d34462c fixed css positioning bug.
hamidouk
parents: 214
diff changeset
   204
  var position 	= ((time / duration) * 100).toFixed(2);
ec3e6d34462c fixed css positioning bug.
hamidouk
parents: 214
diff changeset
   205
ec3e6d34462c fixed css positioning bug.
hamidouk
parents: 214
diff changeset
   206
  this.positionMarker.css("left", position + "%");  
300
a50aea26ec89 fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents: 229
diff changeset
   207
};