fixed some rounding errrors in segmentsWidget.js and animated the arrow and added popcorn-port
authorhamidouk
Wed, 23 Nov 2011 15:45:41 +0100
branchpopcorn-port
changeset 313 7df805ebb75e
parent 312 228b27fd2a7c
child 314 da3eafabe9ce
fixed some rounding errrors in segmentsWidget.js and animated the arrow and added a position fix to the arrowWidget.
src/js/widgets/arrowWidget.js
src/js/widgets/segmentsWidget.js
--- a/src/js/widgets/arrowWidget.js	Wed Nov 23 15:16:48 2011 +0100
+++ b/src/js/widgets/arrowWidget.js	Wed Nov 23 15:45:41 2011 +0100
@@ -20,5 +20,11 @@
 };
 
 IriSP.ArrowWidget.prototype.segmentClickHandler = function(percents) {
- this.selector.children(".Ldt-arrowWidget").css("left", percents + "%");
+ // we need to apply a fix because the arrow has a certain length
+ // it's half the length of the arrow (27 / 2). We need to convert
+ // it in percents though.
+ var totalWidth = this.selector.width();
+ var correction = ((27 / 2) / totalWidth) * 100;
+ var corrected_percents = percents - correction;
+ this.selector.children(".Ldt-arrowWidget").animate({"left" : corrected_percents + "%"});
 }
--- a/src/js/widgets/segmentsWidget.js	Wed Nov 23 15:16:48 2011 +0100
+++ b/src/js/widgets/segmentsWidget.js	Wed Nov 23 15:45:41 2011 +0100
@@ -117,14 +117,15 @@
 };
 
 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 begin = (+ annotation.begin) / 1000;
+  var end = (+ annotation.end) / 1000;
+  this._Popcorn.currentTime(Math.floor(begin));
 
   var duration = +this._serializer.currentMedia().meta["dc:duration"] / 1000;
   var middle_time = (begin + end) / 2;
-  var percents = Math.round((middle_time / duration) * 100);
+  var percents = Math.floor((middle_time / duration) * 100);
 
+  console.log(begin, end, duration, middle_time, percents);
   this._Popcorn.trigger("IriSP.SegmentsWidget.segmentClick", percents);
 };