Hello,
I am using JIRA 6, I added a custom javascript file in following jsp files :
<atlassian-jira>/includes/decorators/aui-layout/head-common.jsp
<atlassian-jira>/includes/decorators/aui-layout/head-common-nodecorator-pre.jsp
this file contains some common functions that i want within every JIRA page. When loading page in browser console shows "Uncaught TypeError: AJS.$ is not a function" on following line :
AJS.$(document).ready(function() {
<< Some custom code here>>
});
It appears like JIRA is loading custom js file before AUI & jquery. ( If it may be a possibility then Is there any solution for this? )
any suggestions are welcome!
Community moderators have prevented the ability to post new answers.
I would recommend against injecting code into JIRA's jsp files — use the web resource context that @Volodymyr Krupach mentioned and add a dependency on <dependency>com.atlassian.plugins.jquery:jquery</dependency>
to ensure jQuery is loaded on the page first.
However if you're going to be adding code to jsp files, then in you'd be better off adding it to the bottom of /atlassian-jira/includes/decorators/aui-layout/footer.jsp
Do not do changes to JIRA JSPs.
I guess you want your JS to work on all JIRA pages so you can wrap an addon with web-resource. Your web-resource should look like:
<web-resource name="Resources" key="resources"> <resource name="foo.js" type="download" location="resources/foo.js"/> <dependency>com.atlassian.auiplugin:ajs</dependency> <context>atl.general</context> <context>atl.admin</context> </web-resource>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Volodymyr,
Yes i want my js on all pages (view + edit + create screens).
It was working earlier in JIRA 5, you may include custom js file in <atlassian-jira>/atlassian-jira/includes/decorators/aui-layout/header.jsp which has been changed in JIRA 6.
I did follow this kb article for JIRA 6.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Saurabh,
Did you try put the script to the end of head-common.jsp and head-common-nodecorator-pre.jsp?
Have you restarted JIRA after you changes?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes I did that but still getting the same error ("AJS.$ is not a function").
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Looks through the page source to find where your script is injected. Also you may check if jQuery is already inited and use it instead of AJS.$.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I did tried that too, it throws "ReferenceError: jQuery is not defined". i think its probably because custom js file is being load before jquery & AJS.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Maybe you can go with pure JS script "document ready" approach without jQuery: http://stackoverflow.com/questions/799981/document-ready-equivalent-without-jquery
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Maybe you should also try
AJS.toInit(function() { //Code here });
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Stephen for your reply,
AJS.toInit will not work (I did tried that too) because AJS & jQuery are not available in context when cutom js is being execute.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.