summaryrefslogtreecommitdiff
path: root/js/threadscroll.js
blob: 5cbcbbe806e73908a8ea5177033c9f132092a531 (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
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){
	//Up arrow
	if(e.which == 38){
		var ele = hoverElem;
		var par = $(ele).parents('div[id^="thread_"]');
		
		if(par.length == 1){
			if(par.prev().attr("id") != null){
				if(par.prev().attr("id").match("^thread")){
					window.location.href = window.location.protocol+"//"+window.location.host+window.location.pathname+"#"+par.prev().attr("id");
				}
			}
		}
	//Down arrow
	}else if(e.which == 40){
		var ele = hoverElem;
		var par = $(ele).parents('div[id^="thread_"]');
		
		if(par.length == 1){
			if(par.next().attr("id") != null){
				if(par.next().attr("id").match("^thread")){
					window.location.href = window.location.protocol+"//"+window.location.host+window.location.pathname+"#"+par.next().attr("id");
				}
			}
		}
	}
});