I have stolen a user macro for "Expand All" from this forum, but my users have asked if it is possible to make the text in the button change based on the state of the page.
So it toggles between "Expand" or "Collapse" based on whether the button has been clicked.
This is the macro I have used, but not sure how to change to get dynamic button name:
## Macro title: Expand All
## Macro has a body: N
## Developed by: George Lewe
## Date created: 2014-09-22
## Installed by: George Lewe
## @noparams
<p align="left"><button name="toggleAll" id="toggleAll" type="button" class="aui-button" aria-pressed="false" style="background-color:blue;color:white;font-weight:bold">Expand All / Collapse All</button></p>
<script type="text/javascript">
AJS.toInit(function ()
{
AJS.$('#toggleAll').click(function()
{
var expanded = jQuery(".expand-icon.aui-iconfont-chevron-down").closest("div");
var unexpanded = jQuery(".expand-icon.aui-iconfont-chevron-right").closest("div");
if (expanded.size() > unexpanded.size()) {
expanded.each(function(){ jQuery(this).trigger("click");})
} else {
unexpanded.each(function(){ jQuery(this).trigger("click");})
}
});
});
</script>
@Stewart Eade which button in trello are you trying to change? i could probably make something with PixieBrix that changes the text of the button when its clicked, but to show an example I'd need to know which button you're talking about
Thanks for your response. I managed to work it out and the new code (shown in BOLD) below:-
## Macro title: Expand All
## Macro has a body: N
## Developed by: George Lewe
## Date created: 2014-09-22
## Installed by: George Lewe
## @noparams
<p align="left"><button name="toggleAll" id="toggleAll" type="button" class="aui-button" aria-pressed="false" style="background-color:blue;color:white;font-weight:bold">Expand All</button></p>
<script type="text/javascript">
const btn = document.getElementById("toggleAll");
AJS.toInit(function ()
{
AJS.$('#toggleAll').click(function()
{
var expanded = jQuery(".expand-icon.aui-iconfont-chevron-down").closest("div");
var unexpanded = jQuery(".expand-icon.aui-iconfont-chevron-right").closest("div");
if (expanded.size() > unexpanded.size()) {
expanded.each(function(){ jQuery(this).trigger("click");
btn.innerText = "Expand All";})
} else {
unexpanded.each(function(){ jQuery(this).trigger("click");
btn.innerText = "Collapse All";})
}
});
});
</script>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.