This is my solution to auto-hide/collapsible comments. This is probably not good enough for a patch, but it works... and if this is what you need, now you don't have to re-invent the wheel (-;

1. Alter vote_up_down.module v. 1.16.2.3, Add line one new, #478 to store the comment's score

    // Do the voting via voting api.
    if ($uid = _vote_up_down_get_uid()) {
      if ($vote->value == 0) {
        votingapi_unset_vote($type, $cid, $uid);
      }
      else {
        votingapi_set_vote($type, $cid, $vote, $uid);
      }
+      db_query("UPDATE {comments} SET score = $vote->value WHERE cid = %d", $cid);
    }

-------------

2. Add this to theme's page.tpl.php head, change div classes as req'd

<script type="text/javascript">
// <![CDATA[
   $(document).ready(function(){
    $('.comment .comment-body');
    $('.comment .title a').click(function() {
     $(this).parent().next(".comment-body").slideToggle('fast');
     return false;
    });
  });
// ]]>
</script>

there's probably a way to skip this step and use the default drupal collapsible js... anyone have a clue?

--------------

3. Add this line to the collapsible div in comment.tpl.php

<div <?php if ($comment->score < -2) print 'style="display: none;"'; ?> class="comment-body">

and you might need to add class="title" to the comment title div

optional: open style.css and add-> .comment .title a {display: block}
this will make the entire comment header clickable, rather than just the text of the title

Now when a page is loaded, all comments with a score of -2 only show the title, but the body is hidden. Clicking on comment titles javascript opens and closes them without needing a page refresh.

Comments

flaviovs’s picture

I think there's a bug in the first changeset. Here's a better version:

// Do the voting via voting api.
    if ($uid = _vote_up_down_get_uid()) {
      if ($vote->value == 0) {
        votingapi_unset_vote($type, $cid, $uid);
      }
      else {
        votingapi_set_vote($type, $cid, $vote, $uid);
      }
    }
+    if ( $type == 'comment' && $vote->value != 0 )
+      db_query("UPDATE {comments} SET score = score + $vote->value WHERE cid = %d", $cid);

ferrangil’s picture

Hi!
I was trying to do that, but I can't figure out where are you adding the line in the comment.tpl.php... I tried in several places (sometimes the comment dissapears, sometimes the title and the comment body dissapears... but I never get the title, clicable to expand the comment)...
I'm testing with a comment rated -3. I also have another comment below this one with no votes and it's always there.
Please could you give more detail in step 3??
Thanks

funana’s picture

Hi,

I tried it but the comments were still open. I could click the titles to open and close the comment body but that was not what it was supposed to do ;-)

Somebody here who knows how2?

justin3’s picture

look for something like this in comment.tpl.php

<div class="comment-body">

then insert this between div & class

<?php if ($comment->score < -2) print 'style="display: none;"'; ?> 

if your theme just has comment-content, fine, just you'll need to alter the .js code from above to match.

mrwhizkid’s picture

Version: 5.x-1.x-dev » 6.x-1.0-beta1

Could someone tell me how to do this in Drupal 6? This is a great idea but I just can't get it to work! Should I use the same code or something different?

marvil07’s picture

Status: Needs review » Closed (won't fix)

No more features to 6.x-1.x, please take a look to the update on the project page.

This feature is already on 2.x: #781546: Dim comments with [n] negative comments. It's no t exactly the same, but if you want collapsible please open another issue ;-) and if possible provide a patch