Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

Issue 1249

Today gadget developers need to write the same few lines of javascript to access the embedded experiences context.

Code Block
javascript
javascript

gadgets.util.registerOnLoadHandler(function() {
  opensocial.data.getDataContext().registerListener('org.opensocial.ee.context', function(key) {
    var context = opensocial.data.getDataContext().getDataSet(key);
    //finally do something with the context
  });
});

This code is the same for ALL embedded experience gadgets who want to access their context, no matter what.  It can be simplified and made easier for the gadget developer by wrapping all of this code in a simple API...

<static> gadgets.ee.registerContextListener(listener)

Description: Registers a listener for when the embedded experience context object is passed to the gadget. The listener will be called whenever the context object is updated for this gadget.

Parameters:

Name

Type

Description

listener

Function

A function that will be called whenever the embedded experience context is set for this gadget.  The function should take one parameter which is a JSON object representing the embedded experience context from the gadget.  See the embedded experiences data model description for more information on the context object.

Example:

Code Block
javascript
javascript

gadgets.ee.registerContextListener(function(context) {
  //Do something with the context
});