I render a web-panel on the Jira issue view (location: atl.jira.view.issue.right.context). The velocity template looks as roughly follows:
<!-- some HTML here -->
<script type="text/javascript">
// some javascript here
</script>
On the normal issue view (/browse/ISSUE-KEY) this works just fine, the HTML loads and the JS tag gets executed.
However, if the same panel gets loaded on the browse Jira project view, the HTML loads as expected but the JS tag seems to get magically removed from the velocity template.
Does anyone have an explanation for this? This inconsistency is driving me mad. I tried a bunch of variants to make this work with no success. E.g. to put the JS code in a separate JS file, create a web-resource for it in atlassian-plugin.xml, and load it via $webResourceManager.requireResourcesForContext("context-key")
@chisiang.ng I kind of solved this but also with a workaround. Here is what I did:
Extract the iframeResize() call to a separate JS file that looks something like this (leaving the script tag in the velocity template - because in the browse issue view it works):
/**
* Resizes the iframe every time the user selects another issue in
* the issue navigator.
*/
window.JIRA.bind(window.JIRA.Events.ISSUE_REFRESHED, function() {
window.iFrameResize({heightCalculationMethod: "taggedElement"});
});
Update the plugin descriptor with these 2 webresource definitions:
The context property will make sure these two files are included and executed on the required all pages. I left the script tag in the velocity template because for the view issue page that works. For the issue navigator iFrameResize() gets called from the included web resource.
It’s also not a very clean solution and I still don’t understand why the script tag gets removed in some views. It might be because in the issue navigator issues are loaded via Ajax…