mirror of
https://github.com/vichan-devel/vichan.git
synced 2024-11-24 07:30:10 +01:00
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 dont_fetch_again = [];
|
||||||
var init_hover = function() {
|
init_hover = function() {
|
||||||
var link = $(this);
|
var $link = $(this);
|
||||||
|
|
||||||
var id;
|
var id;
|
||||||
|
|
||||||
if(id = $(link).text().match(/^>>(\d+)$/)) {
|
if(id = $link.text().match(/^>>(\d+)$/)) {
|
||||||
id = id[1];
|
id = id[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
var post = false;
|
var $post = false;
|
||||||
var hovering = false;
|
var hovering = false;
|
||||||
var hovered_at;
|
var hovered_at;
|
||||||
$(link).hover(function(e) {
|
$link.hover(function(e) {
|
||||||
hovering = true;
|
hovering = true;
|
||||||
hovered_at = {'x': e.pageX, 'y': e.pageY};
|
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') &&
|
||||||
post.offset().top + post.height() >= $(window).scrollTop() &&
|
$post.offset().top + $post.height() >= $(window).scrollTop() &&
|
||||||
post.offset().top <= $(window).scrollTop() + $(window).height()
|
$post.offset().top <= $(window).scrollTop() + $(window).height()
|
||||||
) {
|
) {
|
||||||
// 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 {
|
||||||
post.clone()
|
var $newPost = $post.clone();
|
||||||
|
$newPost.find('span.mentioned').remove();
|
||||||
|
$newPost
|
||||||
.attr('id', 'post-hover-' + id)
|
.attr('id', 'post-hover-' + id)
|
||||||
.addClass('post-hover')
|
.addClass('post-hover')
|
||||||
.css('position', 'absolute')
|
.css('position', 'absolute')
|
||||||
.css('border-style', 'solid')
|
.css('border-style', 'solid')
|
||||||
.css('box-shadow', '1px 1px 1px #999')
|
.css('box-shadow', '1px 1px 1px #999')
|
||||||
.css('display', 'block')
|
.css('display', 'block')
|
||||||
.insertAfter($(link).parent());
|
.insertAfter($link.parent());
|
||||||
$(link).trigger('mousemove');
|
$link.trigger('mousemove');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
post = $('div.post#reply_' + id);
|
$post = $('div.post#reply_' + id);
|
||||||
if(post.length > 0) {
|
if($post.length > 0) {
|
||||||
start_hover(this);
|
start_hover($(this));
|
||||||
} else {
|
} else {
|
||||||
var url = link.attr('href').replace(/#.*$/, '');
|
var url = $link.attr('href').replace(/#.*$/, '');
|
||||||
|
|
||||||
if($.inArray(url, dont_fetch_again) != -1) {
|
if($.inArray(url, dont_fetch_again) != -1) {
|
||||||
return;
|
return;
|
||||||
@ -70,40 +72,40 @@ $(document).ready(function(){
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
post = $('div.post#reply_' + id);
|
$post = $('div.post#reply_' + id);
|
||||||
if(hovering && post.length > 0) {
|
if(hovering && $post.length > 0) {
|
||||||
start_hover(link);
|
start_hover($link);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, function() {
|
}, function() {
|
||||||
hovering = false;
|
hovering = false;
|
||||||
if(!post)
|
if(!$post)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
post.attr('style', '');
|
$post.attr('style', '');
|
||||||
if(post.hasClass('hidden'))
|
if($post.hasClass('hidden'))
|
||||||
post.css('display', 'none');
|
$post.css('display', 'none');
|
||||||
$('.post-hover').remove();
|
$('.post-hover').remove();
|
||||||
}).mousemove(function(e) {
|
}).mousemove(function(e) {
|
||||||
if(!post)
|
if(!$post)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var hover = $('#post-hover-' + id);
|
var $hover = $('#post-hover-' + id);
|
||||||
if(hover.length == 0)
|
if($hover.length == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var top = (e.pageY ? e.pageY : hovered_at['y']) - 10;
|
var top = (e.pageY ? e.pageY : hovered_at['y']) - 10;
|
||||||
|
|
||||||
if(e.pageY < $(window).scrollTop() + 15) {
|
if(e.pageY < $(window).scrollTop() + 15) {
|
||||||
top = $(window).scrollTop();
|
top = $(window).scrollTop();
|
||||||
} else if(e.pageY > $(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;
|
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:
|
* Usage:
|
||||||
* $config['additional_javascript'][] = 'js/jquery.min.js';
|
* $config['additional_javascript'][] = 'js/jquery.min.js';
|
||||||
|
* // $config['additional_javascript'][] = 'js/post-hover'; (optional; must come first)
|
||||||
* $config['additional_javascript'][] = 'js/show-backlinks.js';
|
* $config['additional_javascript'][] = 'js/show-backlinks.js';
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$(document).ready(function(){
|
onready(function(){
|
||||||
$('div.post.reply').each(function() {
|
var showBackLinks = function() {
|
||||||
var reply_id = $(this).attr('id').replace(/^reply_/, '');
|
var reply_id = $(this).attr('id').replace(/^reply_/, '');
|
||||||
|
|
||||||
$(this).find('p.body a:not([rel="nofollow"])').each(function() {
|
$(this).find('p.body a:not([rel="nofollow"])').each(function() {
|
||||||
var id, post, mentioned;
|
var id, post, $mentioned;
|
||||||
|
|
||||||
if(id = $(this).text().match(/^>>(\d+)$/))
|
if(id = $(this).text().match(/^>>(\d+)$/))
|
||||||
id = id[1];
|
id = id[1];
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
|
|
||||||
post = $('#reply_' + id);
|
$post = $('#reply_' + id);
|
||||||
if(post.length == 0)
|
if($post.length == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mentioned = post.find('p.intro span.mentioned');
|
$mentioned = $post.find('p.intro span.mentioned');
|
||||||
if(mentioned.length == 0)
|
if($mentioned.length == 0)
|
||||||
mentioned = $('<span class="mentioned"></span>').appendTo(post.find('p.intro'));
|
$mentioned = $('<span class="mentioned"></span>').appendTo($post.find('p.intro'));
|
||||||
|
|
||||||
mentioned.append('<a onclick="highlightReply(\'' + reply_id + '\');" href="#' + reply_id + '">>>' + reply_id + '</a>');
|
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