Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Comment | File | Size | Author |
---|---|---|---|
#24 | ajax_comments-fix_position-2679879-24.patch | 646 bytes | zahord |
Comments
Comment #2
snig CreditAttribution: snig as a volunteer and commentedComment #3
snig CreditAttribution: snig as a volunteer and at DevBranch for DevBranch commentedComment #4
formatC'vt CreditAttribution: formatC'vt commentedConfirm bug.
Patch makes duplicates of comments.
Comment #5
kandrupaler CreditAttribution: kandrupaler commentedHi guys, I'm glad I'm not the only one facing this problem. Was freaking out thinking it's something I've done! But I have good news. Maybe.
@formatC'vt Thanks for the patch. I tried it out and it indeed makes duplicates everywhere. In your patch, replacing...
with:
Solves the problem...!!!
Can you pls check? I'm not an expert in PHP or JS or AJAX (or anything, for that matter!), but I was trying to solve this problem come what may. It seems to work for me...
Comment #6
formatC'vt CreditAttribution: formatC'vt commentedthanks, needs review
Comment #7
jmato CreditAttribution: jmato commentedI'm facing the same problem, i think the cause of the comment duplication it's that the chosen selectors are incorrect, the correct selectors would be either.comment-wrapper-nid-x > .ajax-comment-wrapper:last
OR.comment-wrapper-nid-x > .indented:last
, but not the two at the same time, why? because the selector needs to match only one element, matching more than one element will add the comment after every matched element.In my case the container with the replies to a comment (with the class .indented) its on the same level of the DOM structure than the comment, i don't know if that change according to the theme or other factors, example of the structure.In the @snig patch the code is adding the posted comment after every first level comment for the first selector and after every first level of reply to any first level comment for the second selector.In the solution proposed by @kandrupaler the first selector,.comment-wrapper-nid-x > .ajax-comment-wrapper:last
will match only the last first level comment and all the first level replies to a first level comment for the second selector.I can't find a way to build a selector without making a database query, at least on the php code, in the js code it's possible, but looking the super clean js code i thought the developers left the logic for the server side.The solution I've found was fetch the last two comments for the node from the database, the last its the posted comment, the previous it's was the last comment before the posted one, in the previous comment we look the value of the comment pid, if it's 0 then we are at a first level comment, then we use the
.comment-wrapper-nid-x > .ajax-comment-wrapper:last
selector, if it's different than 0 then we are facing a reply, the we use the.comment-wrapper-nid-x > .indented:last
selector, example of code:insert on line 382r = replace, i = insertI'm not uploading a patch right now because I don't know if will work with pagination and other stuff, maybe in a few days, anyway, hope that helps.Edit: Didn't see that the @snig patch also was modifying the ajax_comments.js file :(
Comment #8
kandrupaler CreditAttribution: kandrupaler commented@jmato - thanks for looking into this. You say -
Maybe I don't get it, but my fix is working with comments at all positions and levels. I just tried replying to a 3rd-level reply of a 1st-level comment which is neither first nor last, and it worked.
To make things more clear, I added the comment "reddester" below and my fix worked perfectly.
What am I missing?
Edit: I'm displaying AJAX comments in a view using the "List Comments" feature.
Comment #9
AsadKamil CreditAttribution: AsadKamil at Valuebound commentedThe patch applied cleanly.
Thanks
Comment #10
kandrupaler CreditAttribution: kandrupaler commented@AsadKamil, the patch can be applied, of course, but it has issues.
Comment #11
jmato CreditAttribution: jmato commented@kandrupaler I don't know if it happens with views (i using commentsblock to display comments) but the problem for me arises only with first level comments, replies are displayed fine.
Can you test adding a new first level comment with a reply as the last comment displayed? BTW my fix don't work with pagination :)
Edit: Can you post the HTML structure with the relevant classes as I did in the previous comment? example:
Comment #12
kandrupaler CreditAttribution: kandrupaler commented@jmato, OOPS! You're right, my fix isn't a fix:-)
The AJAX was adding the comment in the right place, but after a page refresh, reddester has landed itself in the blue area (I didn't have any replies to "Blue"):
So apart from pagination (which I don't care about right now) your patch works perfectly?
Comment #13
jmato CreditAttribution: jmato commented@kandrupaler OOOOPS too, now thinking that your fix it's actually a fix, I didn't see that the original patch also was patching the ajax_comments.js file and that changes all, I will do some testing later.
Comment #14
jmato CreditAttribution: jmato commented@kandrupaler I've do some testing, the @snig patch it's working well, inserting the comment in the correct place, not making duplicates and neither the replying problem you mentioned it's happening here, a views related issue?
Comment #15
kandrupaler CreditAttribution: kandrupaler commented@Jmato, views + ajax_comments definitely has this problem. I haven't tested this without views. This problem is making me question whether we need indented/threaded replies in the first place. On the whole, lots of issues using this module. I did think of switching over to facebook commenting instead of this, but that defeats our purpose of having more registrations.
Comment #16
jmato CreditAttribution: jmato commented@kandrupaler, can you post the code of the view you are using to show the comments? you can see the code by exporting the view.
Comment #17
snig CreditAttribution: snig as a volunteer and at DevBranch for DevBranch commentedI can't reproduce any duplications
Comment #18
kandrupaler CreditAttribution: kandrupaler commented@snig I'm seeing duplication when using views.
Comment #19
pmusaraj CreditAttribution: pmusaraj commentedHere is a smaller patch that avoids any chances of duplication by simply targeting the last
div
regardless of its class name.Comment #20
qzmenko@pmusaraj not good solution. Because in default template file comment-wrapper.tpl.php last div element would be wrapper of comment form. And comments would be inserted after form.
Comment #21
zahord CreditAttribution: zahord as a volunteer and at Skilld commentedHi all,
I added a fix to solve the issue with the comments positions, I hope this can help
Regards!
Comment #22
zahord CreditAttribution: zahord as a volunteer and at Skilld commentedComment #23
zahord CreditAttribution: zahord as a volunteer and at Skilld commentedUpdated file
Comment #24
zahord CreditAttribution: zahord as a volunteer and at Skilld commentedI'm adding a new patch with the selector to detect the position updated
Comment #25
qzmenkoHello @zahord.
I still believe that it's not very good to rely on the h2 tag, as many developers replace it with another tag in custom comment template.
Comment #27
qzmenkoFixed in dev branch.