When an OpenSocial gadget includes a "feature" it is generally requesting a particular JavaScript API to be made available by OpenSocial as the gadget starts. In this article, we look at how we would cog go about creating a new feature for a "learning" API and adding the feature to Shindig and using the feature in a Gadget.
...
First we move into the feature directory:
cd features/src/main/javascript/features
Create a new directory named * learning* and put three files into it.
...
Then edit the file features.txt and add a line:
Code Block | ||
---|---|---|
| ||
features/xmlutil/feature.xml |
...
features/com.google.gadgets.analytics/feature.xml |
...
features/learning/feature.xml |
There is a way to update features.txt using a script, but for now, lets just jack-plug in directly.
At this point you need to rebuild Shindig. And you might get syntax errors during the build which you need to fix. The Javascript for features is compiled / processed at mvn time so you may encounter syntax errors causes by your JavaScript.
mvn
once it compiles and installs, start Jetty again
mvn -Prun
And navigate to http://localhost:8080/samplecontainer/samplecontainer.html
You should see the “Social Hello World” gadget. Now lets edit this file:
./target/work/webapp/samplecontainer/examples/SocialHelloWorld.xml
And add two lines:
Code Block | ||||
---|---|---|---|---|
| ||||
<Require feature="osapi"></Require> <Require feature="learning"></Require> <Require feature="settitle"/></Require> ... gadgets.window.setTitle('Social Hello World'); alert(gadgets.learning.getContextLabel()); var hellos = new Array('Hello World', 'Hallo Welt', 'Ciao a tutti', ... |
...
When you have everything working, you should see the popup loaded as follows:
As a note, since we pugged our alert statement into the Javascript before the Gadget loaded its OpenSocial data and rendered itself, the actual gadget is not yet rendered behind the alert box.
Next up: TBD Adding a Service to osapi and Calling Your New Service From a Feature