center the slider exactly under the other position markers. popcorn-port
authorhamidouk
Fri, 16 Dec 2011 14:14:59 +0100
branchpopcorn-port
changeset 471 af5b1db6fd0b
parent 470 19389e221722
child 472 1da76db24aa8
center the slider exactly under the other position markers.
src/js/widgets/sliderWidget.js
--- a/src/js/widgets/sliderWidget.js	Fri Dec 16 10:41:48 2011 +0100
+++ b/src/js/widgets/sliderWidget.js	Fri Dec 16 14:14:59 2011 +0100
@@ -52,8 +52,19 @@
 
   var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000;
   var percent = ((time / duration) * 100).toFixed(2);
+  
+  /* we do these complicated calculations to center exactly
+     the position Marker */
+  var pixels_to_percents = 100 / this.selector.width(); /* how much is a pixel in percents */
+  var positionMarker_width = this.positionMarker.width();
+  var correction = (pixels_to_percents * positionMarker_width) / 2;
+
+  var newPos = percent - correction;
+  if (newPos <= 0)
+    newPos = 0;
+  
 	this.sliderForeground.css("width", percent + "%");
-	this.positionMarker.css("left", percent + "%");
+	this.positionMarker.css("left", newPos + "%");
 
 };