From 2a823ae786f279eaec154faf50cca1fd40085af6 Mon Sep 17 00:00:00 2001 From: anonfagola Date: Tue, 23 Sep 2014 16:50:32 -0700 Subject: Create threadscroll.js --- js/threadscroll.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 js/threadscroll.js (limited to 'js/threadscroll.js') diff --git a/js/threadscroll.js b/js/threadscroll.js new file mode 100644 index 00000000..9b97074a --- /dev/null +++ b/js/threadscroll.js @@ -0,0 +1,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"); + } + } + } + } +}); -- cgit v1.3 From f5d121af105c76217ef0026cdf008f5aeac913e3 Mon Sep 17 00:00:00 2001 From: anonfagola Date: Tue, 23 Sep 2014 18:55:50 -0700 Subject: Update threadscroll.js Fixed a line left from debug, and added comments. --- js/threadscroll.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'js/threadscroll.js') diff --git a/js/threadscroll.js b/js/threadscroll.js index 9b97074a..4f623ed2 100644 --- a/js/threadscroll.js +++ b/js/threadscroll.js @@ -7,7 +7,7 @@ $(document).mouseover(function(e){ }); $(document).keydown(function(e){ - console.log(e); + //Up arrow if(e.which == 38){ var ele = hoverElem; @@ -25,6 +25,7 @@ $(document).keydown(function(e){ } } } + //Down arrow }else if(e.which == 40){ var ele = hoverElem; -- cgit v1.3 From 712e7f6c575f028511bf1ecfdf81e0a02df913fc Mon Sep 17 00:00:00 2001 From: anonfagola Date: Tue, 23 Sep 2014 19:27:41 -0700 Subject: Update threadscroll.js Made cleaner. --- js/threadscroll.js | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) (limited to 'js/threadscroll.js') 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"); } } } -- cgit v1.3 From b9886dc474e5d3fcbf879bd6237bae739c63a9f1 Mon Sep 17 00:00:00 2001 From: anonfagola Date: Tue, 23 Sep 2014 19:31:06 -0700 Subject: Update threadscroll.js Made compatible for use with additional_javascripts. --- js/threadscroll.js | 62 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 30 deletions(-) (limited to 'js/threadscroll.js') diff --git a/js/threadscroll.js b/js/threadscroll.js index 5cbcbbe8..c3c6deef 100644 --- a/js/threadscroll.js +++ b/js/threadscroll.js @@ -1,35 +1,37 @@ -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"); +if(active_page == "index" || active_page == "ukko"){ + 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"); + //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"); + } } } } - } -}); + }); +} -- cgit v1.3 From d9f20c290db89b17640228df6c405925e9ead587 Mon Sep 17 00:00:00 2001 From: anonfagola Date: Fri, 26 Sep 2014 16:55:16 -0700 Subject: Updated threadscroll.js with bettter compatibility --- js/threadscroll.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/threadscroll.js') diff --git a/js/threadscroll.js b/js/threadscroll.js index c3c6deef..0a233f58 100644 --- a/js/threadscroll.js +++ b/js/threadscroll.js @@ -16,7 +16,7 @@ if(active_page == "index" || active_page == "ukko"){ 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"); + par.prev()[0].scrollIntoView(true); } } } @@ -28,7 +28,7 @@ if(active_page == "index" || active_page == "ukko"){ 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"); + par.next()[0].scrollIntoView(true); } } } -- cgit v1.3