summaryrefslogtreecommitdiff
path: root/js/threadscroll.js
blob: 9b97074aaef2f8ef8f12d11ec1dfc9467817cc57 (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
45
46
var hoverElem = null;

$(document).mouseover(function(e){
	var x = e.clientX, y = e.clientY,
		elementOnMouseOver = document.elementFromPoint(x, y);
		hoverElem = $(elementOnMouseOver);
});

$(document).keydown(function(e){
	console.log(e);
	if(e.which == 38){
		var ele = hoverElem;
		
		if(ele.parent().attr("class") == "post op" || ele.attr("class") == "body" || ele.attr("class") == "post-image" || ele.parent().attr("class") == "body" || ele.parent().attr("class") == "body" || (ele.parent().attr("id")!= null && ele.parent().attr("id").match("^thread") != null) || (ele.parent().attr("for")!= null && ele.parent().attr("id").match("delete") != null)){
			var thread = (ele.parent().attr("class") == "post op") ? ele.parent().parent() : ele.parent();
			thread = (thread.attr("class") == "post reply") ? thread.parent() : thread;
			thread = (thread.attr("class") == "body") ? thread.parent().parent() : thread;
			thread = (ele.attr("class") == "post-image") ? thread.parent().parent().parent().parent() : thread; 
			
			if(thread.attr("id") == null) thread = ele.parent().parent().parent().parent(); //op image
			
			if(thread.prev().attr("id") != null){
				if(thread.prev().attr("id").match("^thread")){
					window.location.href = window.location.protocol+"//"+window.location.host+window.location.pathname+"#"+thread.prev().attr("id");
				}
			}
		}
	}else if(e.which == 40){
		var ele = hoverElem;
		
		if(ele.parent().attr("class") == "post op" || ele.attr("class") == "body" || ele.attr("class") == "post-image" || ele.parent().attr("class") == "body" || ele.parent().attr("class") == "body" || (ele.parent().attr("id")!= null && ele.parent().attr("id").match("^thread") != null) || (ele.parent().attr("for")!= null && ele.parent().attr("id").match("delete") != null)){
			var thread = (ele.parent().attr("class") == "post op") ? ele.parent().parent() : ele.parent();
			thread = (thread.attr("class") == "post reply") ? thread.parent() : thread;
			thread = (thread.attr("class") == "body") ? thread.parent().parent() : thread;
			thread = (ele.attr("class") == "post-image") ? thread.parent().parent().parent().parent() : thread; 
			
			if(thread.attr("id") == null) thread = ele.parent().parent().parent().parent(); //op image
			
			if(thread.next().attr("id") != null){
				if(thread.next().attr("id").match("^thread")){
					window.location.href = window.location.protocol+"//"+window.location.host+window.location.pathname+"#"+thread.next().attr("id");
				}
			}
		}
	}
});