Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Javascript inclusion

Pankaj Jangid
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 14, 2011

I am reading this resource http://confluence.atlassian.com/display/CONFDEV/Including+Javascript+and+CSS+resources. But I suppose some other info is also required to include a javascript file.

I had updated my atlassian-plugin.xml file with the following code

<web-resource key="my.js.resources">
<resource type="download" name="menu.js"
location="javascript/menu.js"/>
<context>page</context>
<dependency>confluence.web.resources:ajs</dependency>
</web-resource>

But it is not including my js code. "menu.js" contains the following code:

<script>
alert("Hello World");
</script>

I had tried putting alert() inside AJS.toInit(function(){ }) as well. That too did not work. What am I missing?

3 answers

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
David at David Simpson Apps
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
July 14, 2011

Your example looks reasonable. give it a name though...

<web-resource name="My JavaScript Web Resource" key="my.js.resources">
<resource type="download" name="menu.js" location="javascript/menu.js"/>
<context>page</context>
<dependency>confluence.web.resources:ajs</dependency>
</web-resource>

Also, menu.js should be in a folder called javascript in the same folder as atlassian-plugin.xml. It should not include the script tags. This will break the javascript. To test the inclusion of the JavaScript, View Source in a browser & search for menu.js

Pankaj Jangid
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 17, 2011

David,

I have put the script in javascript directory and do not have script tags in it, just plan alert();

Andres,

I am not creating a seperate gadget. I want to execute my javascript (menu.js) in Page context.

xu zhijian November 23, 2011
&lt;web-resource key="myresource" name="Myresource" &gt;
	    &lt;dependency&gt;com.atlassian.auiplugin:ajs&lt;/dependency&gt;
		&lt;dependency&gt;jira.webresources:jira-global&lt;/dependency&gt;
	    &lt;dependency&gt;jira.webresources:autocomplete&lt;/dependency&gt;
		&lt;resource type="download" name="test.js" location="javascripts/test.js"&gt;
		  &lt;property key="content-type" value="text/javascript"/&gt;
		&lt;/resource&gt; 
		&lt;context&gt;page&lt;/context&gt;
	&lt;/web-resource&gt;

test.js is just includes alert("haha"); and , #requireResource("com.jira.plugin:myresource") #includeResources()

is also added in my jira gadget. But it still doesnot work . does any body help me ? Thanks .

0 votes
Pankaj Jangid
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 17, 2011

David,

My fault. I had script tag in the menu.js. Removed that and it solved the problem.

Thanks.

0 votes
tatoo988 July 14, 2011

are you includding that resource on your gadget spec?

#requireResource("yourResource")

#includeResources()

something like that i guess...

TAGS
AUG Leaders

Atlassian Community Events