From 6f181fada421e92342df53c6470ce89ea76b4111 Mon Sep 17 00:00:00 2001 From: ScottDowne Date: Fri, 19 Nov 2010 17:40:14 -0500 Subject: [PATCH] ticket #141 offsetTop/Left not working in a table --- popcorn.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/popcorn.js b/popcorn.js index e84295e..1ac6ed1 100644 --- a/popcorn.js +++ b/popcorn.js @@ -145,6 +145,20 @@ } }; + 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 //////////////////////////////////////////////////////////////////////////// @@ -237,15 +251,15 @@ 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() { -- 2.43.0