leftypol/js/threadscroll.js

36 lines
965 B
JavaScript
Raw Normal View History

2014-09-23 23:50:32 +00:00
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
2014-09-23 23:50:32 +00:00
if(e.which == 38){
var ele = hoverElem;
2014-09-24 02:27:41 +00:00
var par = $(ele).parents('div[id^="thread_"]');
2014-09-23 23:50:32 +00:00
2014-09-24 02:27:41 +00:00
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");
2014-09-23 23:50:32 +00:00
}
}
}
//Down arrow
2014-09-23 23:50:32 +00:00
}else if(e.which == 40){
var ele = hoverElem;
2014-09-24 02:27:41 +00:00
var par = $(ele).parents('div[id^="thread_"]');
2014-09-23 23:50:32 +00:00
2014-09-24 02:27:41 +00:00
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");
2014-09-23 23:50:32 +00:00
}
}
}
}
});