Skip to content

Instantly share code, notes, and snippets.

@timaschew
Last active May 19, 2016 09:44
Show Gist options
  • Save timaschew/5947188 to your computer and use it in GitHub Desktop.
Save timaschew/5947188 to your computer and use it in GitHub Desktop.
expand children pages in pagetree for current page. Put this into the textarea of: Confluence Admin -> LOOK AND FEEL -> Custom HTML -> At end of the HEAD
<!--
Original snippet is from
http://www.communardo.de/home/techblog/2011/05/02/improve-the-confluence-pagetree-macro-functionality/
-->
<script type="text/javascript" >
AJS.toInit(function ($) {
//first save the original pagetree function "origHideEmptyChildrenContainer"
var origHideEmptyChildrenContainer = AJS.pagetree.hideEmptyChildrenContainers;
//define our own one and overwrite the original pagetree function "hideEmptyChildrenContainers"
//this function is called by the pagetree after children loading
AJS.pagetree.hideEmptyChildrenContainers = function(pagetreeChildrenDiv) {
//search for the child element with the style attribute
pagetreeChildrenDiv.find('span.plugin_pagetree_children_span').each(function(index, item){
//click on the plus icon to expand the children of the current page
// confluence 4.x
//jQuery(this).parent().parent().find('.plugin_pagetree_childtoggle_container a.icon-plus').trigger('click');
// confluence 5.x
var elem = jQuery(item);
// do not toggle the parent of a childs, if child the current page
if (elem.parent().next().find('.plugin_pagetree_children_span.plugin_pagetree_current').length === 0) {
jQuery(this).parent().parent().find('.plugin_pagetree_childtoggle_container a.plugin_pagetree_childtoggle').trigger('click');
}
});
//call the saved original function...
origHideEmptyChildrenContainer(pagetreeChildrenDiv);
};
});
</script>
@gdhaworth
Copy link

I created an updated version that works with Confluence 5.5.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment