Google Gadget Widget
From Hexten
(this documentation is incomplete)
The Google Gadget Widget is a Wiki Widget that embeds a Google Gadget on a wiki page.
Contents |
[edit] Example
Here's an example
<widget
type="googlegadget"
url="http://horloge.maree.frbateaux.net/gh.xml"
xargs="up_Port=401&up_UTC=0"
synd="open"
width="320"
height="222"
title="Mareas en Bilbao"
border="http://gmodules.com/ig/images/"
output="js" />
And here's what it looks like:
Note the use of the xargs attribute to handle arguments whose names are not valid XML attribute names - in this case up_Port and up_UTC. Thanks to Juan Zubeldia for pointing out the need for this mechanism.
[edit] Reference
[edit] Parameters
(this documentation is incomplete)
- debug
- display debug information for the widget (default 0)
- disabled
- temporarily disable display of widget (default 0)
- width
- sets the width of the embedded calendar in pixels (default 320)
- height
- sets the height of the embedded calendar in pixels (default 75)
- title
- the title for the search box
- border
- the border style for the search box
- xargs
- contains any arguments that can't be expressed as XML attributes
[edit] Escaping Arguments
Read this if you're having difficulty getting your Google Gadget working. I'm afraid I've made it sound terribly complex. If anyone can think of a clearer way to say the same thing please feel free to edit --AndyArmstrong
Wiki Widgets use XML syntax. In XML (like HTML) the characters '<', '>' and '&' have special meanings. That means that if you need to use one of those characters in an attribute value it must be encoded. For example, let's suppose you want your gadget's title to be "Law & Order". The ampersand is a special character in XML so it has to be encoded. Instead of
<widget type="googlegadget" title="Law & Order" />
you'd use
<widget type="googlegadget" title="Law & Order" />
The '&' is replaced by '&'. Similarly '<' is replaced by '<' and '>' is replaced by '>'.
[edit] The xargs Attribute
Things get even more complicated in the case of the xargs attribute which allows multiple parameters to be passed - and in particular parameters whose names are not valid XML attribute names.
The arguments contained in xargs are encoded in the same way that multiple arguments are encoded in a URL. For example
x=1&y=2
encodes two arguments - x which is equal to 1 and y equal to 2. Because '&' and '=' are used to separate the parameters and values these characters (along with a number of others) can't appear within parameter values. Instead these characters are encoded as '%' followed by their ASCII character code in hexadecimal. So the text "Law & Order" would be encoded as
Law%20%26%20Order
Optionally the plus sign '+' may be used instead of '%20' to represent spaces.
[edit] Putting it all together
So that's all a bit complex I'm afraid. Here's how it works in practice. Let's say your Google Gadget needs a parameter called 'src_URL' with a value of
http://example.com/rss?id=123&limit=40
That presents two problems:
- src_URL isn't a valid XML attribute name
- the URL contains an ampersand which we'll need to encode
Because src_URL can't be used as the name of one of our XML attributes we'll have to put it inside the xargs attribute. Values in xargs are URL encoded so we'll need something like this:
<widget type="googlegadget" xargs="src_URL=http%3A%2F%2Fexample.com%2Frss%3Fid%3D123%26limit%3D40" />
Notice how most of the punctuation in the URL has been encoded using the '%xx' notation. In particular the ampersand has gone so we don't need to worry additionally about XML entity encoding. Phew.
For attributes other than xargs we do need to consider XML entity encoding so if we add the title "Law & Order" to that we get
<widget
type = "googlegadget"
title = "Law & Order"
xargs = "src_URL=http%3A%2F%2Fexample.com%2Frss%3Fid%3D123%26limit%3D40" />
It looks complex but if you remember that xargs is URL encoded and any other attribute is XML entity encoded you should be OK.
[edit] More Examples
[edit] Google Coop
An example "add this gadget to your webpage" code from google follows. Notice that it should be all on one line, but is presented here broken at each & for ease of viewing:
<script src="http://gmodules.com/ig/ifr? url=http://www.google.com/coop/api/008224879786263662799/cse/dlukhlm8-0m/gadget &synd=open &w=320 &h=75 &title=Appropedia's+Public+Domain+Search &border=http%3A%2F%2Fgmodules.com%2Fig%2Fimages%2F &output=js"></script>
We extract that information, to create:
<widget
type="googlegadget"
url="http://www.google.com/coop/api/008224879786263662799/cse/dlukhlm8-0m/gadget"
synd="open"
width="320"
height="75"
title="Appropedia's Public Domain Search"
border="http://gmodules.com/ig/images/"
output="js" />
Which produces:

