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

Load Web Resource with Javascript

Davin Studer
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.
December 29, 2013

Is it possible to load a webresource with javascript? I'm wanting to load the sortable table (com.atlassian.auiplugin:aui-experimental-table-sortable) web resource but can't do it in an atlassian-plugin.xml as I'm not creating a plugin. I'm adding the table to the page after load via ajax.

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Aseem Parikh
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.
December 29, 2013

Davin, I'm not sure if you can load it with Javascript in an efficient manner, but you could include it at load time with a user macro:

#requireResource("com.atlassian.auiplugin:aui-experimental-table-sortable")

After the table is loaded, you can make it sortable (source):

AJS.tablessortable.setTableSortable(AJS.$("#delayedSortedTable"));

Davin Studer
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.
December 29, 2013

Yeah, I was considering the user macro approach as a last resort, but if it can be done via JS I woudl rather go that route.

Davin Studer
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.
December 29, 2013

Hmm ... just to give it a shot I tried this, and I still don't see the AJS.tablessortable.setTableSortable() method. The JS console says that setTableSortable is undefined. This is my user macro. It is included on the Confluence page. My Key parameter in the page is set to com.atlassian.auiplugin:aui-experimental-table-sortable. It looks to me like this should work. Is the documentation correct? By the way I'm on 5.3.4.

## Developed by: Davin Studer
## Date created: 12/30/2013
## @paramKey:title=Resource Key|type=string|required=true|desc=Resource key.

#requireResource($paramKey)

Aseem Parikh
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.
December 29, 2013

Haha. I'm glad you got it working :)

Davin Studer
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.
December 29, 2013

Ok. I'm a goober. I accidentally had a " at the end of the user macro param ... yeah that won't work. Works fine now that I put in the correct key.

Like apiombini likes this
Aseem Parikh
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.
December 29, 2013

Ok, so it seems that this IS possible to do this entirely with Javascript, but again -- it's not very efficient.

AJS.loadWebResourceTemplates("com.atlassian.auiplugin:aui-experimental-table-sortable", "aui-experimental-tables-sortable.css");
AJS.loadWebResourceTemplates("com.atlassian.auiplugin:aui-experimental-table-sortable", "jquery.tablesorter.js");
AJS.loadWebResourceTemplates("com.atlassian.auiplugin:aui-experimental-table-sortable", "aui-experimental-tables-sortable.js");

Davin Studer
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.
January 1, 2014

I did see that method earlier, but when I tried running that in the console I still didn't get the AJS.tablessortable.setTableSortable method. Guess I'll just resort to Velocity ... oh well! Thanks for the help.

Alexej Geldt
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.
February 27, 2014

I have the same problem. Can't load the proper webresource.

After reading this post i still don't undrestand how you fixed it.

What is that -> #requireResource

I only know it like this

${webResourceManager.requireResourcesForContext("my-plugin")}

Davin Studer
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.
February 27, 2014

It is a shorthand way to call the requireResourcesForContext method via velocity.

TAGS
AUG Leaders

Atlassian Community Events