dashboard
Version:
Create dashboards with gadgets on node.js
124 lines (93 loc) • 3.81 kB
text/xml
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<!-- ** Replace inside quotes with your gadget's title -->
<ModulePrefs title="Gadget Template"
height="10"
scrolling="true">
<Require feature="dynamic-height"/>
<Require feature="opensocial-0.8"/>
<Require feature="minimessage"/>
</ModulePrefs>
<Content type="html"><![CDATA[
<!-- Add HTML content here -->
<div>
<input type="button" value="Say Hello" onclick="myGadget.sayHello();"/>
</div>
<!-- Used to register with the Data Gadget -->
<script src="http://sky.astro.washington.edu/gadgets/js/DataInterface.js" type="text/javascript"></script>
<!-- Contains UW.astro objects -->
<script src="http://sky.astro.washington.edu/gadgets/js/astroObjectLib.js" type="text/javascript"></script>
<script type="text/javascript">
var myGadget = null,
debug = true;
// Writes to the console if debug (global) is true
function debugLog(msg){
if ((debug === true) && (window.console && console.log)) {
console.log(GADGET_NAME + ": " + msg);
}
return;
}
// ** Replace with your gadget's name
var GADGET_NAME = "Gadget_Template" + "_" + Math.floor(Math.random()*100000+1).toString();
// Creates gadget object
function init(){
myGadget = new GadgetTemplate();
gadgets.window.adjustHeight();
}
function GadgetTemplate(){
var my = new Object();
// CONSTANTS
var DEFAULT_NAMESPACE = "NS1",
MM_TIMER_DURATION = 4;
// PRIVATE
var _namespaceList = [ DEFAULT_NAMESPACE ]; // list of our current Namespaces. Just init with the default
// Private Helper Variables
var di = new UW.astro.DataInterface(GADGET_NAME, DEFAULT_NAMESPACE); // make dataInterface object, init with default
var miniMsg = new gadgets.MiniMessage();// make MiniMessage object
// INIT
// ** Variables to register go in this array.
// ex: ["Viewport_Center_Coordinate", "Viewport_Point_List"]
var variableArray = [];
// ** Triggers to register go in this array
// Each trigger is a 2-element array as follows:
// [ "VariableName", triggerFunction ]
// example with one trigger: (notice the array inside the array)
// var triggerArray = [ ["Viewport_Center_Coordinate", function(){ zoomMe() }] ]
// it is recommended to define functions outside the array for more readable code
var triggerArray = [];
var msg = miniMsg.createStaticMessage("Attempting to register gadget...");
di.registerMe( { gadgetName : GADGET_NAME,
namespaceList : _namespaceList,
variableList : variableArray,
triggerList : triggerArray,
successCallback : registrationSuccess,
failureCallback : registrationFailure
} );
// Callback after successful registration
function registrationSuccess(){
debugLog('Registration successful');
if (msg) {
miniMsg.dismissMessage(msg);
// free up msg
msg = null;
miniMsg.createTimerMessage("Registration Succesful.", MM_TIMER_DURATION);
}
}
// Callback after a failure of registration
// Displays failure message
function registrationFailure(){
debugLog('Registration FAILED!');
miniMsg.dismissMessage(msg);
miniMsg.createDismissibleMessage("Unable to register gadget.\nWe cannot communicate with other gadgets.");
}
// METHODS
// ** Add public methods (that will be called from outside the object by a button or something)
my.sayHello = function(){
alert("Hello!");
}
return my;
}
gadgets.util.registerOnLoadHandler(init);
</script>
]]></Content>
</Module>