Skip to main content

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​
NameTypeDescription
strStringThe string to escape.
Return value​
TypeDescription
StringThe escaped string.
Sample​
var html = gadgets.util.escapeString("<foo>");
// str = &#60;foo&#62;

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​
NameTypeDescription
featureStringThe feature for acquiring parameters.
Return value​
TypeDescription
ObjectThe 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​
NameTypeDescription
featureStringSearch feature.
Return value​
TypeDescription
BooleanTrue 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​
NameTypeDescription
callbackFunctionThe 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​
NameTypeDescription
strStringThe string to unescape.
Return value​
TypeDescription
StringThe unescaped string.
Sample​
var str = gadgets.util.unescapeString("&#60;foo&#62;");
// str = <foo>

gadgets.util.sanitizeHtml​

<static> String sanitizeHtml(htmlText, opt_uriPolicy, opt_nmTokenPolicy)

Sanitizes the assigned string.

Parameter​
NameTypeDescription
htmlTextStringString to be sanitized
opt_uriPolicyFunctionProcess for sanitizing a URL
opt_nmTokenPolicyFunctionProcess 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.