wax.Element
TypeComponent
Ownerwax
Dependencieswax.Core, wax
BaseNone
Element tagdiv
Description

The base for all components. An empty component providing basic, essential functionality.

The component is extended by wax.EventHandler to give it event handling capabilities.

Attributes
flex
number

Determines the flexibility of the element, which is the amount of space it 'grabs' when placed inside a wax.Box, expressed in ratio form. For example, if a box contains an element with flex 2, and another with flex 1, the first element will get twice the size as the second one: two thirds and one third of the total available space, respectively.

The attribute can take both integer and rational values. With a value of 0 the element is declared non-flexible, and will retain its full size, unaffected by changes on the box (useful on toolbars, status bars, etc). The default value is 1.

tooltip
text

Gets or sets the tooltip text for the element (displayed when the mouse hovers over an element, equivalent to the HTML title attribute, or alt on some browsers).

display
boolean

Determines wether the object is displayed (true) or hidden (false). If hidden, the display style of the object is set to none; when visible, the style is given the appropiate value matching the element's tag.

disabled
boolean

When set to true, the element doesn't react to user interaction.

draggable
boolean

Determines if the element can be dragged to start a drag and drop operation. The actual dragged item doesn't need to be the element itself, and is determined by the element's getDragElem method.

contextMenu
object

A reference to an instance of wax.Menu (or a derived component) that will be popped up when the user requests a context menu on the element (usually by right-clicking it). If set to null, the default context menu provided by the browser is raised.

Methods
getContainer
element getContainer(boolean internal)

Indicates the item where content added to the element is appended. An item is declared to be the item's container by giving it an id of 'content'. If there's no container item, the element itself is returned (which means content will be directly appended to the element's root).

internalboolean

Indicates wether to select the container for anonymous content or for internal items (which in practice returns the element itself).

add
void add(element child, boolean internal = false)

Appends the given child element to the element's container, indicated by getContainer. The child can be added as content, or as an structural part of the element.

childelement

The child element that is to be appended to the element.

internalboolean

If set to true, the child is added as an inner part of the element. It will be ignored when counting the items inside the element, emptying content, etc. For all purposes, it will be considered a structural block of the element.

remove
void remove()

Removes the element from its owner.

pack
void pack()

This method is called recursively on all elements every time they are affected by a layout change, so that they can react to it and readjust their size and position. The default implementation does nothing more than calling itself recursively on all items inside the element (wether internal or content). It's up to each subclass to extend this behavior.

empty
void empty(boolean internal = false)

Removes all content items from the element.

internalboolean

If set to true, internal items are removed as well, and the element is totally emptied.

raise
void raise()

Increments the element's z-index to match the one from the currently most prominent element, so that it doesn't get overlapped by other elements.

hangsFrom
boolean hangsFrom(element ancestor)

Indicates if the given element is an ancestor of the element.

ancestorelement

A reference to the possible ancestor element.

getDocX
number getDocX()

Calculates the horizontal coordinate of the element (in pixels), relative to the whole document.

getDocY
number getDocY()

Calculates the vertical coordinate of the element (in pixels), relative to the whole document.

getMouseX
number getMouseX(event e)

Calculates the horizontal coordinate of the mouse cursor (in pixels), relative to the element.

eevent

A mouse event object.

getMouseY
number getMouseY(event e)

Calculates the vertical coordinate of the mouse cursor (in pixels), relative to the element.

eevent

A mouse event object.

acceptDrop
boolean acceptDrop(element elem, element src)

Used to determine wether a dragged element can be dropped on the element. For example, if you want an element to discard all dropped elements except for a certain component, you can do:

element.acceptDrop = function (elem) { return (elem.component == myComponent); }

elemelement

The currently dragged element.

srcelement

The element that started the drag and drop operation.

drag
void drag(event e)

Starts a drag and drop operation on the object, dragging the element returned by getDragElem.

eevent

A mouse event object, used to calculate dragging offsets.

getDragElem
element getDragElem()

Returns the element that should be dragged when a drag and drop operation is started on the element. By default it returns the element itself.