src/js/widgets/segmentsWidget.js
author hamidouk
Fri, 04 Nov 2011 12:27:59 +0100
branchpopcorn-port
changeset 194 f5d86e5c4a56
parent 164 d335ee5533c5
child 210 7ab4ff32a19d
permissions -rw-r--r--
some cleaning. Also added a progression indicator.
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
  //this.selector.attr("class", "Ldt-Segments");
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    20
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    21
  //this.selector.append("<div style='position: absolute; z-index: 100; text-color: blue'>bfdgdfgsdfgsdgsdfgsdg</div>")
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    22
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    23
  var i = 0;
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    24
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    25
  for (i = 0; i < annotations.length; i++) {
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    26
    var annotation = annotations[i];
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    27
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    28
    var begin = Math.round((+ annotation.begin) / 1000);
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    29
    var end = Math.round((+ annotation.end) / 1000);
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    30
    var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000;
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    31
    var id = annotation.id;
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    32
    var startPourcent 	= IriSP.timeToPourcent(begin, duration);
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    33
    var endPourcent 	= IriSP.timeToPourcent(end, duration) - startPourcent;
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    34
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    35
    var divTitle		= annotation.content.title.substr(0,55);
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    36
    var color = annotation.content.color
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    37
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    38
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    39
    var annotationTemplate = Mustache.to_html(IriSP.annotation_template,
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    40
        {"divTitle" : divTitle, "id" : id, "startPourcent" : startPourcent,
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    41
        "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
    42
        "seekPlace" : Math.round(begin/1000)});
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    43
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    44
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    45
    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
    46
          {"title" : divTitle, "begin" : begin, "end" : end,
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    47
          "description": annotation.content.description});
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    48
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    49
    this.selector.append(annotationTemplate);
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    50
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    51
    IriSP.jQuery("#" + id).tooltip({ effect: 'slide'});
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    52
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    53
    IriSP.jQuery("#" + id).fadeTo(0,0.3);
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    54
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    55
    IriSP.jQuery("#" + id).mouseover(function() {
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    56
      IriSP.jQuery("#" + id).animate({opacity: 0.6}, 5);
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    57
    }).mouseout(function(){
100
dbd302a995f5 added a new widget and the tests which come with it.
hamidouk
parents:
diff changeset
    58
      IriSP.jQuery("#" + id).animate({opacity: 0.3}, 5);
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    59
    });
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    60
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    61
    IriSP.jQuery("#" + id).click(function(_this, annotation) {
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    62
                                    return function() { _this.clickHandler(annotation)};
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    63
                                 }(this, annotation));
126
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    64
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    65
    // also add an handler to move the arrow.
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    66
    // FIXME: make it work - the arrow swings wildly atm.
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    67
    var middle = IriSP.timeToPourcent(begin + (end - begin)/ 2, duration);
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    68
    var arrow_div_width = IriSP.jQuery("#Ldt-Show-Arrow").width();
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    69
126
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    70
    var real_middle = middle - (middle * (1 - this.width/arrow_div_width));
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    71
    var conf = {start: begin, end: end,
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    72
                onStart:
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    73
                       function(middle) {
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    74
                        return function() {
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    75
                          IriSP.jQuery("#Ldt-Show-Arrow").animate({left: real_middle + '%'}, 1000); }}(middle)
126
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    76
                };
e007a7ad66b8 added some code to move the arrow (WIP).
hamidouk
parents: 121
diff changeset
    77
    this._Popcorn = this._Popcorn.code(conf);
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    78
  }
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    79
};
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    80
154
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
    81
/* restores the view after a search */
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
    82
IriSP.SegmentsWidget.prototype.clear = function() {
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
    83
  // reinit the fields
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    84
  for (var id in this.oldSearchMatches) {
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
      IriSP.jQuery("#"+id).dequeue();
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    87
			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
    88
			IriSP.jQuery("#"+id).css('border','0px');
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
    89
			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
    90
			IriSP.jQuery("#"+id).animate({opacity:0.3},100);
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
    91
  }
154
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
    92
};
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
    93
104
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    94
IriSP.SegmentsWidget.prototype.clickHandler = function(annotation) {
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    95
  var begin = Math.round((+ annotation.begin) / 1000);
d571e9020092 fixed the segments widget.
hamidouk
parents: 100
diff changeset
    96
  this._Popcorn.currentTime(begin)
108
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents: 104
diff changeset
    97
};
148
5e877acd85ca added a function to handle search messages.
hamidouk
parents: 139
diff changeset
    98
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
    99
IriSP.SegmentsWidget.prototype.searchHandler = function(searchString) {
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   100
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   101
  if (searchString == "")
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   102
    return;
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
   103
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   104
  console.log(searchString);
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   105
  var matches = this._serializer.searchOccurences(searchString);
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
   106
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   107
  for (var id in matches) {
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   108
    var factor = matches[id] * 8;
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   109
    IriSP.jQuery("#"+id).dequeue();
157
73bce42a3ed3 added a basic test for segmentsWidget.js search.
hamidouk
parents: 154
diff changeset
   110
    IriSP.jQuery("#"+id).animate({height: factor}, 200);
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   111
    IriSP.jQuery("#"+id).css('border','2px');
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   112
    IriSP.jQuery("#"+id).css('border-color','red');
157
73bce42a3ed3 added a basic test for segmentsWidget.js search.
hamidouk
parents: 154
diff changeset
   113
    IriSP.jQuery("#"+id).animate({opacity:0.6}, 200);
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   114
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   115
    //IriSP.jQuery("#LdtSearchInput").css('background-color','#e1ffe1');
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   116
  }
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
   117
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   118
  // clean up the blocks that were in the previous search
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   119
  // but who aren't in the current one.
164
d335ee5533c5 cosmetic changes.
hamidouk
parents: 157
diff changeset
   120
  for (var id in this.oldSearchMatches) {
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   121
    if (!matches.hasOwnProperty(id)) {
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   122
        IriSP.jQuery("#"+id).dequeue();
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   123
				IriSP.jQuery("#"+id).animate({height:0},250);
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   124
				IriSP.jQuery("#"+id).animate({opacity:0.3},200);
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   125
    }
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   126
  }
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   127
  this.oldSearchMatches = matches;
148
5e877acd85ca added a function to handle search messages.
hamidouk
parents: 139
diff changeset
   128
};
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   129
154
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
   130
IriSP.SegmentsWidget.prototype.searchFieldClearedHandler = function() {
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
   131
  this.clear();
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
   132
};
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
   133
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   134
IriSP.SegmentsWidget.prototype.searchFieldClosedHandler = function() {
154
6e115a094858 another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents: 152
diff changeset
   135
  this.clear();
152
5950ab2855a8 added a comment.
hamidouk
parents: 148
diff changeset
   136
};