gadgets.util
Method
gadgets.util.escapeString
<static> String escapeString(str)
Escapes with HTML entities. The following characters are affected.
- Newline (\n, Unicode 10)
- Carriage return (\r, Unicode 13)
- Double quotation mark (", Unicode 34)
- Ampersand (&, Unicode 38)
- Single quotation mark (', Unicode 39)
- Less-than sign (<, Unicode 60)
- Greater-than sign (>, Unicode 62)
- Backslash (, Unicode 92)
- Line separator (Unicode 8232)
- Paragraph separator (Unicode 8233)
Parameter
| Name | Type | Description |
|---|---|---|
| str | String | The string to escape. |
Return value
| Type | Description |
|---|---|
| String | The escaped string. |
Sample
var html = gadgets.util.escapeString("<foo>");
// str = <foo>
gadgets.util.getFeatureParameters
<static> Object getFeatureParameters(feature)
It returns the value of parameters for this feature. A gadget specifies parameters using the sub-element of the element or element.
Parameter
| Name | Type | Description |
|---|---|---|
| feature | String | The feature for acquiring parameters. |
Return value
| Type | Description |
|---|---|
| Object | The parameters for the specified feature. If none, null. |
gadgets.util.hasFeature
<static> Boolean hasFeature(feature)
Returns whether or not the specified feature is supported.
Parameter
| Name | Type | Description |
|---|---|---|
| feature | String | Search feature. |
Return value
| Type | Description |
|---|---|
| Boolean | True if the feature is supported. |
gadgets.util.registerOnLoadHandler
<static> registarOnLoadHandler(callback)
Registers an onload handler. This handler is a function that is executed when the gadget loads.
Parameter
| Name | Type | Description |
|---|---|---|
| callback | Function | The handler to be executed. |
Return value
None
Sample
gadgets.util.registerOnLoadHandler(init);
function init() {
//...
}
gadgets.util.unescapeString
<static> String unescapeString(str)
Returns the HTML escaped string to its original form.
Parameter
| Name | Type | Description |
|---|---|---|
| str | String | The string to unescape. |
Return value
| Type | Description |
|---|---|
| String | The unescaped string. |
Sample
var str = gadgets.util.unescapeString("<foo>");
// str = <foo>
gadgets.util.sanitizeHtml
<static> String sanitizeHtml(htmlText, opt_uriPolicy, opt_nmTokenPolicy)
Sanitizes the assigned string.
Parameter
| Name | Type | Description |
|---|---|---|
| htmlText | String | String to be sanitized |
| opt_uriPolicy | Function | Process for sanitizing a URL |
| opt_nmTokenPolicy | Function | Process for sanitizing an id, class, etc. |
Sample
var html = gadgets.util.sanitizeHtml('<script type="text/javascript">alert("evil code")</script>');
// html = ""
Revision History
- 12/2010
- Initial Release.