System.Gadget.Flyout
The
System.Gadget.Flyout object enables you to implement a flyout for your Sidebar gadget. The gadget in
Listing 3 contains a button that shows a flyout page when it is clicked. You first set the name of the flyout file using the file property. To make the flyout appear, set the show property to true. Then, set the
onHide and
onShow events to the two event handlers,
FlyoutHidden and
FlyoutOnShow. When the flyout is shown, you will display a string indicating that the flyout is shown. When the flyout closes, you will display the name entered in the flyout.
Figure 3 shows the flyout.
 |
Figure 3. Flyout: Displaying the flyout of the gadget. |
The flyout page (see Listing 4) provides a textbox for entering a name. Clicking the Done button closes the flyout page by setting the show property to false.
When the user clicks the Done button the flyout closes and the name entered in the flyout is displayed in the gadget, which is achieved using the System.Gadget.Flyout.document.getElementById() method.
System.Gadget.Settings
The System.Gadget.Settings object enables you to save setting values specific to each Sidebar gadget. The following code example shows how you can save and read values using each of the four methods:
System.Gadget.Settings.write ("age", 30);
System.Gadget.Settings.write ("PI_1", 3.142857142857142857142);
System.Gadget.Settings.writeString ("PI_2",
"3.142857142857142857142");
System.Gadget.Settings.write ("firstname", "John");
System.Gadget.Settings.writeString ("lastname", "Smith");
var result = document.getElementById("result");
result.innerHTML = System.Gadget.Settings.readString("age") + "<br/>";
result.innerHTML += System.Gadget.Settings.read("PI_1") + "<br/>";
result.innerHTML += System.Gadget.Settings.readString("PI_1") +
"<br/>";
result.innerHTML += System.Gadget.Settings.read("PI_2") + "<br/>";
result.innerHTML += System.Gadget.Settings.readString("PI_2") +
"<br/>";
result.innerHTML += System.Gadget.Settings.read("firstname") +
"<br/>";
result.innerHTML += System.Gadget.Settings.readString("lastname") +
"<br/>";
The outputs from the code are as follows:
30
3.14285714285714 (PI_1)
3.14285714285714 (PI_1)
3.142857142857143 (PI_2)
3.142857142857142857142 (PI_2)
John
Smith
What is interesting is that when you try to save the value of
PI using the
write() method, it will attempt to guess the data type of the data to be saved and some rounding or truncation may occur inadvertently (depending on the precision of the number to be saved). In this case, the value of
PI_1 will be truncated when it is saved, and that can be seen when you read the value of
PI_1 using the
read() and
readString() methods. For
PI_2, it is saved using the
writeString() method, which writes the value as a string without trying to convert it to a numeric type. Notice that when you use the
read() method to try to read the value of
PI_2, there is a loss of precision because
read() tries to guess the datatype it is reading. If you use the
readString() method, the value of
PI_2 will be retrieved correctly.
In general, use the writeString() and readString() methods when manipulating numeric values.