views:

58

answers:

2

I've been struggling with a feature I've been trying to create for sometime. The idea here is that the user sees the little thumbnail + headline, as well as the Posted By information. They can then click on the headline to expand to the article or click on the "Comments" link to expand directly to the comments made on the article. Or, if they want they can view comments by clicking on the headline(to expand to the article), then click on View Comments (to expand to the comments). In the end, a modular yet flexible and functional open/close system to view latest news.

Here is what I've been working on: (I put all my code in one place so its easier on whomever may look at this to view) http://notedls.com/pointtest.html

This is what I'm shooting for, but it's far from what I want ;( It's using the jQuery 1.6 plugin, which 1.8 is out but I'm far from being a master or expert at this and I don't think I could build from the ground up. I've already edited this plugin to get it to work like this, but as you can see, the AUTHOR and Comments start making shit hit the fan ;; It's because the code is calling the "A TAG" for the header; which is the headline.

Does anyone know any easier way to achieve what I'm envisioning or possible a way to fix this current code? I'm pretty desperate at this point ;;

A: 

oh, i feel i get it

$('.author').click(function() {
    $(this).parent().find('.authordiv').toggleClass('hidden');
});
$('.comments').click(function() {
    $(this).parent().find('.commentsdiv').toggleClass('hidden');
});

and use hidden css class

.hidden {
    display:none;
}
vittore
A: 

Something like this:?

http://jsbin.com/elawu

alt text

It's an accordion. Each "first element", or header, is a div. Within that header is an article headline, an author, and a clickable span listing the number of comments for that article.

Each "second element", or content portion of the accordion, is also a div. Within that div there is an article content div, and comments div. Within the comments div there is a comment header, again clickable, and another content div. The hierarchy looks like this:

<div id='outer-accordion'>
   <div class='header'>
      <p>Article headline</p>
      <p>by: Author</p>
      <p><span class='clickable'># comments</span></p>
   </div>
   <div class='content'>
      <div class='article'>...</div>
      <div class='comments'>
        <p><span class='clickable'># of comments</span></p>
        <div class='comment-content'>
           comment #1
           comment #2
           ...
        </div>
      </div>
   </div>

   ....

When the page starts all the comment content divs get hidden via $('div.comments div').hide(); Also the accordion gets set up, and the accordion onaccordionchange and onaccordionchangestart events get bound. Finally, a click event is registered for the Comments links.

If you click anywhere on the header, it pops open the associated accordion content tab. If you click on the comments link in the header, it opens the accordion, and opens the comments div within the content div.

Any time an accordion tab gets opened, the comments link in the header gets hidden. Any time an accordion tab closes, the comments link in the header gets shown.

Clicking on the comments link within the accordion content div, toggles the actual comments.

Cheeso
Omg yes! You sir, are a savior! Thanks!
Josh
Actually I do have a question, since you have the links reacting this way, I'm assuming if I make the author a link it will open up the article like its being told to, what if I wanted to direct the author link to a completely different page?
Josh
Clicking the "comments" link causes the accordion tab to open, because the comments link lies within the "first element", and clicking anywhere in the first element causes the accordion tab to open. You can see from the code that I registered an additional click event for the "comments" link - it just sets a flag that is then referenced in the accordion `onaccordionchange` event. You'd have to set up a similar click event for the author. You may also want to suppress the accordion activation when the author gets clicked - not sure how. Seems possible. I'll let you figure that part out.
Cheeso
Thanks a bunch!
Josh