]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
ticket #141 offsetTop/Left not working in a table
authorScottDowne <sdowne@learn.senecac.on.ca>
Fri, 19 Nov 2010 22:40:14 +0000 (17:40 -0500)
committerScottDowne <sdowne@learn.senecac.on.ca>
Fri, 19 Nov 2010 22:40:14 +0000 (17:40 -0500)
popcorn.js

index e84295e5dbbf80623b3ebdf6d9b72602f63e9445..1ac6ed155f4a9f232e7e08c54fe35aefc4219cb4 100644 (file)
     }
   };
 
+  var offset = function(elem) {
+    if(!elem) elem = this;
+
+    var x = elem.offsetLeft;
+    var y = elem.offsetTop;
+
+    while (elem = elem.offsetParent) {
+      x += elem.offsetLeft;
+      y += elem.offsetTop;
+    }
+
+    return { left: x, top: y };
+  }
+
   ////////////////////////////////////////////////////////////////////////////
   // Command objects
   ////////////////////////////////////////////////////////////////////////////
           google.language.translate(this.text, '', document.getElementById(this.params.languagesrc).options[i].value, function(result) {
             that.target.innerHTML = result.translation;
             that.target.style.display = "inline";
-            popcorn.SubtitleCommand.subDiv.style.top = videoManager.videoElement.offsetTop + videoManager.videoElement.offsetHeight - 64 + "px";
-            popcorn.SubtitleCommand.subDiv.style.left = videoManager.videoElement.offsetLeft + ((videoManager.videoElement.offsetWidth / 2) - (popcorn.SubtitleCommand.subDiv.offsetWidth / 2)) + "px";
+            popcorn.SubtitleCommand.subDiv.style.top = offset(videoManager.videoElement).top + videoManager.videoElement.offsetHeight - 64 + "px";
+            popcorn.SubtitleCommand.subDiv.style.left = offset(videoManager.videoElement).left + ((videoManager.videoElement.offsetWidth / 2) - (popcorn.SubtitleCommand.subDiv.offsetWidth / 2)) + "px";
           });
         }
       } else {
         this.target.innerHTML = this.text;
         this.target.style.display = "inline";
-        popcorn.SubtitleCommand.subDiv.style.top = videoManager.videoElement.offsetTop + videoManager.videoElement.offsetHeight - 64 + "px";
-        popcorn.SubtitleCommand.subDiv.style.left = videoManager.videoElement.offsetLeft + ((videoManager.videoElement.offsetWidth / 2) - (popcorn.SubtitleCommand.subDiv.offsetWidth / 2)) + "px";
+        popcorn.SubtitleCommand.subDiv.style.top = offset(videoManager.videoElement).top + videoManager.videoElement.offsetHeight - 64 + "px";
+        popcorn.SubtitleCommand.subDiv.style.left = offset(videoManager.videoElement).left + ((videoManager.videoElement.offsetWidth / 2) - (popcorn.SubtitleCommand.subDiv.offsetWidth / 2)) + "px";
       }
     };
     this.onOut = function() {