1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-12-25 05:44:57 +01:00
vichan/js/id_highlighter.js

51 lines
1.1 KiB
JavaScript
Raw Normal View History

if (active_page == 'thread' || active_page == 'index') {
$(document).ready(function(){
function arrayRemove(a, v) { a.splice(a.indexOf(v) == -1 ? a.length : a.indexOf(v), 1); }
2014-09-27 18:47:11 +02:00
var idshighlighted = [];
2014-09-27 18:47:11 +02:00
function getPostsById(id){
return $(".poster_id").filter(function(i){
return $(this).text() == id;
});
}
2014-09-27 18:47:11 +02:00
function getMasterPosts(parents){
if(!parents.hasClass("post")) return;
var toRet = [];
$(parents).each(function(){
if($(this).hasClass("post"))
toRet.push($(this));
});
return toRet;
}
2014-09-27 18:47:11 +02:00
var id_highlighter = function(){
var id = $(this).text();
if($.inArray(id, idshighlighted) !== -1){
arrayRemove(idshighlighted, id);
$(getMasterPosts(getPostsById(id).parents())).each(function(i){
$(this).removeClass("highlighted");
});
}else{
idshighlighted.push(id);
$(getMasterPosts(getPostsById(id).parents())).each(function(i){
$(this).addClass("highlighted");
});
}
}
$(".poster_id").on('click', id_highlighter);
$(document).on('new_post', function(e, post) {
$(post).find('.poster_id').on('click', id_highlighter);
2014-09-27 18:47:11 +02:00
});
});
}