Custom Javascript

Adding custom javascript code

When working with Forms it may be required to use javascript to animate forms and perform certain actions. JEditor allows you to add custom Javascript code that will be executed on page load.

To add javascript code to your Jira pages do the following:

  1. Go to JEditor Configuration > Custom Javascript
  2. Insert the code into the Javascript field
  3. Save

The code will be executed every time when you reload the page.

Please note: You don't need to wrap your code into the <script> tags in the Custom Javascript field.

Executing code when Jira updates a page without reloading it

Jira doesn't always reload the page when you navigate issues, update fields etc.

If you need your code to be executed every time Jira reloads data (for example when a user navigates to another issue in a queue or edits and saves a field), you may want to add a listener that executes a callback every time when Jira fires a corresponding event.

CKEDITOR.fn.page.myFunc = function(message) {
alert(message);
}
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context, reason) {
if (reason === 'pageLoad' || reason === 'issueTableRowRefreshed') {
CKEDITOR.fn.helpers.proxy.cooldown(CKEDITOR.fn.page.myFunc, null, 1000)('test');
}
});

In this example:

CKEDITOR.fn.page is JEditor's namespace for functions that work with the page.

myFunc is a sample name of your function, you can give it any name. You can also define your function using var myFunc. But this will pollute the global namespace.

CKEDITOR.fn.helpers.proxy.cooldown is a JEditor API function that allows executing other functions not more often than once in a given interval of time.

When JIRA loads any new data into the view, it triggers the NEW_CONTENT_ADDED event. This event is fired every time when, for example, a user selects another ticket in a queue. However, the event will be fired multiple times.

To avoid calling myFunc several times you can use a proxy function that provides a "cooldown" time (1000ms in this case). The null parameter is for an editor instance which is not needed in this example.

Notice how a text parameter 'test' is passed to myFunc through the cooldown proxy function. You may pass any number of parameters like this.

Have more questions? Submit a request

0 Comments

Article is closed for comments.
Powered by Zendesk