Spry Utilities

addClassName

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.

Format

Spry.Utils.addClassName(element,classname);

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

Description

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

Format

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

Arguments

element

eventType

handler

capture

Example

<div id="myDiv">Click me!</div>  ...  
<script type="text/javascript>  
  function myClickHandler(event) { 	
    alert("myClickHandler was called!"); 
  }  
Spry.Utils.addEventListener("myDiv", "click", myClickHandler, false);  
</script>

addLoadListener

Description

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

Format

Spry.Utils.addLoadListener = function(handler)

Arguments

Handler

Example

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

eval

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.

Format

Spry.Utils.eval(string);

Arguments

String

Example

Spry.Utils.eval("alert('Run Eval');";

getNodeText

Description

Returns the text of the specified Element

Format

Spry.Utils.getNodeText(elementID);

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

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 req = Spry.Utils.loadURL("GET", "/app/book.php?id=1&code=54321", true);

Sample

loadURL Sample

removeClassName

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.

Format

Spry.Utils.removeClassName(element,classname);

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

Description

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

Format

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

Arguments

element

eventType

handler

Example

<script type="text/javascript>     
function myClickHandler(event) { 	     
alert("myClickHandler was called!");    
}   
Spry.Utils.removeEventListener("myDiv", "click", myClickHandler, false);   
script>

stringToXMLDoc

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.

Format

Spry.Utils.stringToXMLDoc(xmlStr);

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);

Copyright © 2007. Adobe Systems Incorporated.
All rights reserved.