summaryrefslogtreecommitdiff
path: root/js/id_highlighter.js
blob: 82e2c79dbfdc8c8146795a4e257b0ba26a8072d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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); }

		var idshighlighted = [];

		function getPostsById(id){
			return $(".poster_id").filter(function(i){
				return $(this).text() == id;
			});
		}

		function getMasterPosts(parents){
			if(!parents.hasClass("post")) return;
			
			var toRet = [];
			
			$(parents).each(function(){
				if($(this).hasClass("post"))
					toRet.push($(this));
			});
			
			return toRet;
		}

		$(".poster_id").click(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");
				});
			}
		});
	});
}