The context object is probably one the most important things about creating a gadget, but how do you know what it contains. Here is a little gadget that can show you what it’s values are. Just create a new project like you did for the other examples, and add it to all the integration points. When this app runs, it will show you all the values for the Context Object. When this gadget runs it will output name value pairs in the form of name : value. This will all be contained between {}. This is what is known as JSON notation before it was processed into a JavaScript Object. For example, lets take an object Person. A possible JSON definition would be:
{
name: “bob”,
eyeColor: “red”,
height:”10ft”,
age: 25
}
If this were processed into an object, you could access person.name and get “bob”. So here is the code!
Enjoy!
<?xml version=”1.0″ encoding=”UTF-8″?>
<Module>
<ModulePrefs description="Displays the context information made available to the gadget.">
<Require feature="opensocial-0.9" />
<Require feature="sciverse" />
<Require feature="dynamic-height"/>
</ModulePrefs>
<UserPref name="secureAuthtoken" datatype="hidden" />
<Content type="html" view="canvas,profile">
<![CDATA[
<script type="text/javascript">
function getContextInfo(){
gadgets.sciverse.getContextInfo(contextCallback);
}
function contextCallback(obj){
var rs = JSON.stringify(obj);
//Format the string for display.
rs = rs.replace(/",/g,"\",<br>");
var contextInfo = document.getElementById("contextInfo");
contextInfo.innerHTML = rs;
gadgets.window.adjustHeight();
}
gadgets.util.registerOnLoadHandler(getContextInfo);
</script>
<p><a href="javascript:void(0);" onclick="getContextInfo();">Reload Context Info</a></p>
<div>
<span>Secured Authtoken is: </span> <span>__UP_secureAuthtoken__ </span>
</div>
<div><u>Context Info:</u></div>
<div id="contextInfo" style="display:block">
</div>
]]>
</Content>
</Module>
