2012-03-15 07:05:33 +01:00
|
|
|
/*
|
|
|
|
* post-hover.js
|
2012-03-31 02:13:11 +02:00
|
|
|
* https://github.com/savetheinternet/Tinyboard/blob/master/js/post-hover.js
|
2012-03-15 07:05:33 +01:00
|
|
|
*
|
|
|
|
* Released under the MIT license
|
|
|
|
* Copyright (c) 2012 Michael Save <savetheinternet@tinyboard.org>
|
2014-01-19 14:27:24 +01:00
|
|
|
* Copyright (c) 2013-2014 Marcin Łabanowski <marcin@6irc.net>
|
|
|
|
* Copyright (c) 2013 Macil Tech <maciltech@gmail.com>
|
2012-03-15 07:05:33 +01:00
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
* $config['additional_javascript'][] = 'js/jquery.min.js';
|
|
|
|
* $config['additional_javascript'][] = 'js/post-hover.js';
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-04-29 18:59:11 +02:00
|
|
|
onready(function(){
|
2012-03-16 21:45:38 +01:00
|
|
|
var dont_fetch_again = [];
|
2012-04-29 18:59:11 +02:00
|
|
|
init_hover = function() {
|
|
|
|
var $link = $(this);
|
2012-03-18 13:55:01 +01:00
|
|
|
|
2012-03-15 07:05:33 +01:00
|
|
|
var id;
|
|
|
|
|
2012-04-29 18:59:11 +02:00
|
|
|
if(id = $link.text().match(/^>>(\d+)$/)) {
|
2012-03-15 07:05:33 +01:00
|
|
|
id = id[1];
|
2013-06-18 19:10:06 +02:00
|
|
|
} else {
|
|
|
|
return;
|
2012-03-15 07:05:33 +01:00
|
|
|
}
|
|
|
|
|
2014-04-05 18:25:05 +02:00
|
|
|
/*var board = $(this);
|
2013-12-29 18:32:58 +01:00
|
|
|
var i = 0;
|
|
|
|
while (board.data('board') === undefined) {
|
|
|
|
board = board.parent();
|
|
|
|
i++;
|
|
|
|
if (i >= 10) return;
|
|
|
|
}
|
|
|
|
var threadid;
|
|
|
|
if ($link.is('[data-thread]')) threadid = 0;
|
|
|
|
else threadid = board.attr('id').replace("thread_", "");
|
|
|
|
|
|
|
|
board = board.data('board');
|
|
|
|
|
|
|
|
var parentboard = board;
|
|
|
|
|
|
|
|
if ($link.is('[data-thread]')) parentboard = $('form[name="post"] input[name="board"]').val();
|
2014-04-05 18:25:05 +02:00
|
|
|
else if (matches[1] !== undefined) board = matches[1];*/
|
2013-12-29 18:32:58 +01:00
|
|
|
|
2012-04-29 18:59:11 +02:00
|
|
|
var $post = false;
|
2012-03-16 22:09:24 +01:00
|
|
|
var hovering = false;
|
2012-03-17 00:59:14 +01:00
|
|
|
var hovered_at;
|
2012-04-29 18:59:11 +02:00
|
|
|
$link.hover(function(e) {
|
2012-03-16 22:09:24 +01:00
|
|
|
hovering = true;
|
2012-03-17 00:59:14 +01:00
|
|
|
hovered_at = {'x': e.pageX, 'y': e.pageY};
|
2012-03-16 22:09:24 +01:00
|
|
|
|
2012-04-29 18:59:11 +02:00
|
|
|
var start_hover = function($link) {
|
|
|
|
if($post.is(':visible') &&
|
|
|
|
$post.offset().top + $post.height() >= $(window).scrollTop() &&
|
|
|
|
$post.offset().top <= $(window).scrollTop() + $(window).height()
|
2012-03-16 22:09:24 +01:00
|
|
|
) {
|
2012-03-16 21:40:15 +01:00
|
|
|
// post is in view
|
2012-04-29 18:59:11 +02:00
|
|
|
$post.attr('style', 'border-style: none dashed dashed none; background: ' + $post.css('border-right-color'));
|
2012-03-16 21:40:15 +01:00
|
|
|
} else {
|
2012-04-29 18:59:11 +02:00
|
|
|
var $newPost = $post.clone();
|
|
|
|
$newPost.find('span.mentioned').remove();
|
|
|
|
$newPost
|
2012-03-16 21:40:15 +01:00
|
|
|
.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')
|
2013-12-25 16:26:24 +01:00
|
|
|
.css('z-index', '100')
|
|
|
|
.addClass('reply').addClass('post')
|
|
|
|
.insertAfter($link.parent())
|
2012-04-29 18:59:11 +02:00
|
|
|
$link.trigger('mousemove');
|
2012-03-16 21:40:15 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-04-29 18:59:11 +02:00
|
|
|
$post = $('div.post#reply_' + id);
|
|
|
|
if($post.length > 0) {
|
|
|
|
start_hover($(this));
|
2012-03-15 23:42:17 +01:00
|
|
|
} else {
|
2012-04-29 18:59:11 +02:00
|
|
|
var url = $link.attr('href').replace(/#.*$/, '');
|
2012-03-17 00:59:14 +01:00
|
|
|
|
|
|
|
if($.inArray(url, dont_fetch_again) != -1) {
|
2012-03-16 21:45:38 +01:00
|
|
|
return;
|
|
|
|
}
|
2012-03-17 00:59:14 +01:00
|
|
|
dont_fetch_again.push(url);
|
2012-03-16 21:45:38 +01:00
|
|
|
|
2012-03-16 21:40:15 +01:00
|
|
|
$.ajax({
|
2012-03-17 00:59:14 +01:00
|
|
|
url: url,
|
2012-03-16 21:40:15 +01:00
|
|
|
context: document.body,
|
|
|
|
success: function(data) {
|
2012-03-17 01:10:59 +01:00
|
|
|
$(data).find('div.post.reply').each(function() {
|
2013-08-16 15:49:57 +02:00
|
|
|
// Not 100% sure that this doesn't break shit:
|
|
|
|
$(document).trigger('new_post', this);
|
|
|
|
|
2012-03-18 14:11:55 +01:00
|
|
|
if($('#' + $(this).attr('id')).length == 0)
|
2013-08-17 06:42:48 +02:00
|
|
|
$('body').prepend($(this).css('display', 'none').addClass('hidden'));
|
2012-03-17 01:10:59 +01:00
|
|
|
});
|
2012-03-17 00:59:14 +01:00
|
|
|
|
2012-04-29 18:59:11 +02:00
|
|
|
$post = $('div.post#reply_' + id);
|
|
|
|
if(hovering && $post.length > 0) {
|
|
|
|
start_hover($link);
|
2012-03-18 14:11:55 +01:00
|
|
|
}
|
2012-03-16 21:40:15 +01:00
|
|
|
}
|
|
|
|
});
|
2012-03-15 23:42:17 +01:00
|
|
|
}
|
2012-03-15 07:05:33 +01:00
|
|
|
}, function() {
|
2012-03-16 22:09:24 +01:00
|
|
|
hovering = false;
|
2012-04-29 18:59:11 +02:00
|
|
|
if(!$post)
|
2012-03-16 21:40:15 +01:00
|
|
|
return;
|
2012-03-16 22:09:24 +01:00
|
|
|
|
2012-04-29 18:59:11 +02:00
|
|
|
$post.attr('style', '');
|
|
|
|
if($post.hasClass('hidden'))
|
|
|
|
$post.css('display', 'none');
|
2012-03-15 23:29:58 +01:00
|
|
|
$('.post-hover').remove();
|
|
|
|
}).mousemove(function(e) {
|
2012-04-29 18:59:11 +02:00
|
|
|
if(!$post)
|
2012-03-16 21:40:15 +01:00
|
|
|
return;
|
2012-03-17 00:59:14 +01:00
|
|
|
|
2012-04-29 18:59:11 +02:00
|
|
|
var $hover = $('#post-hover-' + id);
|
|
|
|
if($hover.length == 0)
|
2012-03-17 01:33:20 +01:00
|
|
|
return;
|
|
|
|
|
2012-03-17 00:59:14 +01:00
|
|
|
var top = (e.pageY ? e.pageY : hovered_at['y']) - 10;
|
|
|
|
|
2012-03-17 01:33:20 +01:00
|
|
|
if(e.pageY < $(window).scrollTop() + 15) {
|
|
|
|
top = $(window).scrollTop();
|
2012-04-29 18:59:11 +02:00
|
|
|
} else if(e.pageY > $(window).scrollTop() + $(window).height() - $hover.height() - 15) {
|
|
|
|
top = $(window).scrollTop() + $(window).height() - $hover.height() - 15;
|
2012-03-17 01:33:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-29 18:59:11 +02:00
|
|
|
$hover.css('left', (e.pageX ? e.pageX : hovered_at['x'])).css('top', top);
|
2012-03-15 07:05:33 +01:00
|
|
|
});
|
2012-03-18 13:55:01 +01:00
|
|
|
};
|
|
|
|
|
2012-08-27 15:01:08 +02:00
|
|
|
$('div.body a:not([rel="nofollow"])').each(init_hover);
|
2012-03-18 13:55:01 +01:00
|
|
|
|
|
|
|
// allow to work with auto-reload.js, etc.
|
|
|
|
$(document).bind('new_post', function(e, post) {
|
2012-08-27 15:01:08 +02:00
|
|
|
$(post).find('div.body a:not([rel="nofollow"])').each(init_hover);
|
2012-03-15 07:05:33 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|