How to open / close all toggles in one article?

Feel free to talk about everything related to our Wordpress Products
Rate this topic: Evaluations: 1, 6.00 on the average.Evaluations: 1, 6.00 on the average.Evaluations: 1, 6.00 on the average.Evaluations: 1, 6.00 on the average.Evaluations: 1, 6.00 on the average.Evaluations: 1, 6.00 on the average.6.00 out of 6 based on 1 vote(s)
GK User
Wed May 07, 2014 11:35 am
Hello,

Is there any option to open and close all toggles ( [toggle] ) in one article. For example I have 10 toggles in one article and I would like that users have the option to quickly open all oraz close all. You can see similar solution on Nokia website (Expnad all, Collapse all): http://developer.nokia.com/devices/devi ... ns/nokia-x
User avatar
Senior Boarder

GK User
Wed May 07, 2014 12:18 pm
It might be possible with some changes to [toggle] shortcode or by placing aditional html element and creating custom action in javascript.
Could You please post an url to your site to a place where you have the togglers, I'll check what can be done?
User avatar
Moderator

GK User
Wed May 07, 2014 2:41 pm
User avatar
Senior Boarder

GK User
Thu May 08, 2014 6:14 pm
What I would suggest is to create 2 links:
Code: Select all
<a href="#" class="closeAll">Close All</a>
<a href="#" class="openAll">Open All</a>

You can also style them somehow in css (as they should have unique classes.
Now in file:
wp-content/themes/Magazine/js/gk.scripts.js
just before last line:
Code: Select all
})();

please add this code:
Code: Select all
jQuery('.openAll').click(function(){
   jQuery('.gk-toggle').removeClass('closed').addClass('opened');
});
jQuery('.closeAll').click(function(){
   jQuery('.gk-toggle').removeClass('opened').addClass('closed');
});

User avatar
Moderator

GK User
Fri May 09, 2014 8:52 am
Thank you Cyberek. Your solution is working good.

I have only one question. When I click on Close All or Open All I am moved to the top of the page and I have to scroll down to see the togglers again. Is there any solution for this?
User avatar
Senior Boarder

GK User
Fri May 09, 2014 3:33 pm
Code: Select all
jQuery('.openAll').click(function(e){
   e.preventDefault();
   jQuery('.gk-toggle').removeClass('closed').addClass('opened');
});
jQuery('.closeAll').click(function(e){
   e.preventDefault();
   jQuery('.gk-toggle').removeClass('opened').addClass('closed');
});


Correct previous code with above one. Should fix the problem.
User avatar
Moderator

GK User
Mon May 12, 2014 8:16 am
Thank you! Everything is now working great.
User avatar
Senior Boarder

GK User
Mon May 12, 2014 3:59 pm
I'm glad I could help :).
User avatar
Moderator


cron