Using static resources (such as JQuery) in jira plugin

Vasiliy Vasiliev October 1, 2012

How to include web resources in Atlassian Jira plugin?

atlassian-plugin.xml:

<web-resource key="statistics-resources" name="statistics">
        <resource type="download" name="statistics.js" location="js/statistics/statistics.js"/>
        <dependency>jira.webresources:jira-global</dependency>
        <context>com.cs.jira.plugins.statistics-resources</context>
</web-resource>

statistics.js:

$("#projects").change(function() {

    $(location).attr('href', "/jira/secure/StatisticsModuleAction!project.jspa?project=" + $(this).find("option:selected").text());});

Including resources in Velocity template:

$webResourceManager.requireResourcesForContext("com.cs.jira.plugins.statistics-resources")

When i try to call javascript function from my statistics.js, i get this error:

> Uncaught TypeError: Property '$' of object [object Window] is not a function

Then i tried to include external jQuery library:

<web-resource key="statistics-resources" name="statistics">
        <resource type="download" name="jquery-1.8.2.js" location="js/lib/jquery-1.8.2.js"/>
        <resource type="download" name="statistics.js" location="js/statistics/statistics.js"/>
        <dependency>jira.webresources:jira-global</dependency>
        <context>com.cs.jira.plugins.statistics-resources</context>
</web-resource>

i got another error in batch.js:

> Uncaught TypeError: Object [object Object] has no method 'handleAccessKeys'

How can i include my resources properly?

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Harry Chan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 1, 2012

The built in jQuery that Atlassian has requires AJS.$ instead of just $. Give that a try.

Vasiliy Vasiliev October 2, 2012

It's works, thanks. Now how can I include to the my plugin images, such as icons of type of issues?

<web-resource key="statistics-resources" name="statistics">
        <resource type="download" name="statistics.js" location="js/statistics/statistics.js"/>
        <resource type="download" name="icons" location="/images/icons/"/>
        <dependency>jira.webresources:jira-global</dependency>
        <context>com.cs.jira.plugins.statistics-resources</context>
</web-resource>

<img src="$issue.getIssueType().getIconUrlHtml()"alt="$issue.getIssueType().getName()"/>

Doesn't work for me :(

TAGS
AUG Leaders

Atlassian Community Events