From 85cc117b33c70841e4a8dfba7f81b6d154cae109 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Thu, 15 Mar 2012 17:05:33 +1100 Subject: post-hover.js --- js/post-hover.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 js/post-hover.js (limited to 'js/post-hover.js') diff --git a/js/post-hover.js b/js/post-hover.js new file mode 100644 index 00000000..4771c42d --- /dev/null +++ b/js/post-hover.js @@ -0,0 +1,30 @@ +/* + * post-hover.js + * https://github.com/savetheinternet/Tinyboard-Tools/blob/master/js/post-hover.js + * + * Released under the MIT license + * Copyright (c) 2012 Michael Save + * + * Usage: + * $config['additional_javascript'][] = 'js/jquery.min.js'; + * $config['additional_javascript'][] = 'js/post-hover.js'; + * + */ + +$(document).ready(function(){ + $('p.body a:not([rel="nofollow"])').each(function() { + var id; + + if(id = $(this).text().match(/^>>(\d+)$/)) { + id = id[1]; + } + + var post = $('div.post#reply_' + id); + $(this).hover(function() { + post.attr('style', 'border-style: none dashed dashed none; background: ' + post.css('border-color')); + }, function() { + post.attr('style', ''); + }); + }); +}); + -- cgit v1.3 From ae848ef6663ec90c1e83f3729558c59547b2e0e7 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Thu, 15 Mar 2012 18:57:43 +1100 Subject: use border-right-color for firefox --- js/post-hover.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/post-hover.js') diff --git a/js/post-hover.js b/js/post-hover.js index 4771c42d..d151e5b3 100644 --- a/js/post-hover.js +++ b/js/post-hover.js @@ -21,7 +21,7 @@ $(document).ready(function(){ var post = $('div.post#reply_' + id); $(this).hover(function() { - post.attr('style', 'border-style: none dashed dashed none; background: ' + post.css('border-color')); + post.attr('style', 'border-style: none dashed dashed none; background: ' + post.css('border-right-color')); }, function() { post.attr('style', ''); }); -- cgit v1.3 From a5739602296251b698aab834205829ac37edca1b Mon Sep 17 00:00:00 2001 From: Michael Save Date: Fri, 16 Mar 2012 09:29:58 +1100 Subject: show actual posts instead of highlighting them --- js/post-hover.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'js/post-hover.js') diff --git a/js/post-hover.js b/js/post-hover.js index d151e5b3..06dd55a2 100644 --- a/js/post-hover.js +++ b/js/post-hover.js @@ -20,10 +20,22 @@ $(document).ready(function(){ } var post = $('div.post#reply_' + id); - $(this).hover(function() { - post.attr('style', 'border-style: none dashed dashed none; background: ' + post.css('border-right-color')); + $(this).hover(function(e) { + post.clone() + .attr('id', 'post-hover-' + id) + .addClass('post-hover') + .css('position', 'absolute') + .css('left', e.pageX + 15) + .css('top', e.pageY - post.height() - 15) + .css('border-style', 'solid') + .css('box-shadow', '1px 1px 1px #999') + .insertAfter($(this).parent()); }, function() { - post.attr('style', ''); + $('.post-hover').remove(); + }).mousemove(function(e) { + $('#post-hover-' + id) + .css('left', e.pageX + 15) + .css('top', e.pageY - post.height() - 15); }); }); }); -- cgit v1.3 From 1d7381554d3647c92db3b8b1b1f7a96d6f2653dd Mon Sep 17 00:00:00 2001 From: Michael Save Date: Fri, 16 Mar 2012 09:42:17 +1100 Subject: Don't show post when it's already in view. Highlight it instead. --- js/post-hover.js | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'js/post-hover.js') diff --git a/js/post-hover.js b/js/post-hover.js index 06dd55a2..335e3ac4 100644 --- a/js/post-hover.js +++ b/js/post-hover.js @@ -20,17 +20,26 @@ $(document).ready(function(){ } var post = $('div.post#reply_' + id); + if(post.length == 0) + return; + $(this).hover(function(e) { - post.clone() - .attr('id', 'post-hover-' + id) - .addClass('post-hover') - .css('position', 'absolute') - .css('left', e.pageX + 15) - .css('top', e.pageY - post.height() - 15) - .css('border-style', 'solid') - .css('box-shadow', '1px 1px 1px #999') - .insertAfter($(this).parent()); + if($(window).scrollTop() <= post.offset().top + post.height()) { + // post is in view + post.attr('style', 'border-style: none dashed dashed none; background: ' + post.css('border-right-color')); + } else { + post.clone() + .attr('id', 'post-hover-' + id) + .addClass('post-hover') + .css('position', 'absolute') + .css('left', e.pageX + 15) + .css('top', e.pageY - post.height() - 15) + .css('border-style', 'solid') + .css('box-shadow', '1px 1px 1px #999') + .insertAfter($(this).parent()); + } }, function() { + post.attr('style', ''); $('.post-hover').remove(); }).mousemove(function(e) { $('#post-hover-' + id) -- cgit v1.3 From 34fc25f71629a52f76c4c48bc543eb65835ca40b Mon Sep 17 00:00:00 2001 From: Michael Save Date: Fri, 16 Mar 2012 09:48:37 +1100 Subject: clip to top --- js/post-hover.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'js/post-hover.js') diff --git a/js/post-hover.js b/js/post-hover.js index 335e3ac4..89808f54 100644 --- a/js/post-hover.js +++ b/js/post-hover.js @@ -32,19 +32,19 @@ $(document).ready(function(){ .attr('id', 'post-hover-' + id) .addClass('post-hover') .css('position', 'absolute') - .css('left', e.pageX + 15) - .css('top', e.pageY - post.height() - 15) .css('border-style', 'solid') .css('box-shadow', '1px 1px 1px #999') .insertAfter($(this).parent()); + $(this).trigger('mousemove'); } }, function() { post.attr('style', ''); $('.post-hover').remove(); }).mousemove(function(e) { + var top = e.pageY - post.height() - 15; $('#post-hover-' + id) - .css('left', e.pageX + 15) - .css('top', e.pageY - post.height() - 15); + .css('left', $(this).width() + e.pageX) + .css('top', top > $(window).scrollTop() ? top : $(window).scrollTop()); }); }); }); -- cgit v1.3 From 50624ba5ce953552c98f3042de4664d6ec0879e3 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Sat, 17 Mar 2012 07:40:15 +1100 Subject: Use AJAX to fetch posts that aren't on the current page. --- js/post-hover.js | 53 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 16 deletions(-) (limited to 'js/post-hover.js') diff --git a/js/post-hover.js b/js/post-hover.js index 89808f54..0d0f3bb1 100644 --- a/js/post-hover.js +++ b/js/post-hover.js @@ -19,31 +19,52 @@ $(document).ready(function(){ id = id[1]; } - var post = $('div.post#reply_' + id); - if(post.length == 0) - return; - + var post = false; $(this).hover(function(e) { - if($(window).scrollTop() <= post.offset().top + post.height()) { - // post is in view - post.attr('style', 'border-style: none dashed dashed none; background: ' + post.css('border-right-color')); + var start_hover = function(link) { + if(post.is(':visible') && $(window).scrollTop() <= post.offset().top + post.height()) { + // post is in view + post.attr('style', 'border-style: none dashed dashed none; background: ' + post.css('border-right-color')); + } else { + post.clone() + .attr('id', 'post-hover-' + id) + .addClass('post-hover') + .css('position', 'absolute') + .css('border-style', 'solid') + .css('box-shadow', '1px 1px 1px #999') + .css('display', 'block') + .insertAfter($(link).parent()); + $(link).trigger('mousemove'); + } + }; + + post = $('div.post#reply_' + id); + if(post.length > 0) { + start_hover(this); } else { - post.clone() - .attr('id', 'post-hover-' + id) - .addClass('post-hover') - .css('position', 'absolute') - .css('border-style', 'solid') - .css('box-shadow', '1px 1px 1px #999') - .insertAfter($(this).parent()); - $(this).trigger('mousemove'); + var link = this; + $.ajax({ + url: $(this).attr('href'), + context: document.body, + success: function(data) { + post = $('div.post:first').prepend($(data).find('div.post#reply_' + id).css('display', 'none').addClass('hidden')).find('div.post#reply_' + id); + start_hover(link, post); + } + }); } }, function() { + if(!post) + return; post.attr('style', ''); + if(post.hasClass('hidden')) + post.css('display', 'none'); $('.post-hover').remove(); }).mousemove(function(e) { + if(!post) + return; var top = e.pageY - post.height() - 15; $('#post-hover-' + id) - .css('left', $(this).width() + e.pageX) + .css('left', e.pageX) .css('top', top > $(window).scrollTop() ? top : $(window).scrollTop()); }); }); -- cgit v1.3 From 68e873315a0104968a722b7814ad1ce1c62243dd Mon Sep 17 00:00:00 2001 From: Michael Save Date: Sat, 17 Mar 2012 07:45:38 +1100 Subject: Ensure no double-fetching of posts. --- js/post-hover.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'js/post-hover.js') diff --git a/js/post-hover.js b/js/post-hover.js index 0d0f3bb1..39c4aca6 100644 --- a/js/post-hover.js +++ b/js/post-hover.js @@ -12,6 +12,7 @@ */ $(document).ready(function(){ + var dont_fetch_again = []; $('p.body a:not([rel="nofollow"])').each(function() { var id; @@ -43,6 +44,12 @@ $(document).ready(function(){ start_hover(this); } else { var link = this; + + if($.inArray($(this).attr('href'), dont_fetch_again) != -1) { + return; + } + + dont_fetch_again.push($(this).attr('href')); $.ajax({ url: $(this).attr('href'), context: document.body, -- cgit v1.3 From e34de4e09dc8bdb8fad59b08348d60e9e0a694e9 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Sat, 17 Mar 2012 07:46:44 +1100 Subject: Allow post-hover.js to work with forced-anon.js --- js/forced-anon.js | 2 +- js/post-hover.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'js/post-hover.js') diff --git a/js/forced-anon.js b/js/forced-anon.js index 6949769d..0f7f1c70 100644 --- a/js/forced-anon.js +++ b/js/forced-anon.js @@ -12,7 +12,7 @@ */ $(document).ready(function(){ - var enable_fa = function() { + enable_fa = function() { $('p.intro label').each(function() { if($(this).children('a.capcode').length == 0) { var id = $(this).parent().children('a.post_no:eq(1)').text(); diff --git a/js/post-hover.js b/js/post-hover.js index 39c4aca6..d7d567cd 100644 --- a/js/post-hover.js +++ b/js/post-hover.js @@ -55,6 +55,8 @@ $(document).ready(function(){ context: document.body, success: function(data) { post = $('div.post:first').prepend($(data).find('div.post#reply_' + id).css('display', 'none').addClass('hidden')).find('div.post#reply_' + id); + if(localStorage['forcedanon']) + enable_fa(); start_hover(link, post); } }); -- cgit v1.3 From 134146e32cc873b6a8a74a4b2084ad9ae984f8e2 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Sat, 17 Mar 2012 07:51:45 +1100 Subject: Allow post-hover.js to work /without/ forced-anon.js... --- js/post-hover.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'js/post-hover.js') diff --git a/js/post-hover.js b/js/post-hover.js index d7d567cd..5e5f4bab 100644 --- a/js/post-hover.js +++ b/js/post-hover.js @@ -54,8 +54,10 @@ $(document).ready(function(){ url: $(this).attr('href'), context: document.body, success: function(data) { - post = $('div.post:first').prepend($(data).find('div.post#reply_' + id).css('display', 'none').addClass('hidden')).find('div.post#reply_' + id); - if(localStorage['forcedanon']) + post = $('div.post:first') + .prepend($(data).find('div.post#reply_' + id).css('display', 'none').addClass('hidden')) + .find('div.post#reply_' + id); + if(typeof window.enable_fa == 'function' && localStorage['forcedanon']) enable_fa(); start_hover(link, post); } -- cgit v1.3 From ce25db62ea6064069414d0f5b2bb53132a51c328 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Sat, 17 Mar 2012 07:54:08 +1100 Subject: css bug --- js/post-hover.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'js/post-hover.js') diff --git a/js/post-hover.js b/js/post-hover.js index 5e5f4bab..e8b0c9b0 100644 --- a/js/post-hover.js +++ b/js/post-hover.js @@ -27,6 +27,8 @@ $(document).ready(function(){ // post is in view post.attr('style', 'border-style: none dashed dashed none; background: ' + post.css('border-right-color')); } else { + var top = e.pageY - post.height() - 15; + post.clone() .attr('id', 'post-hover-' + id) .addClass('post-hover') @@ -34,6 +36,8 @@ $(document).ready(function(){ .css('border-style', 'solid') .css('box-shadow', '1px 1px 1px #999') .css('display', 'block') + .css('left', e.pageX) + .css('top', top > $(window).scrollTop() ? top : $(window).scrollTop()) .insertAfter($(link).parent()); $(link).trigger('mousemove'); } @@ -59,7 +63,7 @@ $(document).ready(function(){ .find('div.post#reply_' + id); if(typeof window.enable_fa == 'function' && localStorage['forcedanon']) enable_fa(); - start_hover(link, post); + start_hover(link); } }); } -- cgit v1.3 From a2ac54e01ee8a9176ba5054d453fc5f2a3662908 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Sat, 17 Mar 2012 08:09:24 +1100 Subject: Check if post is below viewable region. --- js/post-hover.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'js/post-hover.js') diff --git a/js/post-hover.js b/js/post-hover.js index e8b0c9b0..808570c5 100644 --- a/js/post-hover.js +++ b/js/post-hover.js @@ -21,9 +21,15 @@ $(document).ready(function(){ } var post = false; + var hovering = false; $(this).hover(function(e) { + hovering = true; + var start_hover = function(link) { - if(post.is(':visible') && $(window).scrollTop() <= post.offset().top + post.height()) { + if(post.is(':visible') && + post.offset().top + post.height() >= $(window).scrollTop() && + post.offset().top <= $(window).scrollTop() + $(window).height() + ) { // post is in view post.attr('style', 'border-style: none dashed dashed none; background: ' + post.css('border-right-color')); } else { @@ -44,6 +50,7 @@ $(document).ready(function(){ }; post = $('div.post#reply_' + id); + console.log(post); if(post.length > 0) { start_hover(this); } else { @@ -63,13 +70,16 @@ $(document).ready(function(){ .find('div.post#reply_' + id); if(typeof window.enable_fa == 'function' && localStorage['forcedanon']) enable_fa(); - start_hover(link); + if(hovering) + start_hover(link); } }); } }, function() { + hovering = false; if(!post) return; + post.attr('style', ''); if(post.hasClass('hidden')) post.css('display', 'none'); -- cgit v1.3 From bf7fd32c21762803bf22d2e55a0e07334b2b9139 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Sat, 17 Mar 2012 08:12:47 +1100 Subject: start_hover() causing weird positing issues when using AJAX method --- js/post-hover.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'js/post-hover.js') diff --git a/js/post-hover.js b/js/post-hover.js index 808570c5..f9e032aa 100644 --- a/js/post-hover.js +++ b/js/post-hover.js @@ -42,8 +42,6 @@ $(document).ready(function(){ .css('border-style', 'solid') .css('box-shadow', '1px 1px 1px #999') .css('display', 'block') - .css('left', e.pageX) - .css('top', top > $(window).scrollTop() ? top : $(window).scrollTop()) .insertAfter($(link).parent()); $(link).trigger('mousemove'); } @@ -52,10 +50,9 @@ $(document).ready(function(){ post = $('div.post#reply_' + id); console.log(post); if(post.length > 0) { - start_hover(this); + start_hover(this, e); } else { var link = this; - if($.inArray($(this).attr('href'), dont_fetch_again) != -1) { return; } -- cgit v1.3 From 443c79047be865c747bb7e47f685d041cde85e28 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Sat, 17 Mar 2012 10:59:14 +1100 Subject: post-hover.js: Fix position on AJAX. Fetch all replies when using AJAX. --- js/post-hover.js | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'js/post-hover.js') diff --git a/js/post-hover.js b/js/post-hover.js index f9e032aa..d68c103d 100644 --- a/js/post-hover.js +++ b/js/post-hover.js @@ -22,8 +22,10 @@ $(document).ready(function(){ var post = false; var hovering = false; + var hovered_at; $(this).hover(function(e) { hovering = true; + hovered_at = {'x': e.pageX, 'y': e.pageY}; var start_hover = function(link) { if(post.is(':visible') && @@ -33,8 +35,6 @@ $(document).ready(function(){ // post is in view post.attr('style', 'border-style: none dashed dashed none; background: ' + post.css('border-right-color')); } else { - var top = e.pageY - post.height() - 15; - post.clone() .attr('id', 'post-hover-' + id) .addClass('post-hover') @@ -48,26 +48,28 @@ $(document).ready(function(){ }; post = $('div.post#reply_' + id); - console.log(post); if(post.length > 0) { - start_hover(this, e); + start_hover(this); } else { var link = this; - if($.inArray($(this).attr('href'), dont_fetch_again) != -1) { + var url = $(this).attr('href').replace(/#.*$/, ''); + + if($.inArray(url, dont_fetch_again) != -1) { return; } + dont_fetch_again.push(url); - dont_fetch_again.push($(this).attr('href')); $.ajax({ - url: $(this).attr('href'), + url: url, context: document.body, success: function(data) { - post = $('div.post:first') - .prepend($(data).find('div.post#reply_' + id).css('display', 'none').addClass('hidden')) - .find('div.post#reply_' + id); + $('div.post:first').prepend($(data).find('div.post.reply').css('display', 'none').addClass('hidden')); + if(typeof window.enable_fa == 'function' && localStorage['forcedanon']) enable_fa(); - if(hovering) + + post = $('div.post#reply_' + id); + if(hovering && post.length > 0) start_hover(link); } }); @@ -84,9 +86,11 @@ $(document).ready(function(){ }).mousemove(function(e) { if(!post) return; - var top = e.pageY - post.height() - 15; + + var top = (e.pageY ? e.pageY : hovered_at['y']) - 10; + $('#post-hover-' + id) - .css('left', e.pageX) + .css('left', (e.pageX ? e.pageX : hovered_at['x'])) .css('top', top > $(window).scrollTop() ? top : $(window).scrollTop()); }); }); -- cgit v1.3 From de5e7e27ece1b91f58302e918cafb38adf6584f7 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Sat, 17 Mar 2012 11:10:59 +1100 Subject: Don't clone replies we can already see. That will break stuff. --- js/post-hover.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'js/post-hover.js') diff --git a/js/post-hover.js b/js/post-hover.js index d68c103d..68dfc98e 100644 --- a/js/post-hover.js +++ b/js/post-hover.js @@ -63,7 +63,10 @@ $(document).ready(function(){ url: url, context: document.body, success: function(data) { - $('div.post:first').prepend($(data).find('div.post.reply').css('display', 'none').addClass('hidden')); + $(data).find('div.post.reply').each(function() { + if($('#' + $(this).attr('id')).length == 0) + $('div.post:first').prepend($(this).css('display', 'none').addClass('hidden')); + }); if(typeof window.enable_fa == 'function' && localStorage['forcedanon']) enable_fa(); -- cgit v1.3 From c36d654a083913d186442bb639212e9531b9dec1 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Sat, 17 Mar 2012 11:33:20 +1100 Subject: Clip post to page borders. --- js/post-hover.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'js/post-hover.js') diff --git a/js/post-hover.js b/js/post-hover.js index 68dfc98e..f6ac69aa 100644 --- a/js/post-hover.js +++ b/js/post-hover.js @@ -90,11 +90,20 @@ $(document).ready(function(){ if(!post) return; + var hover = $('#post-hover-' + id); + if(hover.length == 0) + return; + var top = (e.pageY ? e.pageY : hovered_at['y']) - 10; - $('#post-hover-' + id) - .css('left', (e.pageX ? e.pageX : hovered_at['x'])) - .css('top', top > $(window).scrollTop() ? top : $(window).scrollTop()); + if(e.pageY < $(window).scrollTop() + 15) { + top = $(window).scrollTop(); + } else if(e.pageY > $(window).scrollTop() + $(window).height() - hover.height() - 15) { + top = $(window).scrollTop() + $(window).height() - hover.height() - 15; + } + + + hover.css('left', (e.pageX ? e.pageX : hovered_at['x'])).css('top', top); }); }); }); -- cgit v1.3 From 21a1152ebead57c60c76c341d4f8ec8bc737949b Mon Sep 17 00:00:00 2001 From: Michael Save Date: Sun, 18 Mar 2012 23:55:01 +1100 Subject: custom event for new posts, so auto-reload.js etc will work with forced-anon.js and post-hover.js --- js/auto-reload.js | 3 ++- js/forced-anon.js | 42 ++++++++++++++++++++++++------------------ js/post-hover.js | 24 +++++++++++++++--------- 3 files changed, 41 insertions(+), 28 deletions(-) (limited to 'js/post-hover.js') diff --git a/js/auto-reload.js b/js/auto-reload.js index 0921c36d..44a4b9be 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -27,12 +27,13 @@ $(document).ready(function(){ var id = $(this).attr('id'); if($('#' + id).length == 0) { $(this).insertAfter($('div.post:last').next()).after('
'); + $(document).trigger('new_post', this); } }); } }); - poll_interval = setTimeout(poll, 5000); + poll_interval = setTimeout(poll, 500); }; $(window).scroll(function() { diff --git a/js/forced-anon.js b/js/forced-anon.js index 0f7f1c70..9b9df1eb 100644 --- a/js/forced-anon.js +++ b/js/forced-anon.js @@ -11,24 +11,26 @@ * */ -$(document).ready(function(){ - enable_fa = function() { - $('p.intro label').each(function() { - if($(this).children('a.capcode').length == 0) { - var id = $(this).parent().children('a.post_no:eq(1)').text(); - - if($(this).children('a.email').length != 0) - var p = $(this).children('a.email'); - else - var p = $(this); - - old_info[id] = {'name': p.children('span.name').text(), 'trip': p.children('span.trip').text()}; - - p.children('span.name').text('Anonymous'); - if(p.children('span.trip').length != 0) - p.children('span.trip').text(''); - } - }); +$(document).ready(function() { + var force_anon = function() { + if($(this).children('a.capcode').length == 0) { + var id = $(this).parent().children('a.post_no:eq(1)').text(); + + if($(this).children('a.email').length != 0) + var p = $(this).children('a.email'); + else + var p = $(this); + + old_info[id] = {'name': p.children('span.name').text(), 'trip': p.children('span.trip').text()}; + + p.children('span.name').text('Anonymous'); + if(p.children('span.trip').length != 0) + p.children('span.trip').text(''); + } + }; + + var enable_fa = function() { + $('p.intro label').each(force_anon); }; var disable_fa = function() { @@ -75,5 +77,9 @@ $(document).ready(function(){ if(forced_anon) enable_fa(); + $(document).bind('new_post', function(e, post) { + if(forced_anon) + $(post).find('p.intro label').each(force_anon); + }); }); diff --git a/js/post-hover.js b/js/post-hover.js index f6ac69aa..c76ca0d8 100644 --- a/js/post-hover.js +++ b/js/post-hover.js @@ -13,17 +13,19 @@ $(document).ready(function(){ var dont_fetch_again = []; - $('p.body a:not([rel="nofollow"])').each(function() { + var init_hover = function() { + var link = $(this); + var id; - if(id = $(this).text().match(/^>>(\d+)$/)) { + if(id = $(link).text().match(/^>>(\d+)$/)) { id = id[1]; } var post = false; var hovering = false; var hovered_at; - $(this).hover(function(e) { + $(link).hover(function(e) { hovering = true; hovered_at = {'x': e.pageX, 'y': e.pageY}; @@ -52,7 +54,7 @@ $(document).ready(function(){ start_hover(this); } else { var link = this; - var url = $(this).attr('href').replace(/#.*$/, ''); + var url = $(link).attr('href').replace(/#.*$/, ''); if($.inArray(url, dont_fetch_again) != -1) { return; @@ -64,13 +66,10 @@ $(document).ready(function(){ context: document.body, success: function(data) { $(data).find('div.post.reply').each(function() { - if($('#' + $(this).attr('id')).length == 0) - $('div.post:first').prepend($(this).css('display', 'none').addClass('hidden')); + if($('#' + $(link).attr('id')).length == 0) + $('div.post:first').prepend($(link).css('display', 'none').addClass('hidden')); }); - if(typeof window.enable_fa == 'function' && localStorage['forcedanon']) - enable_fa(); - post = $('div.post#reply_' + id); if(hovering && post.length > 0) start_hover(link); @@ -105,6 +104,13 @@ $(document).ready(function(){ hover.css('left', (e.pageX ? e.pageX : hovered_at['x'])).css('top', top); }); + }; + + $('p.body a:not([rel="nofollow"])').each(init_hover); + + // allow to work with auto-reload.js, etc. + $(document).bind('new_post', function(e, post) { + $(post).find('p.body a:not([rel="nofollow"])').each(init_hover); }); }); -- cgit v1.3 From 741e30e22fd05ebbb7eea969f919ea1573db815a Mon Sep 17 00:00:00 2001 From: Michael Save Date: Mon, 19 Mar 2012 00:11:55 +1100 Subject: post-hover.js: Fixed bug on index pages --- js/post-hover.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'js/post-hover.js') diff --git a/js/post-hover.js b/js/post-hover.js index c76ca0d8..7e085e97 100644 --- a/js/post-hover.js +++ b/js/post-hover.js @@ -53,8 +53,7 @@ $(document).ready(function(){ if(post.length > 0) { start_hover(this); } else { - var link = this; - var url = $(link).attr('href').replace(/#.*$/, ''); + var url = link.attr('href').replace(/#.*$/, ''); if($.inArray(url, dont_fetch_again) != -1) { return; @@ -66,13 +65,15 @@ $(document).ready(function(){ context: document.body, success: function(data) { $(data).find('div.post.reply').each(function() { - if($('#' + $(link).attr('id')).length == 0) - $('div.post:first').prepend($(link).css('display', 'none').addClass('hidden')); + if($('#' + $(this).attr('id')).length == 0) + $('div.post:first').prepend($(this).css('display', 'none').addClass('hidden')); + }); post = $('div.post#reply_' + id); - if(hovering && post.length > 0) + if(hovering && post.length > 0) { start_hover(link); + } } }); } -- cgit v1.3