Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

AJS.toInit is getting called before plugin has loaded

imamudin naseem April 10, 2018 edited

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>

 

 

3 answers

2 votes
Matthew Beda
Contributor
October 15, 2018 edited
AJS.$('.element-in-plugin').ajaxComplete(function(){
//...Your Code
});
Tomislav Nikolic December 10, 2018 edited

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

1 vote
Hans Pesata
Contributor
November 6, 2018
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 

0 votes
cdlee August 15, 2018

we have the same problem, did you figure it out?

Suggest an answer

Log in or Sign up to answer
TAGS
Atlassian, Team '25 Europe, Atlassian conference, AI-powered teamwork, Atlassian events, keynote speakers, Barcelona tech conference, Atlassian Williams Racing, Carlos Sainz, Jenson Button, Mike Cannon-Brookes, Anu Bharadwaj, Atlassian Rovo

Atlassian Williams Racing is coming to Team '25 Europe 🏎️

Discover the teamwork and precision behind success on and off the track. See how this high-performing team makes the impossible possible. Be one of the first 100 customers to register for a chance to win 2 tickets to an Atlassian Williams 2026 race.

Register now
AUG Leaders

Atlassian Community Events