Hi,
First of all I want to apologise for this short title.. I forgot to edit this after I wrote my problem.. and now I can't find an edit button....
I'm making an Open Social gadget and i'm having a little problem a.t.m. I've got a object which is built the OO way. When initializing an object you have to give a parameter containing the variable name (this is used for making correct id's so it would be possible to use more of the same objects and have different ID's). So this object builds his own skin with divs with ID's like: this.InstanceName+"_content" etc. an example:
If I initialize a var gadget like:
var gadget = new object("gadget");
it would generate a div like:
<div id="gadget_content">
same for:
var midget = new object("midget");
would give you <div id="midget_content"> ... you'll get the point.
The object contains some variables and some functions one of these functions is getInstanceName() which will return the name of the instance (the parameter which you gave to the object). I can call this method with this.getInstanceName() cause the "this" variable is a.t.m. my instance.
So far no problems. But im building an OpenSocial gadget and I have to use the gadgets.io.makeRequest function to get data from another app.
This function works like:
gadgets.io.makeRequest(jsonGenerateFileUrl, this.callbackFunction, this.params);
jsonGenerateFileUrl = is a PHP file which will generate a JSON object and ruturns it.
this.callbackFunction = a function declared in my object which will get the JSON object and will show it on the screen.
this.params =
this.params = {}; this.params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;
and is nothing more than a parameter that tells the gadgets.io.makeRequest() will return a JSON object.
When I call this function it will return a correct JSON file and it wil go to a callback function in my object, which will show the json data in the content div of the app.
The problem is when I made the request the "this" variabele is not my instance anymore but a window object :S so I can't use my own method: this.getInstanceName(). The problem with this is, that I can't get the correct div cause I should use: document.getElementById(this.getInstanceName()+"_c ontent"); but the "this" variable is not my instance anymore so it returns undefined.
I would like to avoid hardcoded ocument.getElementById("gadget_content"); this btw does work but only if you call your variable gadget..
Does anyone of you know the solution of this problem?
link to the app:
http://www.nijm.nl/cvhj/cvhjgadget.xml
you can see it working at:
http://solidarjan.hyves.com/gapsb <-- need to register I'm afraid :S else add the gadget in Orkut (login = your google account)