Syncing toggle icons when collapsing / expanding multiple portlets at once
Not sure if this is the correct forum but I'm fairly new to JQuery so I think I'll fit right in. I've come pretty far with my coding but now I have encountered a problem I don't know how to solve and I have searched everywhere. Hope you can help.
So, I have created multiple expandable and collapsible portlets with plus / minus icon toggles. When I collapse or expand portlets individually the icons toggle correctly. I have added two buttons that expand or collapse all portlets respectively - again the icons toggle correctly. However, when I collapse one portlet and then collapse all portlets (using the button) the toggle icon for that particularly portlet will be out of sync.
How can I sync all the portlets so when they are collapsed there will always be a plus icon and vice versa?
My Code:
- $( ".portlet" )
- .addClass( "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" )
- .find( ".portlet-header" )
- .addClass( "ui-widget-header ui-corner-all" )
- .prepend( "<span class='ui-icon ui-icon-minusthick portlet-toggle'></span>");
- $( ".portlet-toggle" ).on( "click", function() {
- var icon = $( this );
- icon.toggleClass( "ui-icon-plusthick ui-icon-minusthick" );
- icon.closest( ".portlet" ).find( ".portlet-content" ).toggle("fast");
- });
/*This is the click.functions for the collapse / expand all buttons */
- $( "#expand-all" ).click(function() {
- $( ".portlet-content" ).show( "fast" );
- $( ".portlet-toggle" ).toggleClass( "ui-icon-plusthick ui-icon-minusthick");
- });
- $( "#collapse-all" ).click(function() {
- $( ".portlet-content" ).hide( "fast" );
- $( ".portlet-toggle" ).toggleClass( "ui-icon-minusthick ui-icon-plusthick");
- });
Thanks