src/js/widgets/segmentsWidget.js
author hamidouk
Mon, 14 Nov 2011 17:19:26 +0100
branchrequire-js
changeset 238 6008172a0592
parent 229 808768eb5930
permissions -rw-r--r--
converted all the source files to use the require.js syntax.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
     1
define(["IriSP", "widgets", "util", "tooltipWidget"], function() {
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
     2
  IriSP.SegmentsWidget = function(Popcorn, config, Serializer) {
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
     3
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
     4
    var self = this;
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
     5
    IriSP.Widget.call(this, Popcorn, config, Serializer);
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
     6
    this.oldSearchMatches = [];
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
     7
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
     8
    // event handlers
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
     9
    this._Popcorn.listen("IriSP.search", function(searchString) { self.searchHandler.call(self, searchString); });
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    10
    this._Popcorn.listen("IriSP.search.closed", function() { self.searchFieldClosedHandler.call(self); });
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    11
    this._Popcorn.listen("IriSP.search.cleared", function() { self.searchFieldClearedHandler.call(self); });
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    12
  };
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    13
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    14
  IriSP.SegmentsWidget.prototype = new IriSP.Widget();
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    15
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    16
  IriSP.SegmentsWidget.prototype.draw = function() {
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    17
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    18
    var self = this;
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    19
    var annotations = this._serializer._data.annotations;
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    20
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    21
    this.selector.css("overflow", "auto"); // clear the floats - FIXME : to refactor ?
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    22
    this.selector.append(Mustache.to_html(IriSP.overlay_marker_template));
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    23
    
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    24
    this.positionMarker = this.selector.children(":first");
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    25
    
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    26
    this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.positionUpdater));
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    27
    
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    28
    this.selector.after("<div class='cleaner'></div>"); // we need to do this because the segments are floated                                                      
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    29
    
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    30
    var i = 0;
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    31
    var totalWidth = this.selector.width();
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    32
    var onePxPercent = 100 / totalWidth; /* the value of a pixel, in percents */
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    33
    
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    34
    for (i = 0; i < annotations.length; i++) {
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    35
      var annotation = annotations[i];
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    36
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    37
      var begin = Math.round((+ annotation.begin) / 1000);
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    38
      var end = Math.round((+ annotation.end) / 1000);
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    39
      var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000;
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    40
      var id = annotation.id;
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    41
      var startPourcent 	= IriSP.timeToPourcent(begin, duration);
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    42
      
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    43
      /* some sort of collapsing occurs, so we only have to substract one pixel to each box instead of
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    44
         two
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    45
      */
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    46
      var endPourcent 	= IriSP.timeToPourcent(end, duration) - startPourcent - onePxPercent * 1;
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    47
      
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    48
      /* on the other hand, we have to substract one pixel from the first box because it's the only
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    49
         one to have to effective 1px margins */
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    50
      if (i == 0) {
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    51
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    52
        endPourcent -= onePxPercent;
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    53
      }
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    54
      
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    55
      var divTitle = annotation.content.title.substr(0,55);
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    56
      var color = annotation.content.color
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    57
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    58
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    59
      var annotationTemplate = Mustache.to_html(IriSP.annotation_template,
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    60
          {"divTitle" : divTitle, "id" : id, "startPourcent" : startPourcent,
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    61
          "endPourcent" : endPourcent, "hexa_color" : IriSP.DEC_HEXA_COLOR(color),
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    62
          "seekPlace" : Math.round(begin/1000)});
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    63
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    64
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    65
      var toolTipTemplate = Mustache.to_html(IriSP.tooltip_template,
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    66
            {"title" : divTitle, "begin" : begin, "end" : end,
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    67
            "description": annotation.content.description});
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    68
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    69
      this.selector.append(annotationTemplate);
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    70
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    71
      IriSP.jQuery("#" + id).tooltip({ effect: 'slide'});
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    72
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    73
      IriSP.jQuery("#" + id).fadeTo(0, 0.3);
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    74
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    75
      IriSP.jQuery("#" + id).mouseover(function() {
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    76
        IriSP.jQuery("#" + id).animate({opacity: 0.6}, 5);
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    77
      }).mouseout(function(){
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    78
        IriSP.jQuery("#" + id).animate({opacity: 0.3}, 5);
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    79
      });
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    80
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    81
      IriSP.jQuery("#" + id).click(function(_this, annotation) {
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    82
                                      return function() { _this.clickHandler(annotation)};
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    83
                                   }(this, annotation));
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    84
    }
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    85
  };
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    86
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    87
  /* restores the view after a search */
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    88
  IriSP.SegmentsWidget.prototype.clear = function() {
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    89
    // reinit the fields
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    90
    for (var id in this.oldSearchMatches) {
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    91
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    92
        IriSP.jQuery("#"+id).dequeue();
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    93
        IriSP.jQuery("#"+id).animate({height:0}, 100);
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    94
        IriSP.jQuery("#"+id).css('border-color','lightgray');
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    95
        IriSP.jQuery("#"+id).animate({opacity:0.3}, 100);
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    96
    }
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    97
  };
154
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
    98
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
    99
  IriSP.SegmentsWidget.prototype.clickHandler = function(annotation) {
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   100
    var begin = Math.round((+ annotation.begin) / 1000);
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   101
    this._Popcorn.currentTime(begin);
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   102
  };
148
5e877acd85ca added a function to handle search messages.
hamidouk
parents: 139
diff changeset
   103
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   104
  IriSP.SegmentsWidget.prototype.searchHandler = function(searchString) {
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   105
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   106
    if (searchString == "")
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   107
      return;
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
   108
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   109
    var matches = this._serializer.searchOccurences(searchString);
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
   110
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   111
    for (var id in matches) {
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   112
      var factor = matches[id] * 8;
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   113
      this.selector.find("#"+id).dequeue();
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   114
      this.selector.find("#"+id).animate({height: factor}, 200);    
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   115
      this.selector.find("#"+id).css('border-color','red');
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   116
      this.selector.find("#"+id).animate({opacity:0.6}, 200);
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   117
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   118
      IriSP.jQuery("#LdtSearchInput").css('background-color','#e1ffe1');
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   119
    }
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
   120
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   121
    // clean up the blocks that were in the previous search
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   122
    // but who aren't in the current one.
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   123
    for (var id in this.oldSearchMatches) {
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   124
      if (!matches.hasOwnProperty(id)) {
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   125
          IriSP.jQuery("#"+id).dequeue();
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   126
          IriSP.jQuery("#"+id).animate({height:0}, 250);				
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   127
          IriSP.jQuery("#"+id).animate({opacity:0.3}, 200);
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   128
          this.selector.find("#"+id).css('border','solid 1px #aaaaaa');
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   129
      }
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   130
    }
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   131
    
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   132
    this.oldSearchMatches = matches;
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   133
  };
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   134
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   135
  IriSP.SegmentsWidget.prototype.searchFieldClearedHandler = function() {
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   136
    this.clear();
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   137
  };
154
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
   138
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   139
  IriSP.SegmentsWidget.prototype.searchFieldClosedHandler = function() {
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   140
    this.clear();
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   141
  };
214
50c4609e50f4 WIP - added a div that should move over the widget.
hamidouk
parents: 212
diff changeset
   142
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   143
  IriSP.SegmentsWidget.prototype.positionUpdater = function() {  
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   144
    var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000;
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   145
    var time = this._Popcorn.currentTime();
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   146
    var position 	= ((time / duration) * 100).toFixed(2);
217
ec3e6d34462c fixed css positioning bug.
hamidouk
parents: 214
diff changeset
   147
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   148
    this.positionMarker.css("left", position + "%");  
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   149
  };
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 229
diff changeset
   150
});