custom event for new posts, so auto-reload.js etc will work with forced-anon.js and post-hover.js

This commit is contained in:
Michael Save 2012-03-18 23:55:01 +11:00
parent 8208d7151b
commit 21a1152ebe
3 changed files with 41 additions and 28 deletions

View File

@ -27,12 +27,13 @@ $(document).ready(function(){
var id = $(this).attr('id'); var id = $(this).attr('id');
if($('#' + id).length == 0) { if($('#' + id).length == 0) {
$(this).insertAfter($('div.post:last').next()).after('<br class="clear">'); $(this).insertAfter($('div.post:last').next()).after('<br class="clear">');
$(document).trigger('new_post', this);
} }
}); });
} }
}); });
poll_interval = setTimeout(poll, 5000); poll_interval = setTimeout(poll, 500);
}; };
$(window).scroll(function() { $(window).scroll(function() {

View File

@ -11,24 +11,26 @@
* *
*/ */
$(document).ready(function(){ $(document).ready(function() {
enable_fa = function() { var force_anon = function() {
$('p.intro label').each(function() { if($(this).children('a.capcode').length == 0) {
if($(this).children('a.capcode').length == 0) { var id = $(this).parent().children('a.post_no:eq(1)').text();
var id = $(this).parent().children('a.post_no:eq(1)').text();
if($(this).children('a.email').length != 0)
if($(this).children('a.email').length != 0) var p = $(this).children('a.email');
var p = $(this).children('a.email'); else
else var p = $(this);
var p = $(this);
old_info[id] = {'name': p.children('span.name').text(), 'trip': p.children('span.trip').text()};
old_info[id] = {'name': p.children('span.name').text(), 'trip': p.children('span.trip').text()};
p.children('span.name').text('Anonymous');
p.children('span.name').text('Anonymous'); if(p.children('span.trip').length != 0)
if(p.children('span.trip').length != 0) p.children('span.trip').text('');
p.children('span.trip').text(''); }
} };
});
var enable_fa = function() {
$('p.intro label').each(force_anon);
}; };
var disable_fa = function() { var disable_fa = function() {
@ -75,5 +77,9 @@ $(document).ready(function(){
if(forced_anon) if(forced_anon)
enable_fa(); enable_fa();
$(document).bind('new_post', function(e, post) {
if(forced_anon)
$(post).find('p.intro label').each(force_anon);
});
}); });

View File

@ -13,17 +13,19 @@
$(document).ready(function(){ $(document).ready(function(){
var dont_fetch_again = []; var dont_fetch_again = [];
$('p.body a:not([rel="nofollow"])').each(function() { var init_hover = function() {
var link = $(this);
var id; var id;
if(id = $(this).text().match(/^>>(\d+)$/)) { if(id = $(link).text().match(/^>>(\d+)$/)) {
id = id[1]; id = id[1];
} }
var post = false; var post = false;
var hovering = false; var hovering = false;
var hovered_at; var hovered_at;
$(this).hover(function(e) { $(link).hover(function(e) {
hovering = true; hovering = true;
hovered_at = {'x': e.pageX, 'y': e.pageY}; hovered_at = {'x': e.pageX, 'y': e.pageY};
@ -52,7 +54,7 @@ $(document).ready(function(){
start_hover(this); start_hover(this);
} else { } else {
var link = this; var link = this;
var url = $(this).attr('href').replace(/#.*$/, ''); var url = $(link).attr('href').replace(/#.*$/, '');
if($.inArray(url, dont_fetch_again) != -1) { if($.inArray(url, dont_fetch_again) != -1) {
return; return;
@ -64,13 +66,10 @@ $(document).ready(function(){
context: document.body, context: document.body,
success: function(data) { success: function(data) {
$(data).find('div.post.reply').each(function() { $(data).find('div.post.reply').each(function() {
if($('#' + $(this).attr('id')).length == 0) if($('#' + $(link).attr('id')).length == 0)
$('div.post:first').prepend($(this).css('display', 'none').addClass('hidden')); $('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); post = $('div.post#reply_' + id);
if(hovering && post.length > 0) if(hovering && post.length > 0)
start_hover(link); start_hover(link);
@ -105,6 +104,13 @@ $(document).ready(function(){
hover.css('left', (e.pageX ? e.pageX : hovered_at['x'])).css('top', top); 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);
}); });
}); });