开发者

modify the comment reply link

开发者 https://www.devze.com 2023-01-23 15:22 出处:网络
now, i want to modify the comment reply link,the effect开发者_JAVA技巧 which i love is like the wordpress\'s. when i click the \"reply\" link. it takes me to the comment box which at the bottom of the

now, i want to modify the comment reply link,the effect开发者_JAVA技巧 which i love is like the wordpress's. when i click the "reply" link. it takes me to the comment box which at the bottom of the page.just like the name anchor. not taking me to a new page, any tips would be appreciated.


use ajax_comments


First, go to the Edit page of your Content Type. Then, find the "Comment Settings", and put the option "Location of comment submission form" on "Display below post or comments"

Edit your suiting node template file, and print a reply link, like for example :

<a href="#addComment"><?php print t('Add Comment'); ?></a>

Add some funky jQuery to the link, to scroll to the Form for example, and you're off. For example :

Drupal.behaviors.initCommentLink = function(context) {
  // Hide the comment form
  $('#comment-form').hide(); 

  // Add click handler to our custom relpy link
  $('a[href=#addComment]').click(function(){
    $('#comment-form').fadeIn('slow');
    var targetOffset = $('#comment-form').offset().top;
    $('html,body').animate({
      scrollTop : targetOffset
    },'slow');
    $(this).fadeOut('fast');
  }); 
}

If all goes well, you should now see a Reply link, but no Comment Form. Clicking on the Reply link should make the Comment form appear, and make the Page scroll to the Form. In addition, the Reply link should be hidden after clicking it.

If you don't know jQuery, no worries, the code should work if you put it in a regular JS file, just make sure that it is included. To make sure of that, put it in the JS file that you have in your theme.


You can setup that file like so

$nid = arg(1);
$node = node_load($nid);
$node->comment = COMMENT_NODE_READ_WRITE;
$commentLink = comment_link('node',$node);

You can test for login status etc here too and place it in your view.

0

精彩评论

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