summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoranonfagola <anonfagola@users.noreply.github.com>2014-09-23 19:27:41 -0700
committerczaks <marcin@6irc.net>2014-09-24 04:47:40 +0200
commit712e7f6c575f028511bf1ecfdf81e0a02df913fc (patch)
tree9b70c56c467776cbba059ff89a70b2266de6cafa
parentf5d121af105c76217ef0026cdf008f5aeac913e3 (diff)
Update threadscroll.js
Made cleaner.
-rw-r--r--js/threadscroll.js32
1 files changed, 10 insertions, 22 deletions
diff --git a/js/threadscroll.js b/js/threadscroll.js
index 4f623ed2..5cbcbbe8 100644
--- a/js/threadscroll.js
+++ b/js/threadscroll.js
@@ -10,36 +10,24 @@ $(document).keydown(function(e){
//Up arrow
if(e.which == 38){
var ele = hoverElem;
+ var par = $(ele).parents('div[id^="thread_"]');
- 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");
+ 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(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");
+ 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");
}
}
}