Spry Utilities

addClassName

Spry.Utils.addClassName(element,classname);

Description

addClassName will add a CSS class to the specified element. A class attribute does not have to be on the element. If the element has an existing class applied, this function will add it to the element, not replace it.

Arguments

element

classname

Example

<style type="text/css">
<!--
.dada {
background-color: #FFCC33;
}
-->
</style> <script> function setClass(ele,class){
Spry.Utils.addClassName(ele,class);
} </script> <a href="#" onclick="setClass('content','dada');">Add Class</a> <div id="content">Change This Text</div>

addEventListener

Spry.Utils.addEventListener = function(element, eventType, handler, capture)

Description

addEventListener registers a non-destructive event handler on the specified element. See also removeEventListener.

Arguments

element

eventType

handler

capture

addLoadListener

Spry.Utils.addEventListener = function(handler)

Description

addLoadListener add non-destructive event listener to the onLoad event.

Arguments

Handler

Example

Spry.Utils.addLoadListener(function() { setTimeout(function() { Spry.Data.initRegions(); }, 0); });

eval

Spry.Utils.eval(string);

Description

Call this method from your JS function when you don't want the JS expression to access or interfere with any local variables in your JS function. A standard js eval.

Arguments

String

getNodeText

Spry.Utils.getNodeText(elementID);

Description

Returns the text of the specified Element

Arguments

elementiD

Example

<script>
function getText(node){
var x = Spry.Utils.getNodeText(node)
alert(x);
}
</script>

<p><a href="#" onclick="getText('removeMe');">Get Inner Text</a></p>
<div id="removeMe">This is the Inner Text</div>

loadURL

Spry.Utils.loadURL = function(method, url, async, callback, opts)

Description

loadURL gets the actual XMLHTTPRequest to the server and handles the returned value.

Format

Spry.Utils.loadURL = function(method, url, async, callback, opts)

Arguments

method

url

async

Returns

N/A

Example

var observer = { onPostUpdate: function(notifier, data) { var acc = new Spry.Widget.Accordion("Acc1"); } };
Spry.Data.Region.addObserver("Acc1", observer);
    

Sample

Region Observer Sample

removeAllChildren

Spry.Utils.removeAllChildren(elementID);

Description

removeAllChildren will remove all the child content of the specified element, but leave the container of the specified ID.

Arguments

elementiD

Example

<script>
function removeTheChild(node){
Spry.Utils.removeAllChildren(node)
}
</script> <a href="#" onclick="removeTheChild('removeMe');">Remove Inner Text</a> <div class="codeSample" id="removeMe">Inner Text</div>

removeClassName

Spry.Utils.removeClassName(element,classname);

Description

removeClassName will remove a CSS class to the specified element. A class attribute does not have to be defined on the element, it can remove a class that has been set with addClassName(). If the element has an existing class applied, this function will remove the class name to the element.

Arguments

element

classname

Example

<style type="text/css">
<!--
.dada {
background-color: #FFCC33;
}
-->
</style> <script> function removeClass(ele,class){
Spry.Utils.removeClassName(ele,class);
} </script> <a href="#" onclick="removeClass('content','dada');">Remove Class</a> <div id="content" class="dada">Change This Text</div>

removeEventListener

Spry.Utils.removeEventListener = function(element, eventType, handler, capture)

Description

removeEventListener removes the non-destructive event listener specified. See addEventListener

Arguments

element

eventType

handler

 

stringToXMLDoc

Spry.Utils.stringToXMLDoc(xmlStr);

Description

stringToXMLDoc converts a string that is XML into an actual XML DOM object. This object can now be used as a source for a data set.

Argument

xmlStr

Example

var xmlStr = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?> \
<employees xmlns=\"http://www.foo.com/employees\"> \
<employee id=\"123456\"> \
<lastname>Smith</lastname> \
<firstname>Edward</firstname> \
<phone>(415) 333-0235 </phone> \
<username>esmith</username> \
</employee> \
<employee id=\"127937\"> \
<lastname>Johnson</lastname> \
<firstname>Neil</firstname> \
<phone>(415) 333-9475 </phone> \
<username>njohnson</username> \
</employee> \ </employees>";
var dsEmployees = new Spry.Data.XMLDataSet(null, "/employees/employee");
var xmlDOMDocument = Spry.Utils.stringToXMLDoc(xmlStr);
dsEmployees.setDataFromDoc(xmlDOMDocument);