tags:

views:

115

answers:

2

hello folks,

I am trying to develop a plugin for jira and I'm having issues with jquery. I am pretty sure that its already part of the framework and all i need to do is include it but nothing seems to be working.

I have tried putting this in my atlassian-plugin.xml file

<web-resource key="jquery" name="jquery" >
    <dependency>jira.webresources:jira-global</dependency>
    <resource type="download" name="jquery.js" location="/includes/javascript/jquery.js" />
</web-resource>

I have tried it without the dependency as well

I have tried putting #requireResource("jira.webresources:jira-global") in my velocity template and that doesnt work either. THis is my js in my input.vm file

    <script type="text/javascript">
    jQuery(function($) {
        $('.questions').hide();
    });
</script>

Everything I seem to do just results in the Uncaught ReferenceError: jQuery is not defined

at a bit of a loose end now not really sure what to try next!

+1  A: 

Take a look at the JIRA Subversion plugin for an example of how their resources get defined and included. It's fiddly but it does work. The main documentation for this is at http://confluence.atlassian.com/display/PLUGINFRAMEWORK/Web+Resource+Plugin+Module

Main page for the plugin: https://studio.plugins.atlassian.com/wiki/display/SVN/Subversion+JIRA+plugin

The main plugin config file at https://studio.plugins.atlassian.com/svn/SVN/tags/atlassian-jira-subversion-plugin-0.10.5.4_01/src/main/resources/atlassian-plugin.xml has a web-resource element defined that says it depends on jira.webresources which is where jquery comes from in JIRA:

jira.webresources:jira-global

and then this resource is loaded by https://studio.plugins.atlassian.com/svn/SVN/tags/atlassian-jira-subversion-plugin-0.10.5.4_01/src/main/java/com/atlassian/jira/plugin/ext/subversion/issuetabpanels/changes/SubversionRevisionsTabPanel.java where it says

webResourceManager.requireResource("com.atlassian.jira.plugin.ext.subversion:subversion-resource-js");

The string in this call is crucial - it must be the "key" attribute of the top-level atlassian-plugin element plus a colon plus the "key" attribute of the resource element in atlassian-plugin.xml

HTH,

~Matt

mdoar
Okay thanks, I think I understand. IF I specify a webresource in my main xml file I need to load this resource in the java code rather than the velocity code?This is what I wasn't doing, I was trying to load it in my template.
Alex Edwards
A: 

prior to mdoar's answer I found a work around which solved my problem.

If you are writing your script in the same file as the html then define it within the <body> tag not the <head> tag, this seems to ensure that the jira js libraries have been loaded.

Alex Edwards