2012-03-15 02:05:33 -04:00
|
|
|
/*
|
|
|
|
* post-hover.js
|
2012-03-30 20:13:11 -04:00
|
|
|
* https://github.com/savetheinternet/Tinyboard/blob/master/js/post-hover.js
|
2012-03-15 02:05:33 -04:00
|
|
|
*
|
|
|
|
* Released under the MIT license
|
|
|
|
* Copyright (c) 2012 Michael Save <savetheinternet@tinyboard.org>
|
2014-01-19 08:27:24 -05:00
|
|
|
* Copyright (c) 2013-2014 Marcin Łabanowski <marcin@6irc.net>
|
|
|
|
* Copyright (c) 2013 Macil Tech <maciltech@gmail.com>
|
2012-03-15 02:05:33 -04:00
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
* $config['additional_javascript'][] = 'js/jquery.min.js';
|
|
|
|
* $config['additional_javascript'][] = 'js/post-hover.js';
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-04-29 12:59:11 -04:00
|
|
|
onready(function(){
|
2012-03-16 16:45:38 -04:00
|
|
|
var dont_fetch_again = [];
|
2012-04-29 12:59:11 -04:00
|
|
|
init_hover = function() {
|
|
|
|
var $link = $(this);
|
2012-03-18 08:55:01 -04:00
|
|
|
|
2012-03-15 02:05:33 -04:00
|
|
|
var id;
|
2013-08-05 00:18:25 -04:00
|
|
|
var matches;
|
|
|
|
|
2013-12-28 22:27:53 -05:00
|
|
|
if ($link.is('[data-thread]')) {
|
|
|
|
id = $link.attr('data-thread');
|
|
|
|
}
|
|
|
|
else if(matches = $link.text().match(/^>>(?:>\/([^\/]+)\/)?(\d+)$/)) {
|
2013-08-05 00:18:25 -04:00
|
|
|
id = matches[2];
|
2013-12-28 22:27:53 -05:00
|
|
|
}
|
|
|
|
else {
|
2013-06-18 13:10:06 -04:00
|
|
|
return;
|
2012-03-15 02:05:33 -04:00
|
|
|
}
|
2013-08-05 00:18:25 -04:00
|
|
|
|
2013-08-04 06:08:10 -04:00
|
|
|
var board = $(this);
|
|
|
|
while (board.data('board') === undefined) {
|
|
|
|
board = board.parent();
|
|
|
|
}
|
2013-12-28 22:27:53 -05:00
|
|
|
var threadid;
|
|
|
|
if ($link.is('[data-thread]')) threadid = 0;
|
|
|
|
else threadid = board.attr('id').replace("thread_", "");
|
|
|
|
|
2013-08-04 06:08:10 -04:00
|
|
|
board = board.data('board');
|
|
|
|
|
2013-08-05 00:18:25 -04:00
|
|
|
var parentboard = board;
|
2013-12-28 22:27:53 -05:00
|
|
|
|
|
|
|
if ($link.is('[data-thread]')) parentboard = $('form[name="post"] input[name="board"]').val();
|
|
|
|
else if (matches[1] !== undefined) board = matches[1];
|
2013-08-05 00:18:25 -04:00
|
|
|
|
2012-04-29 12:59:11 -04:00
|
|
|
var $post = false;
|
2012-03-16 17:09:24 -04:00
|
|
|
var hovering = false;
|
2012-03-16 19:59:14 -04:00
|
|
|
var hovered_at;
|
2012-04-29 12:59:11 -04:00
|
|
|
$link.hover(function(e) {
|
2012-03-16 17:09:24 -04:00
|
|
|
hovering = true;
|
2012-03-16 19:59:14 -04:00
|
|
|
hovered_at = {'x': e.pageX, 'y': e.pageY};
|
2012-03-16 17:09:24 -04:00
|
|
|
|
2012-04-29 12:59:11 -04:00
|
|
|
var start_hover = function($link) {
|
2016-06-01 06:35:17 -04:00
|
|
|
if ($post.is(':visible') &&
|
2014-09-26 06:56:05 -04:00
|
|
|
$post.offset().top >= $(window).scrollTop() &&
|
|
|
|
$post.offset().top + $post.height() <= $(window).scrollTop() + $(window).height()) {
|
2012-03-16 16:40:15 -04:00
|
|
|
// post is in view
|
2013-09-18 20:02:59 -04:00
|
|
|
$post.addClass('highlighted');
|
2012-03-16 16:40:15 -04:00
|
|
|
} else {
|
2012-04-29 12:59:11 -04:00
|
|
|
var $newPost = $post.clone();
|
2013-08-05 01:00:25 -04:00
|
|
|
$newPost.find('>.reply, >br').remove();
|
2012-04-29 12:59:11 -04:00
|
|
|
$newPost.find('span.mentioned').remove();
|
2014-06-12 11:36:01 -04:00
|
|
|
$newPost.find('a.post_anchor').remove();
|
2013-08-05 01:00:25 -04:00
|
|
|
|
2012-04-29 12:59:11 -04:00
|
|
|
$newPost
|
2012-03-16 16:40:15 -04:00
|
|
|
.attr('id', 'post-hover-' + id)
|
2013-08-04 06:08:10 -04:00
|
|
|
.attr('data-board', board)
|
2012-03-16 16:40:15 -04:00
|
|
|
.addClass('post-hover')
|
|
|
|
.css('border-style', 'solid')
|
|
|
|
.css('box-shadow', '1px 1px 1px #999')
|
|
|
|
.css('display', 'block')
|
2013-12-28 22:27:53 -05:00
|
|
|
.css('position', 'absolute')
|
|
|
|
.css('font-style', 'normal')
|
2013-12-25 10:26:24 -05:00
|
|
|
.css('z-index', '100')
|
2013-08-05 01:00:25 -04:00
|
|
|
.addClass('reply').addClass('post')
|
|
|
|
.insertAfter($link.parent())
|
2013-12-28 22:27:53 -05:00
|
|
|
|
2012-04-29 12:59:11 -04:00
|
|
|
$link.trigger('mousemove');
|
2012-03-16 16:40:15 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-08-05 01:00:25 -04:00
|
|
|
$post = $('[data-board="' + board + '"] div.post#reply_' + id + ', [data-board="' + board + '"]div#thread_' + id);
|
2012-04-29 12:59:11 -04:00
|
|
|
if($post.length > 0) {
|
|
|
|
start_hover($(this));
|
2012-03-15 18:42:17 -04:00
|
|
|
} else {
|
2012-04-29 12:59:11 -04:00
|
|
|
var url = $link.attr('href').replace(/#.*$/, '');
|
2012-03-16 19:59:14 -04:00
|
|
|
|
|
|
|
if($.inArray(url, dont_fetch_again) != -1) {
|
2012-03-16 16:45:38 -04:00
|
|
|
return;
|
|
|
|
}
|
2012-03-16 19:59:14 -04:00
|
|
|
dont_fetch_again.push(url);
|
2012-03-16 16:45:38 -04:00
|
|
|
|
2012-03-16 16:40:15 -04:00
|
|
|
$.ajax({
|
2012-03-16 19:59:14 -04:00
|
|
|
url: url,
|
2012-03-16 16:40:15 -04:00
|
|
|
context: document.body,
|
|
|
|
success: function(data) {
|
2013-08-05 00:18:25 -04:00
|
|
|
var mythreadid = $(data).find('div[id^="thread_"]').attr('id').replace("thread_", "");
|
2012-03-18 09:11:55 -04:00
|
|
|
|
2013-08-05 00:18:25 -04:00
|
|
|
if (mythreadid == threadid && parentboard == board) {
|
|
|
|
$(data).find('div.post.reply').each(function() {
|
|
|
|
if($('[data-board="' + board + '"] #' + $(this).attr('id')).length == 0) {
|
|
|
|
$('[data-board="' + board + '"]#thread_' + threadid + " .post.reply:first").before($(this).hide().addClass('hidden'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else if ($('[data-board="' + board + '"]#thread_'+mythreadid).length > 0) {
|
|
|
|
$(data).find('div.post.reply').each(function() {
|
|
|
|
if($('[data-board="' + board + '"] #' + $(this).attr('id')).length == 0) {
|
|
|
|
$('[data-board="' + board + '"]#thread_' + mythreadid + " .post.reply:first").before($(this).hide().addClass('hidden'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$(data).find('div[id^="thread_"]').hide().attr('data-cached', 'yes').prependTo('form[name="postcontrols"]');
|
|
|
|
}
|
2013-08-16 11:29:13 -04:00
|
|
|
|
2013-08-05 01:00:25 -04:00
|
|
|
$post = $('[data-board="' + board + '"] div.post#reply_' + id + ', [data-board="' + board + '"]div#thread_' + id);
|
2013-08-17 16:21:40 -04:00
|
|
|
|
2012-04-29 12:59:11 -04:00
|
|
|
if(hovering && $post.length > 0) {
|
|
|
|
start_hover($link);
|
2012-03-18 09:11:55 -04:00
|
|
|
}
|
2012-03-16 16:40:15 -04:00
|
|
|
}
|
|
|
|
});
|
2012-03-15 18:42:17 -04:00
|
|
|
}
|
2012-03-15 02:05:33 -04:00
|
|
|
}, function() {
|
2012-03-16 17:09:24 -04:00
|
|
|
hovering = false;
|
2012-04-29 12:59:11 -04:00
|
|
|
if(!$post)
|
2012-03-16 16:40:15 -04:00
|
|
|
return;
|
2012-03-16 17:09:24 -04:00
|
|
|
|
2013-09-18 20:02:59 -04:00
|
|
|
$post.removeClass('highlighted');
|
2013-08-05 01:00:25 -04:00
|
|
|
if($post.hasClass('hidden') || $post.data('cached') == 'yes')
|
2012-04-29 12:59:11 -04:00
|
|
|
$post.css('display', 'none');
|
2012-03-15 18:29:58 -04:00
|
|
|
$('.post-hover').remove();
|
|
|
|
}).mousemove(function(e) {
|
2012-04-29 12:59:11 -04:00
|
|
|
if(!$post)
|
2012-03-16 16:40:15 -04:00
|
|
|
return;
|
2012-03-16 19:59:14 -04:00
|
|
|
|
2013-08-04 06:08:10 -04:00
|
|
|
var $hover = $('#post-hover-' + id + '[data-board="' + board + '"]');
|
2012-04-29 12:59:11 -04:00
|
|
|
if($hover.length == 0)
|
2012-03-16 20:33:20 -04:00
|
|
|
return;
|
2013-12-28 22:27:53 -05:00
|
|
|
|
|
|
|
var scrollTop = $(window).scrollTop();
|
|
|
|
if ($link.is("[data-thread]")) scrollTop = 0;
|
|
|
|
var epy = e.pageY;
|
|
|
|
if ($link.is("[data-thread]")) epy -= $(window).scrollTop();
|
|
|
|
|
|
|
|
var top = (epy ? epy : hovered_at['y']) - 10;
|
2012-03-16 20:33:20 -04:00
|
|
|
|
2013-12-28 22:27:53 -05:00
|
|
|
if(epy < scrollTop + 15) {
|
|
|
|
top = scrollTop;
|
|
|
|
} else if(epy > scrollTop + $(window).height() - $hover.height() - 15) {
|
|
|
|
top = scrollTop + $(window).height() - $hover.height() - 15;
|
2012-03-16 20:33:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-29 12:59:11 -04:00
|
|
|
$hover.css('left', (e.pageX ? e.pageX : hovered_at['x'])).css('top', top);
|
2012-03-15 02:05:33 -04:00
|
|
|
});
|
2012-03-18 08:55:01 -04:00
|
|
|
};
|
|
|
|
|
2012-08-27 09:01:08 -04:00
|
|
|
$('div.body a:not([rel="nofollow"])').each(init_hover);
|
2012-03-18 08:55:01 -04:00
|
|
|
|
|
|
|
// allow to work with auto-reload.js, etc.
|
2014-01-21 13:25:11 -05:00
|
|
|
$(document).on('new_post', function(e, post) {
|
2012-08-27 09:01:08 -04:00
|
|
|
$(post).find('div.body a:not([rel="nofollow"])').each(init_hover);
|
2012-03-15 02:05:33 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|