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

This widget could not be displayed.
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
Community showcase
Posted Monday in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

253 views 2 4
Join discussion

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