src/js/widgets/arrowWidget.js
author hamidouk
Tue, 29 Nov 2011 11:09:08 +0100
branchpopcorn-port
changeset 345 8a088f7daa66
parent 337 ee1d1e4fcf45
child 535 7c25af985344
permissions -rw-r--r--
rollover over the interface buttons now works as expected. Also changed the width of the buttons to the correct size. Resized the width and height of the sprites to be the same as the boxes we display them in.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
299
d2005f747d5a added a new widget, the arrowWidget.
hamidouk
parents:
diff changeset
     1
IriSP.ArrowWidget = function(Popcorn, config, Serializer) {
d2005f747d5a added a new widget, the arrowWidget.
hamidouk
parents:
diff changeset
     2
  IriSP.Widget.call(this, Popcorn, config, Serializer);
321
21d840371c6b Arrow Positioning that Just Works (tm)
hamidouk
parents: 313
diff changeset
     3
21d840371c6b Arrow Positioning that Just Works (tm)
hamidouk
parents: 313
diff changeset
     4
  this._oldAnnotation = null;
299
d2005f747d5a added a new widget, the arrowWidget.
hamidouk
parents:
diff changeset
     5
  
d2005f747d5a added a new widget, the arrowWidget.
hamidouk
parents:
diff changeset
     6
};
d2005f747d5a added a new widget, the arrowWidget.
hamidouk
parents:
diff changeset
     7
d2005f747d5a added a new widget, the arrowWidget.
hamidouk
parents:
diff changeset
     8
d2005f747d5a added a new widget, the arrowWidget.
hamidouk
parents:
diff changeset
     9
IriSP.ArrowWidget.prototype = new IriSP.Widget();
d2005f747d5a added a new widget, the arrowWidget.
hamidouk
parents:
diff changeset
    10
d2005f747d5a added a new widget, the arrowWidget.
hamidouk
parents:
diff changeset
    11
IriSP.ArrowWidget.prototype.clear = function() {
d2005f747d5a added a new widget, the arrowWidget.
hamidouk
parents:
diff changeset
    12
d2005f747d5a added a new widget, the arrowWidget.
hamidouk
parents:
diff changeset
    13
};
d2005f747d5a added a new widget, the arrowWidget.
hamidouk
parents:
diff changeset
    14
d2005f747d5a added a new widget, the arrowWidget.
hamidouk
parents:
diff changeset
    15
IriSP.ArrowWidget.prototype.clearWidget = function() {
d2005f747d5a added a new widget, the arrowWidget.
hamidouk
parents:
diff changeset
    16
};
d2005f747d5a added a new widget, the arrowWidget.
hamidouk
parents:
diff changeset
    17
d2005f747d5a added a new widget, the arrowWidget.
hamidouk
parents:
diff changeset
    18
IriSP.ArrowWidget.prototype.draw = function() {
d2005f747d5a added a new widget, the arrowWidget.
hamidouk
parents:
diff changeset
    19
  var templ = Mustache.to_html(IriSP.arrowWidget_template, {});
d2005f747d5a added a new widget, the arrowWidget.
hamidouk
parents:
diff changeset
    20
  this.selector.append(templ);
321
21d840371c6b Arrow Positioning that Just Works (tm)
hamidouk
parents: 313
diff changeset
    21
  this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.timeUpdateHandler));
299
d2005f747d5a added a new widget, the arrowWidget.
hamidouk
parents:
diff changeset
    22
};
305
e8d05c3f77ed created an arrow widget.
hamidouk
parents: 299
diff changeset
    23
321
21d840371c6b Arrow Positioning that Just Works (tm)
hamidouk
parents: 313
diff changeset
    24
IriSP.ArrowWidget.prototype.timeUpdateHandler = function(percents) {
21d840371c6b Arrow Positioning that Just Works (tm)
hamidouk
parents: 313
diff changeset
    25
  var currentTime = this._Popcorn.currentTime();
21d840371c6b Arrow Positioning that Just Works (tm)
hamidouk
parents: 313
diff changeset
    26
  var currentAnnotation = this._serializer.currentAnnotations(currentTime)[0]; // FIXME : use the others ?
21d840371c6b Arrow Positioning that Just Works (tm)
hamidouk
parents: 313
diff changeset
    27
21d840371c6b Arrow Positioning that Just Works (tm)
hamidouk
parents: 313
diff changeset
    28
  /* move the arrow only if the current annotation changes */
21d840371c6b Arrow Positioning that Just Works (tm)
hamidouk
parents: 313
diff changeset
    29
  if (currentAnnotation != this._oldAnnotation) {
21d840371c6b Arrow Positioning that Just Works (tm)
hamidouk
parents: 313
diff changeset
    30
    var begin = (+ currentAnnotation.begin) / 1000;
21d840371c6b Arrow Positioning that Just Works (tm)
hamidouk
parents: 313
diff changeset
    31
    var end = (+ currentAnnotation.end) / 1000;
21d840371c6b Arrow Positioning that Just Works (tm)
hamidouk
parents: 313
diff changeset
    32
21d840371c6b Arrow Positioning that Just Works (tm)
hamidouk
parents: 313
diff changeset
    33
    var duration = +this._serializer.currentMedia().meta["dc:duration"] / 1000;
21d840371c6b Arrow Positioning that Just Works (tm)
hamidouk
parents: 313
diff changeset
    34
    var middle_time = (begin + end) / 2;
21d840371c6b Arrow Positioning that Just Works (tm)
hamidouk
parents: 313
diff changeset
    35
    var percents = Math.floor((middle_time / duration) * 100);
21d840371c6b Arrow Positioning that Just Works (tm)
hamidouk
parents: 313
diff changeset
    36
21d840371c6b Arrow Positioning that Just Works (tm)
hamidouk
parents: 313
diff changeset
    37
    // we need to apply a fix because the arrow has a certain length
21d840371c6b Arrow Positioning that Just Works (tm)
hamidouk
parents: 313
diff changeset
    38
    // it's half the length of the arrow (27 / 2). We need to convert
21d840371c6b Arrow Positioning that Just Works (tm)
hamidouk
parents: 313
diff changeset
    39
    // it in percents though.
21d840371c6b Arrow Positioning that Just Works (tm)
hamidouk
parents: 313
diff changeset
    40
    var totalWidth = this.selector.width();
21d840371c6b Arrow Positioning that Just Works (tm)
hamidouk
parents: 313
diff changeset
    41
    var correction = ((27 / 2) / totalWidth) * 100;
21d840371c6b Arrow Positioning that Just Works (tm)
hamidouk
parents: 313
diff changeset
    42
    var corrected_percents = percents - correction;
337
ee1d1e4fcf45 prevent the arrow from leaving the screen.
hamidouk
parents: 321
diff changeset
    43
ee1d1e4fcf45 prevent the arrow from leaving the screen.
hamidouk
parents: 321
diff changeset
    44
    /* don't move out of the screen */
ee1d1e4fcf45 prevent the arrow from leaving the screen.
hamidouk
parents: 321
diff changeset
    45
    if (corrected_percents <= 0)
ee1d1e4fcf45 prevent the arrow from leaving the screen.
hamidouk
parents: 321
diff changeset
    46
      corrected_percents = 0;
ee1d1e4fcf45 prevent the arrow from leaving the screen.
hamidouk
parents: 321
diff changeset
    47
321
21d840371c6b Arrow Positioning that Just Works (tm)
hamidouk
parents: 313
diff changeset
    48
    this.selector.children(".Ldt-arrowWidget").animate({"left" : corrected_percents + "%"});
21d840371c6b Arrow Positioning that Just Works (tm)
hamidouk
parents: 313
diff changeset
    49
21d840371c6b Arrow Positioning that Just Works (tm)
hamidouk
parents: 313
diff changeset
    50
    this._oldAnnotation = currentAnnotation;
21d840371c6b Arrow Positioning that Just Works (tm)
hamidouk
parents: 313
diff changeset
    51
  }
305
e8d05c3f77ed created an arrow widget.
hamidouk
parents: 299
diff changeset
    52
}