How to create an "Expand All" button for Confluence

Hi

I've been using the expand macro a lot to organise my data (like a faq) but and am now having trouble searching for things (using the quick search). I can use the quick search to locate the page I'm after. But then I need to manually toggle open each and every expand field, before I can use the normal cntrl-f to find what I'm looking for.

Does anyone know of a way I can install an addon with this Expand All feature, or possibly a way to code my own macro?

A massive thanks in advance for helping!

Tim

8 answers

1 accepted

This widget could not be displayed.

Discused in the documention - not a macro, but a javscript solution.

https://confluence.atlassian.com/display/DOC/Expand+Macro?focusedCommentId=452100227#comment-452100227

Thanks Ernie, your comments and code is really helpful.
This should be all we need for now!

this links directs to the confluence documentation

yeah, I wish I were able to see the javascript solution that Timothy finds so helpful.  This documentation page is exactly the opposite of what I'm looking for: it shows how to implement the "expand" section that I find so annoying!

This widget could not be displayed.

hello , i don't know if you find the solution but after looking in to a lot of pages i tried this and it work :

1- first create user macro:

general configuration -> user macro >create a user Macro

name your macro expandall then past this and save it :

 

## Macro title: Expand All
## Macro has a body: N
## Developed by: George Lewe
## Date created: 2014-09-22
## Installed by: George Lewe
## @noparams
<a id="toggleAll" href="#">Expand/Collapse All</a>
<script type="text/javascript">
AJS.toInit(function ()
{
AJS.$('#toggleAll').click(function()
{
jQuery(".expand-control").each(function(){ jQuery(this).trigger("click");})
});
});
</script>
2-if you want to put this macro on one page you can just do this 
{expandall} 

but if you want to add this to all pages in the confluence :

go to look and feel -> layout -> page layout -> add it where you want  :

    #set($helper = $action.helper)

   $helper.renderConfluenceMacro("{expandall}")
Thank you, 
Amna 

 

 

 

That was exactly what we needed, worked like a charm ... you rock, Amna!

Hi, Is there another way to add this to all pages when you use the Documentation theme as I get a message "You can not customise the site look and feel while a theme is active. You must first disable the currently configured theme."? Thanks

This was great.  Worked perfectly.

No need for jQuery, you can do this in plain ES6 these days:

[].forEach.call(document.querySelectorAll('.expand-control'), x => x.click())
This widget could not be displayed.
No user macro required. Stick this at the bottom of the page in an HTML macro and you're done.
<script type="text/javascript">
AJS.toInit(function() {
	$(".expand-control").trigger('click');
});
</script>

Works like a charm!

Works brilliant but note that if you have more than one expand macro on the page all will be open. Any solution to do that?

$(".expand-control").first().trigger('click');

 I only wanted to expand my first block and altered the code this way....Thanks David May

This widget could not be displayed.

Step 1: Insert a html macro. 

 

Step 2 : Paste the following. 

 

<a id="toggleAll" href="#">Expand/Collapse All sections</a>
<script type="text/javascript">
AJS.toInit(function ()
{
AJS.$('#toggleAll').click(function()
{
jQuery(".expand-control").each(function(){ jQuery(this).trigger("click");})
});
});
</script>

 

Step 3: Throw the feet up smile

Threw my feet up. Yay!

Thanks a lot.

I wish I could use an HTML macro, but this feature is not enabled and it seems to require system-administrator privilege. I sure wish Confluence was not so restrictive. Thanks for the tip.

Brilliant, Ben! I just tweaked the first line of your HTML to use a <button> element instead of an <a href> element:

<p align="center"><button name="toggleAll" id="toggleAll" type:"button">Expand/Collapse All Sections</button></p>

This makes a nifty centered button, and also doesn't alter the URL in the browser address bar. Everything otherwise works the same as the code you so kindly posted.

Thanks again!

Ack. Welcome to the neighborhood... I just realized there's a minor typo ("type:" instead of "type=") in the sample I posted yesterday. The sample still works, despite the typo, but it's annoying to an OCD type like myself. Here's an updated sample that uses the "=" sign consistently:

<p align="center"><button name="toggleAll" id="toggleAll" type="button">Expand/Collapse All Sections</button></p>

Thanks for listening.

Hi, wondering how to do this for a single, specific, expand macro?  Basically i'm just looking to "replace" the clickable text "Click here to expand..." with a button to do the same?  I'm fairly new to JavaScript and jQuery but i was thinking:  instead of the ".each" in the jQuery and replace it with something static, like macro-id....but no luck.

Any thoughts? 

This widget could not be displayed.

Thanks for that Chung, however this seems different from the usual {expand} macro that comes with confluence. Do you know how to do the same thing with the {expand} macro?

I don't think so you can do so. IMO, the expand macro is used to expand 'part by part' - if you want to choose to expand all, you can put all information into one single expand (that defeats its purpose).

Yep I think you are right, that would defeat the purpose.
So in summary, I definitely cannot create my own user macro to do this?

This widget could not be displayed.

Documention for toggle all - not a macro, but a javscript solution.

https://confluence.atlassian.com/display/DOC/Expand+Macro?focusedCommentId=452100227#comment-452100227

This widget could not be displayed.

If you can edit the page then you can search the content without the need for any macro.

This widget could not be displayed.
Ray K. I'm New Here Jul 11, 2018

Is there a way to do this for UI-Expand (NOT regular Expand)?

Ray K. I'm New Here Jul 11, 2018

Never mind, I figured it out!  The UI-Expand class name is "rwui_expand"!

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published Jul 30, 2018 in Confluence

How Manon Soubies-Camy uses Confluence + Trello to organize webinar notes and her knitting stash

@Manon Soubies-Camy is an engineer who has been an avid Atlassian user since 2014. She helps companies of all sizes transform the way they work with the Atlassian stack, including Jira and Confl...

850 views 8 13
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you