post-hover.js: Fix position on AJAX.

Fetch all replies when using AJAX.
This commit is contained in:
Michael Save 2012-03-17 10:59:14 +11:00
parent bf7fd32c21
commit 443c79047b

View File

@ -22,8 +22,10 @@ $(document).ready(function(){
var post = false; var post = false;
var hovering = false; var hovering = false;
var hovered_at;
$(this).hover(function(e) { $(this).hover(function(e) {
hovering = true; hovering = true;
hovered_at = {'x': e.pageX, 'y': e.pageY};
var start_hover = function(link) { var start_hover = function(link) {
if(post.is(':visible') && if(post.is(':visible') &&
@ -33,8 +35,6 @@ $(document).ready(function(){
// post is in view // post is in view
post.attr('style', 'border-style: none dashed dashed none; background: ' + post.css('border-right-color')); post.attr('style', 'border-style: none dashed dashed none; background: ' + post.css('border-right-color'));
} else { } else {
var top = e.pageY - post.height() - 15;
post.clone() post.clone()
.attr('id', 'post-hover-' + id) .attr('id', 'post-hover-' + id)
.addClass('post-hover') .addClass('post-hover')
@ -48,26 +48,28 @@ $(document).ready(function(){
}; };
post = $('div.post#reply_' + id); post = $('div.post#reply_' + id);
console.log(post);
if(post.length > 0) { if(post.length > 0) {
start_hover(this, e); start_hover(this);
} else { } else {
var link = this; var link = this;
if($.inArray($(this).attr('href'), dont_fetch_again) != -1) { var url = $(this).attr('href').replace(/#.*$/, '');
if($.inArray(url, dont_fetch_again) != -1) {
return; return;
} }
dont_fetch_again.push(url);
dont_fetch_again.push($(this).attr('href'));
$.ajax({ $.ajax({
url: $(this).attr('href'), url: url,
context: document.body, context: document.body,
success: function(data) { success: function(data) {
post = $('div.post:first') $('div.post:first').prepend($(data).find('div.post.reply').css('display', 'none').addClass('hidden'));
.prepend($(data).find('div.post#reply_' + id).css('display', 'none').addClass('hidden'))
.find('div.post#reply_' + id);
if(typeof window.enable_fa == 'function' && localStorage['forcedanon']) if(typeof window.enable_fa == 'function' && localStorage['forcedanon'])
enable_fa(); enable_fa();
if(hovering)
post = $('div.post#reply_' + id);
if(hovering && post.length > 0)
start_hover(link); start_hover(link);
} }
}); });
@ -84,9 +86,11 @@ $(document).ready(function(){
}).mousemove(function(e) { }).mousemove(function(e) {
if(!post) if(!post)
return; return;
var top = e.pageY - post.height() - 15;
var top = (e.pageY ? e.pageY : hovered_at['y']) - 10;
$('#post-hover-' + id) $('#post-hover-' + id)
.css('left', e.pageX) .css('left', (e.pageX ? e.pageX : hovered_at['x']))
.css('top', top > $(window).scrollTop() ? top : $(window).scrollTop()); .css('top', top > $(window).scrollTop() ? top : $(window).scrollTop());
}); });
}); });