Skip to content

Commit

Permalink
ticket mozilla#141 offsetTop/Left not working in a table
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottDowne committed Nov 19, 2010
1 parent e136ebd commit 6f181fa
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions popcorn.js
Expand Up @@ -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
////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 6f181fa

Please sign in to comment.