updated the segmentsWidget to throw a message whenever it's clicked to indicate popcorn-port
authorhamidouk
Wed, 23 Nov 2011 11:13:21 +0100
branchpopcorn-port
changeset 304 a938013fc6ea
parent 303 cb091d204ba9
child 305 e8d05c3f77ed
updated the segmentsWidget to throw a message whenever it's clicked to indicate where the arrowWidget should position itself.
src/js/widgets/segmentsWidget.js
unittests/tests/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) {
--- 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
+};