Documentation

Function Description Available since Example
contextPath

The AJS.contextPath() function returns the "path" to the application, which is needed when creating absolute urls within the application, e.g.:

  • var url = AJS.contextPath() + "/rest/some/resource";
  • var url = AJS.contextPath() + "/dashboard.action";
3.5.5
Cookie

store values in a persistent cookie without worrying about the application using too many cookies.

3.5.5
// Save a value to the conglomerate cookie
AJS.Cookie.save("COOKIES_ARE_COOL", "true");
 
// Save will also update a value previously saved
AJS.Cookie.save("COOKIES_ARE_COOL", "not true");
 
// retrieve a value from the conglomerate cookie
AJS.Cookie.read("COOKIES_ARE_COOL");
 
// remove a value from the conglomerate cookie
AJS.Cookie.erase("COOKIES_ARE_COOL");
debounce

Makes sure that a constantly firing function doesn't cause performance issues.

Don't Use when binding to an infrequently firing event.

5.1
function myFunction(){
    //function code
}
 
var myDebouncedFunction = AJS.debounce(myFunction, 300); //this function won't fire if it has been less than 300ms before the last call
 
AJS.$(window).resize(myDebouncedFunction);
escapeHTML

TThe AJS.escapeHtml() performs html-safe escaping of the input string. Specifically, it encodes:

  • <
  • >
  • &
  • '
  • "
4.0
var url = "\"><script>alert('XSS');</script>";
 
// BAD: XSS problem
$("#mydiv").html("linky");
 
// GOOD
$("#mydiv").html("linky");
format

Provides an easy way to substitute parameters into a string.

1.0
AJS.format("Have a {0} day", "good"); /* Have a good day */
AJS.format("Have a '{0}' day", "good"); /* Have a '{0}' day */
AJS.format("Have a ''{0}'' {1}", "good", "Monday"); /* Have a 'good' Monday */
I18n.getText

AUI includes a web resource transformer that will translate some javascript into the literal strings before being served.

For usage tips see the i18n page

3.5.5
isDirty

make sure users cannot accidentally lose data.

2.0
AJS.$("formname=jiraform").isDirty();
log

A safe alternative to console.log(). It ensures that both console and the console.log method exist before executing. This means if you happen to leave one in your code, browsers which don't support console.log (eg. IE, some mobile browsers) shouldn't break.

1.0
AJS.log("Your message here.");
version

Detects the version of AUI on the current page.

1.2
// for peace-of-mind checking
AJS.log(AJS.version); // "3.0"
 
// To use it in all its glory
if (AJS.version == "3.0") {
// take advantage of the awesomeness of AUI 3.0
} else {
// write awesome custom code
}