<%= link_to post.created_at.strftime("%e %b %Y"), post.url, class: 'post-date', target: "_blank" %>
<%- if post.reply_to_post.present? %>
- <%= link_to I18n.t('embed.in_reply_to', username: post.reply_to_post.username), post.reply_to_post.url, class: 'in-reply-to', target: "_blank" %>
+ <%= link_to I18n.t('embed.in_reply_to', username: post.reply_to_post.username), post.reply_to_post.url, 'data-link-to-post' => post.reply_to_post.id.to_s, :class => 'in-reply-to' %>
<%- end %>
@@ -26,7 +26,11 @@
<%= raw post.cooked %>
<%- if post.reply_count > 0 %>
- <%= link_to I18n.t('embed.replies', count: post.reply_count), post.url, class: 'post-replies', target: "_blank" %>
+ <%- if post.reply_count == 1 %>
+ <%= link_to I18n.t('embed.replies', count: post.reply_count), post.url, 'data-link-to-post' => post.replies.first.id.to_s, :class => 'post-replies' %>
+ <% else %>
+ <%= link_to I18n.t('embed.replies', count: post.reply_count), post.url, class: 'post-replies', target: "_blank" %>
+ <%- end %>
<%- end %>
diff --git a/app/views/layouts/embed.html.erb b/app/views/layouts/embed.html.erb
index f663df07cc4..5968b85f0c3 100644
--- a/app/views/layouts/embed.html.erb
+++ b/app/views/layouts/embed.html.erb
@@ -5,12 +5,38 @@
diff --git a/public/javascripts/embed.js b/public/javascripts/embed.js
index 9adbcd5bf09..5349d6d63d6 100644
--- a/public/javascripts/embed.js
+++ b/public/javascripts/embed.js
@@ -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);