Defining Preferences

From WidgetAvenue Wiki

Jump to: navigation, search

Defining preferences for a widget is easy. Here is a basic example with a "Hello You" widget.


Creating the source waHTML file

Create a helloyou.html file on your server with the following content:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
	<head>
		<title></title>
	</head>
	<body>
		<span>Hello, </span><span class="ldWidgetJS_insertName"></span>
	</body>
</html>

This code contains a div with a special ClassName starting with ldWidgetJS which is going to trigger the execution of the getPref function.

Creating the waJS file

Now, you need to create a second file to include the JS function. Create a file called js.js in the same directory as helloyou.html, with the following content:

ldWidgetUid_JS['insertName'] = function(elt)
{
	ldWidgetUid_setInnerHtml('ldWidgetJS_insertName',ldWidgetUid_getPref('name'));
}

Building the URL to display the standalone version of the widget

Once again, the most simple option is to display the standalone version of your widget. The URL is built as follows:

http://www.widgetavenue.com/wdg/loaders/stn.php?root=html&url=[Your Source URL]&_js=[Your js filename]&[Pref Name]=[Pref Value]

For example, if your source HTML file is located at http://myserver.com/helloyou.html, you will be able to display your widget at

http://www.widgetavenue.com/wdg/loaders/stn.php?root=html&url=http%3A%2F%2Fmyserver.com%2Fhelloyou.html&_js=js.js&name=You

If your URL is correct, you should get something similar to this. Then, clicking on install at the bottom of the widget allows you to install it on various host platforms. You can edit the preference by clicking on "Preferences" at the bottom of the widget. On host platforms which support permanent storage of preferences, such as iGoogle, Netvibes, PageFlakes, or Webwag, you will also note that if you change the preference, it will be stored by the platform on a permanent basis. Also, on these platforms, you can usually edit the preferences by clicking on a link or button at the top of the widget.

Personal tools