I have written a plugin which shows up as Web panel in the right bar of issue page.
I have all my js written inside AJS.toInit function since I want to make sure DOM tree of plugin is ready before execution of javascript.
AJS.toInit(function(){
// JS Code
})
Plugin loads perfectly fine on view issue page (i.e /jira/browse/APPS-1) but when issue is opened on projects page (i.e /jira/projects/APPS/issues/APPS-1?filter=allopenissues), AJS.toInit function gets fired before plugin has loaded, and since I am doing something like $(".element-in-plugin"), it fails because $(".element-in-plugin") is not present in DOM
My velocity template file is as below
$webResourceManager.requireResource("com.atlassian.flock.jiraPlugin:jiraPlugin-resources")
<div id="jira-plugin" class="fp hidden">
</div>
I have defined web-resource as below
<web-resource key="jiraPlugin-resources" name="jiraPlugin Web Resources">
<dependency>com.atlassian.auiplugin:ajs</dependency>
<dependency>com.atlassian.auiplugin:aui-select2</dependency>
<resource type="download" name="jiraPlugin.css" location="/css/jiraPlugin.css"/>
<resource type="download" name="jiraPlugin.js" location="/js/jiraPlugin.js"/>
<resource type="download" name="images/" location="/images"/>
<context>atl.general</context>
</web-resource>
AJS.$('.element-in-plugin').ajaxComplete(function(){
//...Your Code
});
This is the way to go. I was ripping my hair out tryna make new_content_added work. AjaxComplete (I use ajaxStop, don't know if it's better) works flawlessly. Not sure about how expensive it is, but a milisecond slower webpanel is better than one that doesn't work at all. I just make sure I put my init-checks at the beginning of ajaxComplete
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context, reason) {
var $context = $(context);
switch(reason) {
case JIRA.CONTENT_ADDED_REASON.panelRefreshed:
{
$context.find('.element-in-plugin').each(function() {
// Your code
});
}
break;
default:
break;
}
});
Regards,
Hans
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.