From 21a1152ebead57c60c76c341d4f8ec8bc737949b Mon Sep 17 00:00:00 2001 From: Michael Save Date: Sun, 18 Mar 2012 23:55:01 +1100 Subject: [PATCH] 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(-) 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); }); });