Object | +--YAHOO.ext.Element
Wraps around a DOM element and provides convenient access to Yahoo
UI library functionality.
Usage:
var el = YAHOO.ext.Element.get('myElementId');
// or the shorter
var el = getEl('myElementId');
Using YAHOO.ext.Element.get() instead of calling the constructor directly ensures you get the same object
each call instead of constructing a new one.| Field Summary | |
Object |
autoBoxAdjust
Whether to automatically adjust width and height settings for box-model issues |
String |
defaultUnit
The default unit to append to CSS values where a unit isn't provided (Defaults to px). |
String |
id
The DOM element ID |
CustomEvent |
onMoved
Fires when element moves. |
CustomEvent |
onResized
Fires when element is resized. |
CustomEvent |
onVisibilityChanged
Fires when visibility changes. |
<static> Number |
DISPLAY
Visibility mode constant - Use display to hide element |
<static> Number |
VISIBILITY
Visibility mode constant - Use visibility to hide element |
| Constructor Summary | |
YAHOO.ext.Element
(<String> elementId, <Boolean> forceNew)
|
|
| Method Summary * Parameter types in italic indicate optional parameters | |
void
|
addClass(<String> className)
Add a CSS class to the element. |
void
|
addHandler(<String> eventName, <Boolean> stopPropagation, <Function> handler, <Object> scope, <boolean> override)
Appends an event handler to this element and automatically prevents the default action, and if set stops propagation (bubbling) as well |
void
|
addListener(<String> eventName, <Function> handler, <Object> scope, <boolean> override)
Appends an event handler to this element |
Object
|
addManagedListener(<String> eventName, <Function> fn, <Object> scope, <boolean> override)
Append a managed listener - See YAHOO.ext.EventObject for more details. |
void
|
alignTo(<String/HTMLElement/YAHOO.ext.Element> element, <String> position, <Array> offsets, <Boolean> animate, <Float> duration, <Function> onComplete, <Function> easing)
Align this element with another element. |
void
|
animate(<Object> args, <Float> duration, <Function> onComplete, <Function> easing, <Function> animType)
Perform Yahoo UI animation on this element. |
void
|
beginMeasure()
|
void
|
clearOpacity()
Clears any opacity settings from this element. |
void
|
clearPositioning()
Clear positioning back to the default when the document was loaded |
void
|
clip()
Clip overflow on the element - use unclip() to remove |
void
|
enableDisplayMode()
Convenience method for setVisibilityMode(Element.DISPLAY) |
void
|
endMeasure()
|
void
|
focus()
Tries to focus the element. |
Number
|
getBorderWidth(<String> side)
Gets the width of the border(s) for the specified side(s) |
String
|
getBottom()
Gets the bottom Y coordinate of the element (element Y position + element height) |
void
|
getBox(contentBox)
Return a box {x, y, width, height} that can be used to set another elements size to match this element. |
Array
|
getCenterXY(offsetScroll)
Calculates the x, y to center this element on the screen |
Array
|
getChildrenByClassName(<String> className, <String> tagName)
Gets an array of child YAHOO.ext.Element objects by class name and optional tagName |
Array
|
getChildrenByTagName(<String> tagName)
Gets an array of child YAHOO.ext.Element objects by tag name |
Number
|
getHeight()
Returns the offset height of the element |
Object
|
getLeft()
Same as getX() |
Number
|
getPadding(<String> side)
Gets the width of the padding(s) for the specified side(s) |
void
|
getPositioning()
Gets an object with all CSS positioning properties. |
Region
|
getRegion()
Returns the region position of the given element. |
String
|
getRight()
Gets the right X coordinate of the element (element X position + element width) |
Object}
|
getSize()
Returns the size of the element |
String
|
getStyle(name)
Normalizes currentStyle and ComputedStyle. |
Object
|
getTop()
Same as getY() |
YAHOO.ext.UpdateManager
|
getUpdateManager()
Gets this elements UpdateManager |
Number
|
getWidth()
Returns the offset width of the element |
Object
|
getX()
Gets the current X position of the element based on page coordinates. |
Object
|
getXY()
Gets the current position of the element based on page coordinates. |
Object
|
getY()
Gets the current Y position of the element based on page coordinates. |
Boolean
|
hasClass(<String> className)
Checks if a CSS class is in use by the element. |
void
|
hide(<Boolean> animate, <Float> duration, <Function> onComplete, <Function> easing)
Hide this element - Uses display mode to determine whether to use "display" or "visibility". |
void
|
isBorderBox()
Tests various css rules/browsers to determine if this element uses a border box |
Boolean
|
isVisible(<Boolean> deep)
Checks whether the element is currently visible using both visibility and display properties. |
Object
|
mon(<String> eventName, <Function> fn, <Object> scope, <boolean> override)
Append a managed listener (shorthanded for addManagedListener()) |
void
|
move(<String> direction, <Number> distance, <Boolean> animate, <Float> duration, <Function> onComplete, <Function> easing)
Move this element relative to it's current position. |
void
|
moveTo(<Number> x, <Number> y, <Boolean> animate, <float> duration, <Function> onComplete, <Function> easing)
Set the position of the element in page coordinates, regardless of how the element is positioned. |
void
|
on(<String> eventName, <Function> handler, <Object> scope, <boolean> override)
Appends an event handler to this element (Same as addListener) |
void
|
radioClass(className)
Adds the passed className to this element and removes the class from all siblings |
void
|
removeAllListeners()
Removes all previous added listeners from this element |
void
|
removeClass(<String> className)
Removes a CSS class from the element. |
void
|
removeListener(eventName, handler)
Removes an event handler from this element |
void
|
replaceClass(<String> oldClassName, <String> newClassName)
Replaces a CSS class on the element with another. |
void
|
setAbsolutePositioned(<Number> zIndex)
Set the element as absolute positioned with the specified z-index |
void
|
setBottom(bottom)
Set the element's css bottom style |
void
|
setBounds(<Number> x, <Number> y, <Number> width, <Number> height, <Boolean> animate, <float> duration, <Function> onComplete, <Function> easing)
Sets the element's position and size in one shot. |
void
|
setBox(<Object> box, <Boolean> adjust, <Boolean> animate, <float> duration, <Function> onComplete, <Function> easing)
Sets the element's box. |
void
|
setHeight(<Number> height, <Boolean> animate, <float> duration, <Function> onComplete, <Function> easing)
Set the height of the element |
void
|
setLeft(<String> left)
Set the element's X position directly using CSS style (instead of setX()) |
void
|
setLocation(<Number> x, <Number> y, <Boolean> animate, <float> duration, <Function> onComplete, <Function> easing)
Set the position of the element in page coordinates, regardless of how the element is positioned. |
void
|
setOpacity(<Float> opacity, <Boolean> animate, <Float> duration, <Function> onComplete, <Function> easing)
Set the opacity of the element |
void
|
setPositioning(positionCfg)
Set positioning with an object returned by getPositioning(). |
void
|
setRegion(<YAHOO.util.Region> region, <Boolean> animate, <float> duration, <Function> onComplete, <Function> easing)
Sets the element's position and size the the specified region. |
void
|
setRelativePositioned(<Number> zIndex)
Set the element as relative positioned with the specified z-index |
void
|
setRight(right)
Set the element's css right style |
void
|
setSize(<Number> width, <Number> height, <Boolean> animate, <float> duration, <Function> onComplete, <Function> easing)
Set the size of the element. |
void
|
setStyle(name, value)
Wrapper for setting style properties |
void
|
setTop(<String> top)
Set the element's Y position directly using CSS style (instead of setY()) |
void
|
setVisibilityMode(visMode)
Sets the elements visibility mode. |
void
|
setVisible(<Boolean> visible, <Boolean> animate, <Float> duration, <Function> onComplete, <Function> easing)
Sets the visibility of the element (see details). |
void
|
setWidth(<Number> width, <Boolean> animate, <float> duration, <Function> onComplete, <Function> easing)
Set the width of the element |
void
|
setX(x)
Sets the X position of the element based on page coordinates. |
void
|
setXY(<Array> pos, <Boolean> animate, <float> duration, <Function> onComplete, <Function> easing)
Set the position of the element in page coordinates, regardless of how the element is positioned. |
void
|
setY(y)
Sets the Y position of the element based on page coordinates. |
void
|
show(<Boolean> animate, <Float> duration, <Function> onComplete, <Function> easing)
Show this element - Uses display mode to determine whether to use "display" or "visibility". |
void
|
toggle(<Boolean> animate, <float> duration, <Function> onComplete, <Function> easing)
Toggles the elements visibility or display, depending on visibility mode. |
void
|
toggleClass(className)
|
void
|
unclip()
Return clipping (overflow) to original clipping when the document loaded |
void
|
update(<String> html, <Boolean> loadScripts)
Update the innerHTML of this element, optionally searching for and processing scripts |
<static> Element
|
get(<String/HTMLElement/Element> el, <Boolean> autoGenerateId)
Static method to retreive Element objects. |
| Field Detail |
Object autoBoxAdjust
String defaultUnit
String id
CustomEvent onMoved
CustomEvent onResized
CustomEvent onVisibilityChanged
<static> Number DISPLAY
<static> Number VISIBILITY
| Constructor Detail |
YAHOO.ext.Element(<String> elementId, <Boolean> forceNew)
elementId -
forceNew - (optional) By default the constructor checks to see if there is already an instance of this element in the cache and if there is it returns the same instance. This will skip that check (useful for extending this class).
| Method Detail |
void addClass(<String> className)
className - The CSS class to add
void addHandler(<String> eventName, <Boolean> stopPropagation, <Function> handler, <Object> scope, <boolean> override)
eventName - The type of event to listen for
stopPropagation - Whether to also stopPropagation (bubbling)
handler - The method the event invokes
scope - (optional) An arbitrary object that will be passed as a parameter to the handler
override - (optional) If true, the obj passed in becomes the execution scope of the listener
void addListener(<String> eventName, <Function> handler, <Object> scope, <boolean> override)
eventName - The type of event to listen for
handler - The method the event invokes
scope - (optional) An arbitrary object that will be passed as a parameter to the handler
override - (optional) If true, the obj passed in becomes the execution scope of the listener
Object addManagedListener(<String> eventName, <Function> fn, <Object> scope, <boolean> override)
eventName - The type of event to listen for
fn - The method the event invokes
scope - (optional) An arbitrary object that will be passed as a parameter to the handler
override - (optional) If true, the obj passed in becomes the execution scope of the listener
void alignTo(<String/HTMLElement/YAHOO.ext.Element> element, <String> position, <Array> offsets, <Boolean> animate, <Float> duration, <Function> onComplete, <Function> easing)
element - The element to align to.
position - The position to align to. Possible values are 'tl' - top left, 'tr' - top right, 'bl' - bottom left, and 'br' - bottom right.
offsets - (optional) Offset the positioning by [x, y]
animate - (optional) Animate the movement (Default is false)
duration - (optional) How long the animation lasts. (Defaults to .35 seconds)
onComplete - (optional) Function to call when animation completes.
easing - (optional) YAHOO.util.Easing method to use.
void animate(<Object> args, <Float> duration, <Function> onComplete, <Function> easing, <Function> animType)
args - The YUI animation control args
duration - (optional) How long the animation lasts. (Defaults to .35 seconds)
onComplete - (optional) Function to call when animation completes.
easing - (optional) YAHOO.util.Easing method to use. (Defaults to YAHOO.util.Easing.easeBoth)
animType - (optional) YAHOO.util.Anim subclass to use. For YAHOO.ext.Element.prototype.example = YAHOO;.util.Motion
void beginMeasure()
void clearOpacity()
void clearPositioning()
void clip()
void enableDisplayMode()
void endMeasure()
void focus()
Number getBorderWidth(<String> side)
side - Can be t, l, r, b or any combination of those to add multiple values. For example, passing lr would get the border (l)eft width + the border (r)ight width.
String getBottom()
void getBox(contentBox)
Array getCenterXY(offsetScroll)
Array getChildrenByClassName(<String> className, <String> tagName)
className -
tagName - (optional)
Array getChildrenByTagName(<String> tagName)
tagName -
Number getHeight()
Object getLeft()
Number getPadding(<String> side)
side - Can be t, l, r, b or any combination of those to add multiple values. For example, passing lr would get the padding (l)eft + the padding (r)ight.
void getPositioning()
Region getRegion()
String getRight()
Object} getSize()
String getStyle(name)
property - The style property whose value is returned.
Object getTop()
YAHOO.ext.UpdateManager getUpdateManager()
Number getWidth()
Object getX()
Object getXY()
Object getY()
Boolean hasClass(<String> className)
className - The CSS class to check
void hide(<Boolean> animate, <Float> duration, <Function> onComplete, <Function> easing)
animate - (optional) Animate (fade) the transition (Default is false)
duration - (optional) How long the animation lasts. (Defaults to .35 seconds)
onComplete - (optional) Function to call when animation completes.
easing - (optional) YAHOO.util.Easing method to use. (Defaults to YAHOO.util.Easing.easeBoth)
void isBorderBox()
Boolean isVisible(<Boolean> deep)
deep - True to walk the dom and see if parent elements are hidden
Object mon(<String> eventName, <Function> fn, <Object> scope, <boolean> override)
eventName - The type of event to listen for
fn - The method the event invokes
scope - (optional) An arbitrary object that will be passed as a parameter to the handler
override - (optional) If true, the obj passed in becomes the execution scope of the listener
void move(<String> direction, <Number> distance, <Boolean> animate, <Float> duration, <Function> onComplete, <Function> easing)
direction - Possible values YAHOO.ext.Element.prototype.are = 'left'; 'right', 'up', 'down'.
distance - How far to move the element in pixels
animate - (optional) Animate the movement (Default is false)
duration - (optional) How long the animation lasts. (Defaults to .35 seconds)
onComplete - (optional) Function to call when animation completes.
easing - (optional) YAHOO.util.Easing method to use.
void moveTo(<Number> x, <Number> y, <Boolean> animate, <float> duration, <Function> onComplete, <Function> easing)
x - X value for new position (coordinates are page-based)
y - Y value for new position (coordinates are page-based)
animate - (optional) Animate the transition (Default is false)
duration - (optional) How long the animation lasts. (Defaults to .35 seconds)
onComplete - (optional) Function to call when animation completes.
easing - (optional) YAHOO.util.Easing method to use. (Defaults to YAHOO.util.Easing.easeBoth)
void on(<String> eventName, <Function> handler, <Object> scope, <boolean> override)
eventName - The type of event to listen for
handler - The method the event invokes
scope - (optional) An arbitrary object that will be passed as a parameter to the handler
override - (optional) If true, the obj passed in becomes the execution scope of the listener
void radioClass(className)
void removeAllListeners()
void removeClass(<String> className)
className - The CSS class to remove
void removeListener(eventName, handler)
sType - the type of event to remove
fn - the method the event invokes
void replaceClass(<String> oldClassName, <String> newClassName)
oldClassName - The CSS class to replace
newClassName - The replacement CSS class
void setAbsolutePositioned(<Number> zIndex)
zIndex - (optional)
void setBottom(bottom)
top - The bottom CSS property value
void setBounds(<Number> x, <Number> y, <Number> width, <Number> height, <Boolean> animate, <float> duration, <Function> onComplete, <Function> easing)
x - X value for new position (coordinates are page-based)
y - Y value for new position (coordinates are page-based)
width - The new width
height - The new height
animate - (optional) Animate the transition (Default is false)
duration - (optional) How long the animation lasts. (Defaults to .35 seconds)
onComplete - (optional) Function to call when animation completes.
easing - (optional) YAHOO.util.Easing method to use. (Defaults to YAHOO.util.Easing.easeBoth)
void setBox(<Object> box, <Boolean> adjust, <Boolean> animate, <float> duration, <Function> onComplete, <Function> easing)
box - The box to fill {x, y, width, height}
adjust - (optional) Whether to adjust for box-model issues automatically
animate - (optional) Animate the transition (Default is false)
duration - (optional) How long the animation lasts. (Defaults to .35 seconds)
onComplete - (optional) Function to call when animation completes.
easing - (optional) YAHOO.util.Easing method to use. (Defaults to YAHOO.util.Easing.easeBoth)
void setHeight(<Number> height, <Boolean> animate, <float> duration, <Function> onComplete, <Function> easing)
height - The new height
animate - (optional) Animate the transition (Default is false)
duration - (optional) How long the animation lasts. (Defaults to .35 seconds)
onComplete - (optional) Function to call when animation completes.
easing - (optional) YAHOO.util.Easing method to use. (Defaults to YAHOO.util.Easing.easeOut if height is larger or YAHOO.util.Easing.easeIn if it is smaller)
void setLeft(<String> left)
left - The left CSS property value
void setLocation(<Number> x, <Number> y, <Boolean> animate, <float> duration, <Function> onComplete, <Function> easing)
x - X value for new position (coordinates are page-based)
y - Y value for new position (coordinates are page-based)
animate - (optional) Animate the transition (Default is false)
duration - (optional) How long the animation lasts. (Defaults to .35 seconds)
onComplete - (optional) Function to call when animation completes.
easing - (optional) YAHOO.util.Easing method to use. (Defaults to YAHOO.util.Easing.easeBoth)
void setOpacity(<Float> opacity, <Boolean> animate, <Float> duration, <Function> onComplete, <Function> easing)
opacity - The new opacity. 0 = transparent, .5 = 50% visibile, 1 = fully visible, etc
animate - (optional) Animate (fade) the transition (Default is false)
duration - (optional) How long the animation lasts. (Defaults to .35 seconds)
onComplete - (optional) Function to call when animation completes.
easing - (optional) YAHOO.util.Easing method to use. (Defaults to YAHOO.util.Easing.easeOut if height is larger or YAHOO.util.Easing.easeIn if it is smaller)
void setPositioning(positionCfg)
void setRegion(<YAHOO.util.Region> region, <Boolean> animate, <float> duration, <Function> onComplete, <Function> easing)
region - The region to fill
animate - (optional) Animate the transition (Default is false)
duration - (optional) How long the animation lasts. (Defaults to .35 seconds)
onComplete - (optional) Function to call when animation completes.
easing - (optional) YAHOO.util.Easing method to use. (Defaults to YAHOO.util.Easing.easeBoth)
void setRelativePositioned(<Number> zIndex)
zIndex - (optional)
void setRight(right)
left - The right CSS property value
void setSize(<Number> width, <Number> height, <Boolean> animate, <float> duration, <Function> onComplete, <Function> easing)
width - The new width
height - The new height
animate - (optional) Animate the transition (Default is false)
duration - (optional) How long the animation lasts. (Defaults to .35 seconds)
onComplete - (optional) Function to call when animation completes.
easing - (optional) YAHOO.util.Easing method to use. (Defaults to YAHOO.util.Easing.easeBoth)
void setStyle(name, value)
property - The style property to be set.
val - The value to apply to the given property.
void setTop(<String> top)
top - The top CSS property value
void setVisibilityMode(visMode)
visMode - Element.VISIBILITY or Element.DISPLAY
void setVisible(<Boolean> visible, <Boolean> animate, <Float> duration, <Function> onComplete, <Function> easing)
visible - Whether the element is visible
animate - (optional) Fade the element in or out (Default is false)
duration - (optional) How long the fade effect lasts. (Defaults to .35 seconds)
onComplete - (optional) Function to call when animation completes.
easing - (optional) YAHOO.util.Easing method to use. (Defaults to YAHOO.util.Easing.easeOut for hiding or YAHOO.util.Easing.easeIn for showing)
void setWidth(<Number> width, <Boolean> animate, <float> duration, <Function> onComplete, <Function> easing)
width - The new width
animate - (optional) Animate the transition (Default is false)
duration - (optional) How long the animation lasts. (Defaults to .35 seconds)
onComplete - (optional) Function to call when animation completes.
easing - (optional) YAHOO.util.Easing method to use. (Defaults to YAHOO.util.Easing.easeOut if width is larger or YAHOO.util.Easing.easeIn if it is smaller)
void setX(x)
The - X position of the element
void setXY(<Array> pos, <Boolean> animate, <float> duration, <Function> onComplete, <Function> easing)
pos - Contains X & Y [x, y] values for new position (coordinates are page-based)
animate - (optional) Animate the transition (Default is false)
duration - (optional) How long the animation lasts. (Defaults to .35 seconds)
onComplete - (optional) Function to call when animation completes.
easing - (optional) YAHOO.util.Easing method to use. (Defaults to YAHOO.util.Easing.easeBoth)
void setY(y)
The - Y position of the element
void show(<Boolean> animate, <Float> duration, <Function> onComplete, <Function> easing)
animate - (optional) Animate (fade in) the transition (Default is false)
duration - (optional) How long the animation lasts. (Defaults to .35 seconds)
onComplete - (optional) Function to call when animation completes.
easing - (optional) YAHOO.util.Easing method to use. (Defaults to YAHOO.util.Easing.easeBoth)
void toggle(<Boolean> animate, <float> duration, <Function> onComplete, <Function> easing)
animate - (optional) Fade the element in or out (Default is false)
duration - (optional) How long the fade effect lasts. (Defaults to .35 seconds)
onComplete - (optional) Function to call when animation completes.
easing - (optional) YAHOO.util.Easing method to use. (Defaults to YAHOO.util.Easing.easeOut for hiding or YAHOO.util.Easing.easeIn for showing)
void toggleClass(className)
void unclip()
void update(<String> html, <Boolean> loadScripts)
html - The new HTML
loadScripts - (optional) true to look for and process scripts
<static> Element get(<String/HTMLElement/Element> el, <Boolean> autoGenerateId)
el - The id of the element or the element to wrap (must have an id). If you pass in an element, it is returned
autoGenerateId - (optional) Set this flag to true if you are passing an element without an id (like document.body). It will auto generate an id if one isn't present.