Attributes | Name and Description |
---|---|
|
caplin.dom.Utility()
|
Attributes | Name and Description |
---|---|
<static>
|
void
addAndRemoveClassNames(Element element, String classesToAdd, String classesToRemove)
Adds and/or removes the specified class names from the specified element. |
<static>
|
void
addClassName(Element element, String className)
Adds the specified class name to the list of CSS classes on the given element, if the class does not already exist. |
<static>
|
Number
addEventListener(Object targetElem, String eventName, Function eventListener, boolean directAttachedEvent, bUseCapture)
Registers the specified event function to a particular event using the provided DOM element. |
<static>
|
void
addScrollListener(Function scrollListener)
Registers a global listener for mouse scroll events. |
<static>
|
Function
createMethodEventListener(Object obj, String method, Array staticArguments)
Creates an event listener (a function pointer) that allows a method to be called on an object when that event is fired. |
<static>
|
void
discard()
Discards one or more elements (all arguments passed will be discarded) by removing children, and removing it from any parentNode. |
<static>
|
DOMElement
getAncestorElementWithClass(Element element, String className)
Returns the first element that contains the given class as part of its |
<static>
|
String
getComputedStyle(DOMElement element, String styleName)
Computes current style of a DOM Element, converting it to pixels where appropriate. |
<static>
|
Object
getElementOffsetValues(Object element)
Returns the bounding rectangle of the specified element. |
<static>
|
Object
getElementPosition(DOMElement element)
Returns the absolute position of the element relative to the window in pixels. |
<static>
|
Array
getElementsByClassName(DOMElement domElement, String tagName, String className)
Returns an array of DOM elements that match the specified tag name and class name. |
<static>
|
DOMElement
getLastChildWithClassName(DOMElement parentElement, String className)
Returns the last child element that contains the specified CSS class. |
<static>
|
Array
getMousePosition(Event event)
Returns the mouse position for the specified event. |
<static>
|
Number
getNodeIndex(Element element)
Returns the node index of the element as it exists in the parent. |
<static>
|
String
getScrollBarWidth()
Returns the computed current width of scrollBar. |
<static>
|
Object
getScrollOffset(Element element)
Returns the scrolled offset of the element (if any) in an object containing a left and top properties. |
<static>
|
Boolean
hasClassName(Element element, String className)
Returns |
<static>
|
void
insertAfter(Element element, Element referenceElement)
Inserts the specified node immediately after the reference element. |
<static>
|
Boolean
isElementAncestorOfElement(Element possibleAncestor, Element possibleChildElement)
Checks to see if the specified ancestor element contains the specified child element. |
<static>
|
Boolean
isMouseLeaveOrEnter(Event event, Element element)
Determines whether the event is the equivalent of the microsoft mouseleave or mouseenter events. |
<static>
|
Boolean
preventEventDefault(Event event)
Allows the user to prevent the default event, with the use |
<static>
|
void
removeChild(Element childElement)
Removes the specified child from its parent. |
<static>
|
void
removeClassName(Element element, String className)
Removes the CSS class name from the specified element. |
<static>
|
void
removeEventListener(Element targetElem, String eventName, Function eventListener)
Removes the specified event listener function from the element. |
<static>
|
void
removeEventListenerById(Number uniqueListenerId)
Removes the DOM event listener that has previously been added via the caplin.dom.Utility#addEventListener method. |
<static>
|
void
replaceClassName(Element element, String currentClass, String newClass)
Replaces the specified CSS class name on the DOM element with another class. |
<static>
|
void
setInnerHtml(Element element, String html)
Sets the innerHTML of the specified element in an efficient way. |
<static>
|
void
stopEventPropagation(Event event)
Stops the propagation of an event. |
►
caplin.dom.Utility()
►
<static>
void
addAndRemoveClassNames(Element element, String classesToAdd, String classesToRemove)
Adds and/or removes the specified class names from the specified element. This operation is performed in a single DOM action, making this more efficient than adding/removing the classes individually. If a class exists in both the add and remove lists, the class will be added to the element.
Element | element | The HTML DOM element to make the class changes to. |
String | classesToAdd | The list of class names that will be added to the list of existing classes. |
String | classesToRemove | The list of class names that will be removed from the list of existing classes. |
►
<static>
void
addClassName(Element element, String className)
Adds the specified class name to the list of CSS classes on the given element, if the class does not already exist.
Element | element | The HTML DOM element to add the CSS class to. |
String | className | The class name that will be added to the list of existing classes. |
►
<static>
Number
addEventListener(Object targetElem, String eventName, Function eventListener, boolean directAttachedEvent, bUseCapture)
Registers the specified event function to a particular event using the provided DOM element.
Object | targetElem | The document element the event will be registered against. |
String | eventName | The name of the event that will be registered (e.g. 'click', but not 'onclick'). |
Function | eventListener | The function that will be called when the event fires. |
boolean | directAttachedEvent | Whether the simpler form of event registration (e.g. elem.onclick )
should be used (false by default). This is still occasionally useful in IE when you want access to the
target element and that is different to window.event.srcElement . |
bUseCapture |
►
<static>
void
addScrollListener(Function scrollListener)
Registers a global listener for mouse scroll events.
This method is used rather than #addEventListener since the registration of mouse scroll events differs
in IE, Opera, and standards compliant browsers. Furthermore, the event parameter passed through as the first
parameter to scrollListener
can be relied upon to exist, even in IE, and has been pre-normalized
using the caplin.dom.event.Event#getNormalizedEvent method, since the format of the scroll
detail
differs so widely.
Function | scrollListener |
►
<static>
Function
createMethodEventListener(Object obj, String method, Array staticArguments)
Creates an event listener (a function pointer) that allows a method to be called on an object when that event is fired.
Normal event listeners are function pointers which make object-oriented programming difficult. The function
pointer returned by this method merely calls the desired method on the specified object so that the
this
pointer is still available.
Each time an event occurs where this event listener has been attached, the method will be called with a single
event parameter, event
, which is the browser event object. Optionally, if
staticArguments
is provided then the arguments within this array will be appended to the method
parameters for each method call.
The last object passed into the callback method method will be the DOM element which triggered the event firing, for example, the button that was clicked or hovered over.
Object | obj | the object the method will be called on. |
String | method | the name of the method to call. |
Array | staticArguments Optional | The arguments that, if provided, will be appended as parameters to the given method. |
►
<static>
void
discard()
Discards one or more elements (all arguments passed will be discarded) by removing children, and removing it from any parentNode.
►
<static>
DOMElement
getAncestorElementWithClass(Element element, String className)
Returns the first element that contains the given class as part of its className
string.
Element | element | the element to start the search at. |
String | className | the class name to look for. |
►
<static>
String
getComputedStyle(DOMElement element, String styleName)
Computes current style of a DOM Element, converting it to pixels where appropriate.
DOMElement | element | Element to get style for. |
String | styleName | Css style name. IE. border-width. |
►
<static>
Object
getElementOffsetValues(Object element)
Returns the bounding rectangle of the specified element.
Object | element | The element to get the bounding recangle for. |
►
<static>
Object
getElementPosition(DOMElement element)
Returns the absolute position of the element relative to the window in pixels. The position also takes into account any scrolling of parents.
DOMElement | element | The DOM element to calculate the position of |
►
<static>
Array
getElementsByClassName(DOMElement domElement, String tagName, String className)
Returns an array of DOM elements that match the specified tag name and class name.
DOMElement | domElement | The DOM element that should be used as the root of the search. |
String | tagName | The tag name (can be *) of elements to search for. |
String | className | The CSS class name of the elements to search for. |
►
<static>
DOMElement
getLastChildWithClassName(DOMElement parentElement, String className)
Returns the last child element that contains the specified CSS class.
DOMElement | parentElement | The parent to use as the root. |
String | className | The class of the wanted last child element. |
►
<static>
Array
getMousePosition(Event event)
Returns the mouse position for the specified event.
Event | event | The event object for which to get the mouse co-ordinates |
►
<static>
Number
getNodeIndex(Element element)
Returns the node index of the element as it exists in the parent.
Element | element | The element to get the index for. |
►
<static>
String
getScrollBarWidth()
Returns the computed current width of scrollBar.
►
<static>
Object
getScrollOffset(Element element)
Returns the scrolled offset of the element (if any) in an object containing a left and top properties.
Element | element | The DOM element to calculate the scrolled offset of. |
►
<static>
Boolean
hasClassName(Element element, String className)
Returns true
if the specified class name exists on the element.
Element | element | The DOMElement to check. |
String | className | The class name to check. |
true
if the specified class name exists on the element.
►
<static>
void
insertAfter(Element element, Element referenceElement)
Inserts the specified node immediately after the reference element.
This convenience method saves the programmer from having to determine whether to call insertBefore()
or appendChild()
, depending on whether the reference element is the last child node.
Element | element | The element to insert. |
Element | referenceElement | The reference element to insert the element after. |
►
<static>
Boolean
isElementAncestorOfElement(Element possibleAncestor, Element possibleChildElement)
Checks to see if the specified ancestor element contains the specified child element.
Element | possibleAncestor | The element that is presumed to be a parent node. |
Element | possibleChildElement | The element to start the search at. |
►
<static>
Boolean
isMouseLeaveOrEnter(Event event, Element element)
Determines whether the event is the equivalent of the microsoft mouseleave or mouseenter events. This method assumes the event being passed is a mouseout or mouseenter and has undefined results if this isn't the case.
Event | event | A mouseover or mouseout event object. |
Element | element | The element we want to test against for mouseenter/mouseleave. |
►
<static>
Boolean
preventEventDefault(Event event)
Allows the user to prevent the default event, with the use return Utility.preventEventDefault(event);
.
Event | event | Event passed to your event handler. Note that event handlers are not wrapped so you need to do
something like event = event || window.event; . |
►
<static>
void
removeChild(Element childElement)
Removes the specified child from its parent.
Element | childElement | The child to remove. |
►
<static>
void
removeClassName(Element element, String className)
Removes the CSS class name from the specified element.
Element | element | The HTML element that the class name should be removed from. |
String | className | The CSS class to remove from the element. |
►
<static>
void
removeEventListener(Element targetElem, String eventName, Function eventListener)
Removes the specified event listener function from the element.
Element | targetElem | The element to remove the event from. |
String | eventName | The name of the event to remove the listener from. |
Function | eventListener | The event listener to remove. |
►
<static>
void
removeEventListenerById(Number uniqueListenerId)
Removes the DOM event listener that has previously been added via the caplin.dom.Utility#addEventListener method.
Number | uniqueListenerId | The event Listener Id that was returned by the method caplin.dom.Utility#addEventListener. |
►
<static>
void
replaceClassName(Element element, String currentClass, String newClass)
Replaces the specified CSS class name on the DOM element with another class.
Element | element | The HTML DOM element to add the class to. |
String | currentClass | The class name to replace. |
String | newClass | The new name of the class. |
►
<static>
void
setInnerHtml(Element element, String html)
Sets the innerHTML of the specified element in an efficient way.
Element | element | The element on which innerHTML needs to be set. |
String | html | The HTML that will be set in the element. |
►
<static>
void
stopEventPropagation(Event event)
Stops the propagation of an event. This method should be used within an event listener to prevent bubbling of an event up to other event listeners.
Event | event | Event passed to your event handler. Note that event handlers are not wrapped so you need to do
something like event = event || window.event; . |