js/post-hover.js and js/show-backlinks.js to work together
This commit is contained in:
parent
760023fd32
commit
3d00a7bdec
@ -11,49 +11,51 @@
|
||||
*
|
||||
*/
|
||||
|
||||
$(document).ready(function(){
|
||||
onready(function(){
|
||||
var dont_fetch_again = [];
|
||||
var init_hover = function() {
|
||||
var link = $(this);
|
||||
init_hover = function() {
|
||||
var $link = $(this);
|
||||
|
||||
var id;
|
||||
|
||||
if(id = $(link).text().match(/^>>(\d+)$/)) {
|
||||
if(id = $link.text().match(/^>>(\d+)$/)) {
|
||||
id = id[1];
|
||||
}
|
||||
|
||||
var post = false;
|
||||
var $post = false;
|
||||
var hovering = false;
|
||||
var hovered_at;
|
||||
$(link).hover(function(e) {
|
||||
$link.hover(function(e) {
|
||||
hovering = true;
|
||||
hovered_at = {'x': e.pageX, 'y': e.pageY};
|
||||
|
||||
var start_hover = function(link) {
|
||||
if(post.is(':visible') &&
|
||||
post.offset().top + post.height() >= $(window).scrollTop() &&
|
||||
post.offset().top <= $(window).scrollTop() + $(window).height()
|
||||
var start_hover = function($link) {
|
||||
if($post.is(':visible') &&
|
||||
$post.offset().top + $post.height() >= $(window).scrollTop() &&
|
||||
$post.offset().top <= $(window).scrollTop() + $(window).height()
|
||||
) {
|
||||
// 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 {
|
||||
post.clone()
|
||||
var $newPost = $post.clone();
|
||||
$newPost.find('span.mentioned').remove();
|
||||
$newPost
|
||||
.attr('id', 'post-hover-' + id)
|
||||
.addClass('post-hover')
|
||||
.css('position', 'absolute')
|
||||
.css('border-style', 'solid')
|
||||
.css('box-shadow', '1px 1px 1px #999')
|
||||
.css('display', 'block')
|
||||
.insertAfter($(link).parent());
|
||||
$(link).trigger('mousemove');
|
||||
.insertAfter($link.parent());
|
||||
$link.trigger('mousemove');
|
||||
}
|
||||
};
|
||||
|
||||
post = $('div.post#reply_' + id);
|
||||
if(post.length > 0) {
|
||||
start_hover(this);
|
||||
$post = $('div.post#reply_' + id);
|
||||
if($post.length > 0) {
|
||||
start_hover($(this));
|
||||
} else {
|
||||
var url = link.attr('href').replace(/#.*$/, '');
|
||||
var url = $link.attr('href').replace(/#.*$/, '');
|
||||
|
||||
if($.inArray(url, dont_fetch_again) != -1) {
|
||||
return;
|
||||
@ -70,40 +72,40 @@ $(document).ready(function(){
|
||||
|
||||
});
|
||||
|
||||
post = $('div.post#reply_' + id);
|
||||
if(hovering && post.length > 0) {
|
||||
start_hover(link);
|
||||
$post = $('div.post#reply_' + id);
|
||||
if(hovering && $post.length > 0) {
|
||||
start_hover($link);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}, function() {
|
||||
hovering = false;
|
||||
if(!post)
|
||||
if(!$post)
|
||||
return;
|
||||
|
||||
post.attr('style', '');
|
||||
if(post.hasClass('hidden'))
|
||||
post.css('display', 'none');
|
||||
$post.attr('style', '');
|
||||
if($post.hasClass('hidden'))
|
||||
$post.css('display', 'none');
|
||||
$('.post-hover').remove();
|
||||
}).mousemove(function(e) {
|
||||
if(!post)
|
||||
if(!$post)
|
||||
return;
|
||||
|
||||
var hover = $('#post-hover-' + id);
|
||||
if(hover.length == 0)
|
||||
var $hover = $('#post-hover-' + id);
|
||||
if($hover.length == 0)
|
||||
return;
|
||||
|
||||
var top = (e.pageY ? e.pageY : hovered_at['y']) - 10;
|
||||
|
||||
if(e.pageY < $(window).scrollTop() + 15) {
|
||||
top = $(window).scrollTop();
|
||||
} else if(e.pageY > $(window).scrollTop() + $(window).height() - hover.height() - 15) {
|
||||
top = $(window).scrollTop() + $(window).height() - hover.height() - 15;
|
||||
} else if(e.pageY > $(window).scrollTop() + $(window).height() - $hover.height() - 15) {
|
||||
top = $(window).scrollTop() + $(window).height() - $hover.height() - 15;
|
||||
}
|
||||
|
||||
|
||||
hover.css('left', (e.pageX ? e.pageX : hovered_at['x'])).css('top', top);
|
||||
$hover.css('left', (e.pageX ? e.pageX : hovered_at['x'])).css('top', top);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -7,32 +7,44 @@
|
||||
*
|
||||
* Usage:
|
||||
* $config['additional_javascript'][] = 'js/jquery.min.js';
|
||||
* // $config['additional_javascript'][] = 'js/post-hover'; (optional; must come first)
|
||||
* $config['additional_javascript'][] = 'js/show-backlinks.js';
|
||||
*
|
||||
*/
|
||||
|
||||
$(document).ready(function(){
|
||||
$('div.post.reply').each(function() {
|
||||
onready(function(){
|
||||
var showBackLinks = function() {
|
||||
var reply_id = $(this).attr('id').replace(/^reply_/, '');
|
||||
|
||||
$(this).find('p.body a:not([rel="nofollow"])').each(function() {
|
||||
var id, post, mentioned;
|
||||
var id, post, $mentioned;
|
||||
|
||||
if(id = $(this).text().match(/^>>(\d+)$/))
|
||||
id = id[1];
|
||||
else
|
||||
return;
|
||||
|
||||
post = $('#reply_' + id);
|
||||
if(post.length == 0)
|
||||
$post = $('#reply_' + id);
|
||||
if($post.length == 0)
|
||||
return;
|
||||
|
||||
mentioned = post.find('p.intro span.mentioned');
|
||||
if(mentioned.length == 0)
|
||||
mentioned = $('<span class="mentioned"></span>').appendTo(post.find('p.intro'));
|
||||
|
||||
mentioned.append('<a onclick="highlightReply(\'' + reply_id + '\');" href="#' + reply_id + '">>>' + reply_id + '</a>');
|
||||
$mentioned = $post.find('p.intro span.mentioned');
|
||||
if($mentioned.length == 0)
|
||||
$mentioned = $('<span class="mentioned"></span>').appendTo($post.find('p.intro'));
|
||||
|
||||
if ($mentioned.find('a.mentioned-' + reply_id).length != 0)
|
||||
return;
|
||||
|
||||
var $link = $('<a class="mentioned-' + reply_id + '" onclick="highlightReply(\'' + reply_id + '\');" href="#' + reply_id + '">>>' +
|
||||
reply_id + '</a>');
|
||||
$link.appendTo($mentioned)
|
||||
|
||||
if (window.init_hover) {
|
||||
$link.each(init_hover);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
$('div.post.reply').each(showBackLinks);
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user