# HG changeset patch # User hamidouk # Date 1322043201 -3600 # Node ID a938013fc6ea79ec919d85cbf9cfdbefdfec1d4b # Parent cb091d204ba908bbbc21fcb795084b785f3b78e0 updated the segmentsWidget to throw a message whenever it's clicked to indicate where the arrowWidget should position itself. diff -r cb091d204ba9 -r a938013fc6ea src/js/widgets/segmentsWidget.js --- a/src/js/widgets/segmentsWidget.js Wed Nov 23 10:40:06 2011 +0100 +++ b/src/js/widgets/segmentsWidget.js Wed Nov 23 11:13:21 2011 +0100 @@ -118,7 +118,14 @@ IriSP.SegmentsWidget.prototype.clickHandler = function(annotation) { var begin = Math.round((+ annotation.begin) / 1000); + var end = Math.round((+ annotation.end) / 1000); this._Popcorn.currentTime(begin); + + var duration = +this._serializer.currentMedia().meta["dc:duration"] / 1000; + var middle_time = (begin + end) / 2; + var percents = Math.round((middle_time / duration) * 100); + + this._Popcorn.trigger("IriSP.SegmentsWidget.segmentClick", percents); }; IriSP.SegmentsWidget.prototype.searchHandler = function(searchString) { diff -r cb091d204ba9 -r a938013fc6ea unittests/tests/widgets/segmentsWidget.js --- a/unittests/tests/widgets/segmentsWidget.js Wed Nov 23 10:40:06 2011 +0100 +++ b/unittests/tests/widgets/segmentsWidget.js Wed Nov 23 11:13:21 2011 +0100 @@ -40,15 +40,18 @@ var widget = new IriSP.SegmentsWidget(this.Popcorn, this.config, this.ser); widget.draw(); - var spy_callback = this.spy(); + var spy_timeupdate = this.spy(); + var spy_segmentClick = this.spy(); var spy_handler = sinon.spy(widget, "clickHandler"); - this.Popcorn.listen("timeupdate", spy_callback); + this.Popcorn.listen("timeupdate", spy_timeupdate); + this.Popcorn.listen("IriSP.SegmentsWidget.segmentClick", spy_segmentClick); var selector = IriSP.jQuery("#widget-div :not(first-child)"); var random = Math.round(Math.random() * selector.length) + 1; selector.eq(random).click(); - ok(spy_callback.called, "the currenttime was changed"); + ok(spy_timeupdate.called, "the timeupdate signal has been sent"); + ok(spy_segmentClick.called, "the IriSP.segmentClick signal has been sent"); ok(spy_handler.called, "handling function has been called"); }); @@ -64,4 +67,4 @@ var newStyle = IriSP.jQuery("#widget-div").children(tag_id).attr("style"); notEqual(oldStyle, newStyle, "the segment style has been modified"); }); -}; \ No newline at end of file +};