Available: | Atlassian Gadgets 2.0 and later. |
Changed: | In Atlassian Gadgets 2.0.6 and later, the |
This page describes the methods available in each type of gadget JavaScript object. This page is part of the documentation on the Atlassian Gadgets JavaScript Framework.
Please refer to Creating a Gadget JavaScript Object for details on constructing a gadget object. The methods provided on this page can be called not only on the constructed object, but also from any method provided in the construction configs. All methods passed in as config parameters (e.g. the view template, the config descriptor, ...) are run in the scope of the gadget itself. Therefore, this
refers to the gadget and any of the following methods can be called on this
.
Under the hood, the constructor method AJS.Gadget(...)
is a factory method that constructs a specific type of gadget depending on the config parameters passed in. The three kinds of gadgets are:
Each type is described below.
A Standard Gadget is constructed when a view
parameter is passed in but no config
parameter. This is useful when no configuration is needed for the gadget. An example is the Quick Issue Create gadget in JIRA.
All other gadget types extend the Standard Gadget type.
1 2return { showMessage: function (type, msg, dismissible){}, /* Displays a message in dialogue box. */ savePref: function (name, value){}, /* Saves user preferences locally and to the database. */ setViewMode: function (){}, /* Toggles class of gadget to the specified view. */ getViewMode: function (){}, /* Returns the current view mode as a string. For example "Canvas". */ getBaseUrl: function (){}, /* Helper function to get the context path for jira. */ getPrefs: function (){}, /* Gets user preference object. */ getPref: function (name){}, /* Some sugar for getting a preference by name */ getPrefArray: function (name){}, /* Retrieves a user pref array */ getMsg: function (key){}, /* Gets the i18n String */ getGadget: function (){}, /* Gets the gadget object, wrapper div for all gadget html (jQuery Object) */ resize: function (){}, /* Resizes iframe to fit content */ showLoading: function (){}, /* Shows loading indicator */ hideLoading: function (){}, /* Hides loading indicator */ createCookie: function (name, value, days){}, /* Stores a value into a cookie, unique to this gadget. */ readCookie: function (name){}, /* Retrieves a previously stored cookie value */ eraseCookie: function (name){} /* Removes a cookie value */ };
Displays a message in a dialogue box.
1 2showMessage: function (type, msg, dismissible, usePopup) {}
Where:
Saves user preferences locally and to the database. In order to persist these values and have them available when gadget is reloaded, the setprefs
feature must be declared as required in the gadget XML specification.
1 2savePref: function (name, value) {}
Where:
Toggles the class of the gadget to the specified view. This class is used to style the view accordingly.
1 2setViewMode: function (mode) {}
Where:
Returns the current view mode as a string. For example "Canvas"
.
1 2getViewMode: function () {}
Helper function to get the context path for JIRA. Necessary for remote requests.
1 2getBaseUrl: function () {}
Gets user preference object.
1 2getPrefs: function () {}
Gets a preference by name.
1 2getPref: function (name) {}
Where:
Retrieves a user preference array.
1 2getPrefArray: function (name){}
Where:
Gets the i18n string from the included language bundles. Returns the key if it does not exist.
1 2getMsg: function (key){}
Where:
Gets the gadget object, wrapper div
for all gadget HTML (jQuery object).
1 2getGadget: function (){}
Resizes the iframe to fit the content.
1 2resize: function (){}
Shows an indicator that the gadget is loading.
1 2showLoading: function (){}
Hides the loading indicator.
1 2hideLoading: function (){}
Stores a value in a cookie, unique to this gadget.
Use cookies with caution, so that the browser does not create too many cookies. They are necessary if you need to store a value for the current user rather than for the gadget. Where possible, use UserPrefs instead. UserPrefs will store values for the gadget, not the user.
Where:
Retrieve a previously stored cookie value.
1 2readCookie: function (name){}
Where:
Removes a cookie value.
1 2eraseCookie: function (name){}
Where:
A Configured Gadget is constructed when view
and config
parameters are passed in but the current user does not have permission to edit the gadget's preferences. The gadget contains a view and footer.
This gadget has all of the same methods as a Standard Gadget plus the following:
1 2return AJS.$.extend(getStandardInterface(), { getView: function(){}, /* Gets the view object, wrapper div for all view html (jQuery Object) */ showView: function(refresh){}, /* Display the view */ getFooter: function(){} /* Gets the footer object, wrapper div for all footer html (jQuery Object) */ });
Gets the view object, wrapper div
for all view HTML (jQuery object). This object is a div
with the class of "view"
and is contained within the object returned from getGadget()
.
1 2getView: function(){}
Displays the view. When refreshing content, the view template is called. If not refreshing content, this method simply displays the currently rendered view.
1 2showView: function(refresh){}
Where:
Gets the footer object, wrapper div
for all footer HTML (jQuery Object). This object is a JQuery wrapped div
with the class of "footer"
. It is contained within the object returned from getGadget()
and is displayed underneath the view.
1 2getFooter: function(){}
A Configurable Gadget is constructed when view
and config
parameters are passed in and the current user has permission to edit the gadget's preferences. The gadget contains a view, a footer and a configuration screen.
This gadget inherits all of the methods from Configured Gadget plus the following:
1 2return AJS.$.extend(getConfiguredInterface(), { showConfig: function(){}, /* Displays the configuration screen */ getConfig: function(){} /* Gets the config object, wrapper div for all config html (jQuery Object) */ });
Displays the configuration screen with all fields defined during construction.
1 2showConfig: function(){}
Gets the config form object, wrapper div
for all config HTML (jQuery Object). It is contained within the object returned from getGadget()
.
1 2getConfig: function(){}
Using the Atlassian Gadgets JavaScript Framework
Writing an Atlassian Gadget
Gadget Developer Documentation
Rate this page: