I am writing a user macro and part of the code is going to target the active page in the page tree (which uses the {pagetree} macro) and apply some simple styling to it.
The code is as follows:
#set ($activePage = "#childrenspan$content.getIdAsString()-0") <script type="text/javascript"> var AP = '${activePage}'; jQuery(AP).addClass('activePage'); </script>
As you can see it's a mixture of VTL and JS - the VTL sets a variable and passes it to the JS, which is basically the ID for the current page in the page tree.
However, it is running before the page tree has loaded. This means that it's effectively returning nothing. If you run the code in the developer console after the page has finished loading then it works.
So the question is, how can I run some JS after the {pagetree} macro has finished loading?
Here I shall add a completely horrible hacky solution, in the hope that its sheer hackiness encourages somebody from Atlassian to suggest the correct way to do this!
Add a script at the end of your page HEAD:
var oldInit = AJS.toInit; AJS.toInit = function(A) { oldInit(A); // Do some code of our own var AP = '${activePage}'; jQuery(AP).addClass('activePage'); };
Since this code runs before the pagetree plugin is invoked (in batch.js), we hijack the onInit function to add our own code to run at the end.
(can't seem to delete)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As I can't edit my post, that should say "but it didn't have an effect".
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.