Yii Framework Forum: Toggling a DIV at the time - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Toggling a DIV at the time Rate Topic: -----

#1 User is offline   Rosimildo 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 22-February 10

Posted 15 March 2010 - 10:27 AM

Hi there,
How do I display a list of things, example the "Posts" of the blog demo, but showing only the titles, but the content collapsed, and with a click being able to expand them back and forth, one at the time.

Thanks for you help!
0

#2 User is offline   Matt Kelliher 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 12-February 10
  • Location:Tampa, FL

Posted 15 March 2010 - 11:14 AM

First off, maybe you can use CJuiAccordion.

Otherwise, just output the blogs like normal, and say for instance your view is like this:
<div class="blog">
  <h2><a class="title" href="path/to/blog">Blog Title</a></h2>
  <div class="content">
    Blog content...
  </div>
</div>


Using Javascript, turn each blog post into an object having a collapsed/open state, and set the blog link to toggle the state. There are probably cleaner ways of doing it than this, but for the sake of example:

<?php
Yii::app()->clientScript->registerScript('blogCollapse',
  "$(document).ready(function() {
        $('div.blog').each(function() {
           new Blog(this);
        });
    });

    Blog = function (o) {
        this.hidden = false;
        this.target = $('div.content', o);
        var blog = this;

        blog.target.hide();

        $('a.title', o).click(function() {
            blog.Toggle();
            return false;
        });

    }

    Blog.prototype.Toggle = function() {
      if (this.hidden) {
        this.target.slideUp('fast');
        this.hidden = false;
      }
      else {
        this.target.slideDown('fast');
        this.hidden = true;
      }
    }
  ",
  CClientScript::POS_END
);
?>

0

#3 User is offline   Rosimildo 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 22-February 10

Posted 15 March 2010 - 11:35 AM

thanks. I will study that widget.

Thanks a lot.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users