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>