Why is my custom JavaScript not working in Confluence?

As a workaround for this bug: https://jira.atlassian.com/browse/CONF-33273

I'm trying to run the following JS via the "Custom HTML" at the end of HEAD:

<script type="text/javascript">
AJS.toInit(function(){
    AJS.$("#rte-button-publish").attr('data-tooltip','(Ctrl + S)');
});
</script>

I've run the JS via console and it works but it doesn't seem to get loaded directly on the page and I cannot figure out why since I followed this https://confluence.atlassian.com/display/CONFKB/How+to+Use+JavaScript+in+Confluenceas far as I can tell.

Any suggestions?

Thanks

1 answer

0 vote
Davin Studer Community Champion Jun 19, 2014

Your JS is probably running prior to #rte-button-publish existing on the page. Which is why it works in the console, but not during page load.

I thought that might be the reason but then doesn't "AJS.toInit" take care of that problem? I thought it should but clearly it doesn't. Why not?

http://api.jquery.com/ready/

Why you no like me?

Davin Studer Community Champion Jun 19, 2014

If #rte-button-publish is being injected into the DOM by AJS.toInit() as well, then it might be happening after yours.

Maybe the property gets set after I've tried changing it with my hack. Not sure how I could resolve that... The injected property value depends on the OS... Does anybody know the source of the values that get injected? There seems to have been a version where the Save button tooltip is too long which messes up what I'm currently fighting...btw, when I tried to edit my answer above it didn't work at all (using Chrome)

if (!AJS.$("#rte-button-publish").length) alert("all alone");

But that would mean that the code above should create the alert, right? It does on all pages except the edit screen. This is incredibly frustrating... The bug seems to be rare and my clearly not so genius workaround doesn't cut it either.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Sarah Goff-Dupont
Published 3 hours ago in Confluence

Think you know shares vs. @mentions in Confluence? Take this collab quiz.

To anyone who doubts that Atlassians are a little too obsessed with collaboration, and tools related thereto, let me describe a recent discussion we had (which took place on our internal Confluence, ...

38 views 2 3
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