src/js/widgets/sparklineWidget.js
author hamidouk
Fri, 23 Dec 2011 12:47:17 +0100
branchpopcorn-port
changeset 523 8dfeaec4724b
child 524 a06527b99f22
permissions -rw-r--r--
first version of the sparkline widget.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
523
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
     1
/** @class The constructor for the sparkline widget */
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
     2
IriSP.SparklineWidget = function(Popcorn, config, Serializer) {
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
     3
  IriSP.Widget.call(this, Popcorn, config, Serializer);
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
     4
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
     5
  this._oldAnnotation = null;
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
     6
  
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
     7
};
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
     8
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
     9
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
    10
IriSP.SparklineWidget.prototype = new IriSP.Widget();
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
    11
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
    12
IriSP.SparklineWidget.prototype.clear = function() {
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
    13
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
    14
};
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
    15
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
    16
IriSP.SparklineWidget.prototype.draw = function() {
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
    17
  var templ = Mustache.to_html(IriSP.SparklineWidget_template, {});
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
    18
  /** this widget uses three divs -
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
    19
    the first is the sparkline, which is generated by jquery sparkline,
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
    20
    the second is an overlay div to display the progression in the video,
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
    21
    and the third is a div to react to clicks
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
    22
  */
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
    23
  this.selector.append(templ);
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
    24
  this.selector.find(".Ldt-sparkLine").sparkline([1, 34, 56, 45, 34, 67, 78, 84], {width: "640px", height: "60px"});
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
    25
  this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.timeUpdateHandler));
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
    26
};
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
    27
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
    28
/** react to a timeupdate event */
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
    29
IriSP.SparklineWidget.prototype.timeUpdateHandler = function() {
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
    30
  var currentTime = this._Popcorn.currentTime();  
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
    31
  var duration = +this._serializer.currentMedia().meta["dc:duration"] / 1000;
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
    32
  var proportion = ((currentTime / duration) * 100).toFixed(3);
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
    33
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
    34
  IriSP.jQuery(".Ldt-sparkLinePositionMarker").css("width", proportion + "%");                                    
8dfeaec4724b first version of the sparkline widget.
hamidouk
parents:
diff changeset
    35
}