1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-12 10:00:49 +01:00

js/post-hover.js and js/show-backlinks.js to work together

This commit is contained in:
Michael Save 2012-04-30 02:59:11 +10:00
parent fa1d4cb642
commit 6f3cf3ee03
2 changed files with 56 additions and 42 deletions

View File

@ -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);
});
};

View File

@ -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 + '">&gt;&gt;' + 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 + '">&gt;&gt;' +
reply_id + '</a>');
$link.appendTo($mentioned)
if (window.init_hover) {
$link.each(init_hover);
}
});
});
};
$('div.post.reply').each(showBackLinks);
});