Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Triggering 'read more/less' behavior using some other link or button click? #14

Closed
rutwick opened this issue Sep 19, 2011 · 3 comments
Closed

Comments

@rutwick
Copy link

rutwick commented Sep 19, 2011

Hi,

Can I trigger the 'read more' / 'read less' behavior using some other link in my mark-up and passing it's class to the function?
I'm using the plugin to expand the content of a div, and at the same time I'm using fadeOut to reveal 6 more divs below this div. Now the 'read less' button still appears at the same position, in the top div, where the viewer would have to click it to hide the content and the rest of the divs. If I can append a 'read less' link to the bottom of the last div, and trigger the 'read less' behavior by clicking it, it would look neater! I tried appending a similar span > link markup with the same classes as the plugin generates, but it doesn't work.

Any ideas how I can do it ?

Thanks for any help!

Rutwick

@kyds3k
Copy link

kyds3k commented Sep 22, 2011

I need to do the same thing! Any ideas?

@rutwick
Copy link
Author

rutwick commented Sep 23, 2011

Hi,
I checked out the code, there's an event 'click.expander' used. I used it with a link to write my custom jQuery code, and it worked, but only for opening the content! Tried a lot so that it could work for closing, but didn't!
Say your link is 'Open
Then the jQuery would be:

jQuery('#link').bind('click.expander', function(){
    //do stuff here, like opening the divs you want, then remove the link and append it to the last div. Bind the event to it again.
});

This worked for opening the content with my custom link, but not for closing it.

@rutwick rutwick closed this as completed Sep 23, 2011
@rutwick rutwick reopened this Sep 23, 2011
@denomales
Copy link

to do both the expander and collapser I first added two links on the page

<a href=# class='ExpandAll'>Expand All</a>
<a href=# class='CollapseAll'>Collapse All</a>

Then added the following to my ready jquery

$('a.ExpandAll').click(function(event){
    event.preventDefault();
    $('span.read-more a').each(function(){
        $(this).click();
        })
        ;
    })
    ;
$('a.CollapseAll').click(function(event){
    event.preventDefault();
    $('span.read-less a').each(function(){
        $(this).click();
        })
        ;
    })
    ;

Basically when each link is clicked, its function iterates through all the expander read-more or read-less links and triggers the click event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants