## 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

- The ID of the element that is getting the class

classname

- The css class name to be appended to the element.

#### 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

- The ID or the DOM node of the element that you want to attach an event handler to.

eventType

- The event being listened for. This can be things like onPostLoad or onChange.

handler

- The function that will fire when the event is received.

capture

- If true, event handlers triggered during the capture phase (non IE browsers only)

#### 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

- The function that will fire when the event is received.

#### 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

- the string to be evaluated.

#### Example

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

### getNodeText

#### Description

Returns the text of the specified Element

#### Format

Spry.Utils.getNodeText(elementID);

#### Arguments

elementiD

- The ID of the element.

#### 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

- The method of sending the server request.
  - GET
  - POST

url

- Tthe URL source for the request.

async

- Decides whether the request is synchronous or asynchronous.

#### 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

#### Description

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

#### Format

Spry.Utils.removeAllChildren(elementID);

#### Arguments

elementiD

- The ID of the element.

#### 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

#### 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

- Tthe ID of the element that is losing the class

classname

- Tthe css class name to be removed from the element.

#### 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

- The ID or the DOM node of the element that you want to remove an event handler from.

eventType

- The event being listened for. This can be things like onPostLoad or onChange.

handler

- Tthe function that was to fire when the event was received.

#### 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

- The XML string to be converted.

#### 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.