I am trying to get the comments on my website to change color when they are active. More specifically, I am looking to do something very similar to what StackExchange sites do when you click on a notification in your inbox (like this). So what I initially tried to do, was to wrap the comment class in another div class called comment_active
using an if
statement to see whether the current page url contained the string "#comment-". (being that the permalink for a comment is /node/nid#comment-cid
I am trying to get drupal to know what the current cid is) I am having some problems figuring out how to do this. Is placing, for example #comment-1
even part of the url? or does it just bring you to the part of the page that contains that element id? is there a way that I can have the comment.tpl.php know whether a comment is active? Or should I be doing it some other way entirely?
Add a comment
|
1 Answer
Try to add a custom javascript file to in theme.info file
jQuery(document).ready(function() {
//get the current path
var pathname = window.location.hash;
jQuery(pathname).next().addClass('active-comment');
//here add your custom animation
jQuery('.active-comment').fadeOut().fadeIn().fadeOut().fadeIn().fadeOut().fadeIn().fadeOut().fadeIn().fadeOut().fadeIn().fadeOut().fadeIn().fadeOut().fadeIn().fadeOut().fadeIn();
});
here is a plugin to animate the background color of the wrapper :here
Hope this will Help You
-
I'm confused as to what this does. does this add the class
active_comment
to the.comment_class
? or does this create a class for every element with anid
?– EphraimCommented Mar 30, 2012 at 18:18 -
I forgot to add .next() , because the structure of drupal comment is <a href='#idofcomment'></a><div class="wrapperofcomment"></div>, now the code above will add the class to the comment wrapper instead of adding it to the <a> , Commented Mar 30, 2012 at 18:48
-
I added a comments.js file with that code, and pointed to it in the theme.info file, but it doesn't seem to working. Is there something else I'm supposed to be doing, I'm new to jquery with drupal. Also, when I look up online on how to use jquery with drupal,other people seem to be using
JQuery();
instead of$()
. Does that make a difference hear at all. I'm using drupal 7.12– EphraimCommented Mar 30, 2012 at 21:42 -
Out of curiosity, would there also be a way to do this using php?– EphraimCommented Mar 30, 2012 at 22:54
-
I've updated my code snippets , and it's a tested code and working for me Commented Mar 31, 2012 at 4:07