开发者

Help me diagnose this jQuery loop / Bookmark Hash problem?

I'm having some trouble getting my jquery to render correctly 100% of the time - the code I am using is located below. Its purpose is to "simulate" the feel of a threaded forum by hiding everything but the subject of replies - when a subject is clicked, the 1st post is then replaced with the reply.

You can see an example of it in action here:

http://bulldogsworld.com/general-bulldog-chat/50-lbs-bulldog-one-shin-pic

The problem is the script doesn't work so well when people land via a bookmark # in the URL, such as: http://bulldogsworld.com/general-bulldog-chat/50-lbs-bulldog-one-shin-pic#comment-1627028

Specifically, the problem which happens is for some reason all posts below the bookmark entry point are replicated twice. I can't figure out why this is happening - any thoughts?

I'm pulling my hair out on this one - Any help / guidance is greatly appreciated!

function flip(comment) {
$('#first-post').replaceWith(comment.closest(".comment").clone().attr('id','first-post'));
$('#first-post').children('.forumthreadtitle').children('.comment-info').empty();
$('#first-post').find(':hidden').fadeIn('slow');
$('html, body').animate({scrollTop:0}, 'fast');
return false;
}

$(document).ready(
function(){ 

$('.submitted').each(function() {
$(this).clone().addClass('comment-info').appendTo($(this).siblings('.forumthreadtitle'));
if(!$(this).parent('#first-post').html()) {
    $('#first-post').children('span.taxonomy').clone().appendTo($(this));
    }
});

$('.display_mode').html('Show All Replies');
expandedMode = false;
$('.display_mode').click(function() {
    if ( expandedMode  == false  ) {
        $('.forumthreadtitle').siblings().show(); 
        $(this).html('Collapse Replies');
        expandedMode  = true;
        }
    else
        {
        $('.forumthreadtitle').siblings().hide();
        $(this).html('Show All Replies');
        expandedMode = false; 
        }
    });

$('.forumthreadtitle').siblings().hide();

if(window.locatio开发者_开发问答n.hash) {
        flip($(window.location.hash).nextAll().children('.forumthreadtitle').show());
        }

$('.forumthreadtitle').click(function() { 
    pageTracker._trackPageview("/comment?page=" + document.location.pathname);
    flip($(this)); 
    } );
});


You probably need to use next() instead of nextAll() in your flip

flip($(window.location.hash).next().children('.forumthreadtitle').show());

nextAll() returns all elements after selected, and they all are passed to flip function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜