Difference between revisions of "Gadgets.util (v0.9)"
From VZ Developer Wiki
(Created page with '{{NeedsExamples}} <div style="float:right; margin: 0 0 10px 10px;">__TOC__</div> <span style="font-size:150%"><strong>gadgets.util</strong></span> Provides general-purpose util…') |
(→gadgets.util.unescapeString) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 49: | Line 49: | ||
:'''Description''' | :'''Description''' | ||
<div style="margin-left:4em;">Registers an onload handler; a function that's executed when the gadget loads. Multiple handlers can be registered, and all will be invoked in the same order that they were registered.</div> | <div style="margin-left:4em;">Registers an onload handler; a function that's executed when the gadget loads. Multiple handlers can be registered, and all will be invoked in the same order that they were registered.</div> | ||
+ | |||
+ | :'''Example''' | ||
+ | |||
+ | <source lang="javascript"> | ||
+ | gadgets.util.registerOnLoadHandler(init); | ||
+ | |||
+ | function init() { | ||
+ | alert('Hello, World!'); | ||
+ | } | ||
+ | </source> | ||
+ | |||
===gadgets.util.sanitizeHtml=== | ===gadgets.util.sanitizeHtml=== | ||
:;<code style="color:green"><static> String gadgets.util.sanitizeHtml(text)</code> | :;<code style="color:green"><static> String gadgets.util.sanitizeHtml(text)</code> | ||
Line 72: | Line 83: | ||
<div style="margin-left:4em;">Reverses escapeString</div> | <div style="margin-left:4em;">Reverses escapeString</div> | ||
+ | ===gadgets.util.getUrlParameters=== | ||
+ | :;<code style="color:green">gadgets.util.getUrlParameters()</code> | ||
+ | ::Returns all available parameters of the current gadget url | ||
+ | ::;Parameters | ||
+ | :::None | ||
+ | ::;Returns | ||
+ | :::<code style="color:green">Array</code> - An Array of all parameters with values | ||
{{ JsApiAlphaList_(v0.9) }} | {{ JsApiAlphaList_(v0.9) }} |
Latest revision as of 11:19, 22 September 2010
This documentation is not completed yet and will be extended by more examples in future.
gadgets.util
Provides general-purpose utility functions.
Methods
gadgets.util.escapeString
<static> String gadgets.util.escapeString(str)
- Parameters
Name Type Description str String The string to escape
- Returns
Type Description String The escaped string
- Description
Escapes the input using HTML entities to make it safer. The following characters are affected: <list style="symbols">
newline (\n, Unicode code point 10)
carriage return (\r, Unicode 13)
double quote (", Unicode 34)
ampersand (&, Unicode 38)
single quote (', Unicode 39)
left angle bracket (<, Unicode 60)
right angle bracket (>, Unicode 62)
backslash (\, Unicode 92)
line separator (Unicode 8232)
paragraph separator (Unicode 8233)
</list>gadgets.util.getFeatureParameters
<static> Object gadgets.util.getFeatureParameters(feature)
- Parameters
Name Type Description feature String The feature to get parameters for
- Returns
Type Description Object The parameters for the given feature, or null
- Description
Returns the value of parameters for this feature. A gadget specifies parameters using the <Param> subelement of the <Requires> or <Optional> element.
gadgets.util.hasFeature
<static> Boolean gadgets.util.hasFeature(feature)
- Parameters
Name Type Description feature String The feature to test for
- Returns
Type Description Boolean True if the feature is supported
- Description
Returns whether the specified feature is supported.
gadgets.util.registerOnLoadHandler
<static> gadgets.util.registerOnLoadHandler(callback)
- Parameters
Name Type Description callback Function The handler to run. The callback function will not be called until after the existing callstack has completed execution.
- Description
Registers an onload handler; a function that's executed when the gadget loads. Multiple handlers can be registered, and all will be invoked in the same order that they were registered.
- Example
gadgets.util.registerOnLoadHandler(init);
function init() {
alert('Hello, World!');
}
gadgets.util.sanitizeHtml
<static> String gadgets.util.sanitizeHtml(text)
- Parameters
Name Type Description text String arbitrary text string
- Returns
Type Description String a sanitized version that may include HTML tags, but will not execute script.
- Description
Sanitizes a text string. The returned value is safe to assign to innerHTML. The returned value may include HTML tags. If plain text is desired, use gadgets.util.escapeString instead.
gadgets.util.unescapeString
<static> String gadgets.util.unescapeString(str)
- Parameters
Name Type Description str String The string to unescape.
- Returns
Type Description String The unescaped string
- Description
Reverses escapeString
gadgets.util.getUrlParameters
gadgets.util.getUrlParameters()
- Returns all available parameters of the current gadget url
- Parameters
- None
- Returns
Array
- An Array of all parameters with values
OpenSocial (v0.9) | |||
gadgets.util |