Convenience APIs For Embedded Experiences

Issue 1249

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

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:

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