mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 13:51:18 +08:00
Support for scrolling to another post in the iframe; more complicated than you'd think!
This commit is contained in:
@ -11,6 +11,26 @@
|
||||
iframe.scrolling = "no";
|
||||
comments.appendChild(iframe);
|
||||
|
||||
// Thanks http://amendsoft-javascript.blogspot.ca/2010/04/find-x-and-y-coordinate-of-html-control.html
|
||||
function findPosY(obj)
|
||||
{
|
||||
var top = 0;
|
||||
if(obj.offsetParent)
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
top += obj.offsetTop;
|
||||
if(!obj.offsetParent)
|
||||
break;
|
||||
obj = obj.offsetParent;
|
||||
}
|
||||
}
|
||||
else if(obj.y)
|
||||
{
|
||||
top += obj.y;
|
||||
}
|
||||
return top;
|
||||
}
|
||||
|
||||
function postMessageReceived(e) {
|
||||
if (!e) { return; }
|
||||
@ -20,6 +40,12 @@
|
||||
if (e.data.type === 'discourse-resize' && e.data.height) {
|
||||
iframe.height = e.data.height + "px";
|
||||
}
|
||||
|
||||
if (e.data.type === 'discourse-scroll' && e.data.top) {
|
||||
// find iframe offset
|
||||
var destY = findPosY(iframe) + e.data.top;
|
||||
window.scrollTo(0, destY);
|
||||
}
|
||||
}
|
||||
}
|
||||
window.addEventListener('message', postMessageReceived, false);
|
||||
|
Reference in New Issue
Block a user