Represents DOM element. Element has sub-objects: attributes and styles.
| Constants | |
|
STATE_LINK
STATE_HOVER
STATE_ACTIVE
STATE_FOCUS
STATE_VISITED
STATE_CURRENT
STATE_CHECKED
STATE_DISABLED
STATE_READONLY
STATE_EXPANDED
STATE_COLLAPSED
STATE_INCOMPLETE
STATE_ANIMATING
STATE_FOCUSABLE
STATE_ANCHOR
STATE_POPUP
STATE_OWNS_POPUP
STATE_EMPTY
STATE_BUSY |
State flags (bits) of the element, used by get/setState functions. TBD. |
| Properties | |
| length | r - integer, number of child elements in this element. Read-only property. |
| [index] | rw - Element, child element of the element at the index position, Read-write index accessor. Zero-based index. |
| root | r - Element, root element of the DOM this element belongs to. Read-only. |
| parent | r - Element, parent element of given element or null if this element is a root element. Read-only. |
| index | r - Integer, index of the element in parent collection. Undefined if this element is not connected to any parent. |
| tag | r - String, tag name of the element. Read-only. |
| next | r - Element, next sibling element of the element or null if this is last element in the parent collection. |
| prior | r - Element, previous sibling element of the element or null if this is first element in the parent collection. |
| first | r - Element, first child (element) of the element or null if there are no children. |
| last | r - Element, last child (element) of the element or null if there are no children. |
| attributes | c - Attributes, collection of html attributes of the element. |
| @ |
c - short form to access Attributes, collection of html attributes of the element. It is just an alias of the attributes above.
Sample: this.@["selected"] = true is an equivalent of this.attributes["selected"] = true |
| style | c - Style, style attributes of the DOM element. |
| state | c - States, collection of states (runtime flags) of the DOM element. |
| text | rw - String, text of the element. For compound elements this property returns plain-text version of the content |
| html | rw - String, (inner HTML) html source of the content of the element. Text returned (String) will not include head and tail tags of the element. Value to set can be either String or Stream object. |
| outerHtml |
rw - String, (outer HTML) html source of the element. Text returned (String) will include head and tail tags of the element.
Value to set can be either String or Stream object. |
| value | rw - String by default and if input behavior is set to the element it is also: integer, boolean, array, etc. For example <input type="radio"> will return true if this radio button has "on" state. |
| prototype | rw - Either Instance of Behavior or Element class object. Prototype can be set to the element through CSS (prototype:name_of_global_behavior_variable) or using this property. |
| isVisible | r - true if element and all its containers are in visible state - no visibility:hidden or display:none defined for them. false - otherwise. |
| isEnabled | r - true if element and all its containers are not in :disabled state ( setState(Element.STATE_DISABLED)). |
| Obsolete properties, replaced by the Style sub object: | |
| enabled | rw - true if element itself is in :disabled state ( Element.STATE_DISABLED). Read/write attribute. |
| checked | rw - true if element itself is in :checked state ( Element.STATE_CHECKED). Read/write attribute. |
| focus | rw - true if element itself has input focus and so in :focus state ( Element.STATE_FOCUS). Read/write attribute. To set focus on the element use: el.focus = true; |
| current | rw - true if element itself is in :current state so is e.g. current <option> in <select>. Read/write attribute. |
| expanded | rw - true if element is in :expanded state, false if it is :collapsed and undefined if neither :expanded nor :collapsed is set. Read/write attribute. |
| Enumeration | |
| for ... in |
for(var node in element) { /* loop body */ }
Executes body of the loop for all child nodes of the element. Value of node variable is either text or element object. Example, for p element in html: |
| Methods | |
| this |
(tagname[, text])
Constructs new Element object with tag equal to tagname (string). Use it as var el = new Element("option"); Element will be created in disconnected state. To connect it to the DOM use insert method of the parent element. |
| toString |
() returns: string
Returns string - html representation of the element. Text returned is outer html - includes head and tail tags and content s equal to text returned by html attribute. |
| clone |
() :Element
Returns new copy of the element. Method performs a deep copy of the element. New element is disconnected from the DOM state. Use insert() method to include it in the DOM. |
| select |
(CSSselector [, argument1 [, argument2, ... ]]) returns: Element
Returns first element satisfying CSS selector (CSSselector, string). CSSSelector may contain format specifiers like %d, %s which will be substituted by values of argument1 ... argumentN in final CSS selector string. Function uses the same rules as does Stream.printf function. Example, if document contains <input type="text"/> element then following statement |
| select |
(func , CSSselector [, argument1 [, argument2, ... ]]) returns: integer
Calls func (function reference) for each element satisfying (matching) CSSselector. Function func shall accept one parameter where select will provide reference to matched element. Function may return true to stop enumeration. Example, following fragment will print out names of all input elements in the document: |
| selectParent |
(CSSselector [, argument1 [, argument2, ... ]]) returns: Element
Returns first element in child/parent chain satisfying CSS selector (CSSselector, string). CSSSelector may contain format specifiers like %d, %s which will be substituted by values of argument1 ... argumentN in final CSS selector string. Function uses the same rules as does Stream.printf function. ATTN: Function also inspects this element. |
| selectParent |
(func , CSSselector [, argument1 [, argument2, ... ]]) returns: integer
Calls func (function reference) for each element satisfying (matching) CSSselector. Function func shall accept one parameter where select will provide reference to matched element. Function may return true to stop enumeration. Example, following fragment will print out ids of all parent divs of some element: ATTN: Function also inspects this element. |
| match |
(CSSselector [, argument1 [, argument2, ... ]]) returns: true | false
Checks if this DOM element satisfies given CSSselector. |
| find |
(x, y) returns: Element.
Returns reference to child element of the given element at x,y coordinates relative to the origin of the element. If there is no such element method returns element itself. |
| update |
([deep]) returns: undefined
Remeasures given element (if deep == true) and invalidates its visual area after modifications. Use deep=true value if element will get new dimensions due to some operations on it. Omit deep parameter (or set it to false) if only decoration attributes (not changing dimensions, like color) were changed. |
| refresh |
( [x, y, width, height] ) returns: true|false
Invalidates area of occupied by the element on the screen. If x , y, width, height (coordinates of area inside element) are provided then it invalidates only that portion. This method is useful if you are using Graphics for rendering on element surface area. |
| animate |
( nextStep: function ) : undefined
Starts animation on the element. nextStep is a function that executes animation step (changes dimension, opacity, etc.). This function is called with this set to the element itself and should return integer - number of milliseconds for the next step. If it returns zero or not an integer then animation stops. |
| box |
( part [, edge [, relativeTo ]] ) returns: integer, device pixels
Returns coordinates of the edges of the element. Parameters:
|
| scroll |
(part) returns: integer, device pixelsReturns various scrolling related positions of the element. Parameters: part - one of symbolic constants:
|
| scrollToView |
( [toTop:bool] )
Scrolls the element to the view - makes element visible. If toTop is true then forces element to be on top of its scrollable container. |
| insert |
( element | html [,index = Integer.MAX]) returns: true | false.
element is a child DOM element (instance of this Element class) to be inserted at the index position. If index is greater than current number of children in this element then new element will be appended as a last element. Index is optional parameter, if ommited then element will be appended to collection. If element is already a child of some other parent then it will be disconnected from it automaticly. If first parameter is string (html text) then attempt will be made to insert it at given position. |
| detach |
( [update: bool] ) returns: Element
Removes this element from its parent's children collection so after call of this method this.parent become null. If update is true then calls update() for the parent element. Returns element that was just detached (this). |
| load |
( url: string [, now: bool ) returns: true/false
Loads content of the document referred by url as a content of this element. For elements having behavior:frame assigned it loads html, styles and executes scripts refered by the url or contained in the stream. For any other elements it loads only content of body portion of the document, no style loading or script execution happens in this case. |
| load |
( stream: Stream ) returns: true/false
Loads content of the document from in-memory stream as a content of this element. For elements having behavior:frame assigned it loads html, styles and executes scripts refered by the url or contained in the stream. For any other elements it loads only content of body portion of the document, no style loading or script execution happens in this case. |
| loadImage |
( url: string [, callback: function ) returns: Image | null
Loads image from the url. If callback is ommited then the engine will try to load image sycnhronously otherwise (if callback is a function) engine will issue asynchronous request and will call this function upon arrival. Signature of the callback function is function callback(image) where image is an object of class Image or null in case of error. |
| request |
( callback: function | integer, #get | #post | #json, url: string [, params: object] ) : Object | Stream | Bytes | Error
Sends synchronous and asynchronous http data GET/POST request to the server/page (url), a.k.a. JSON-RPC calls.
If parameter callback is integer than it is treated as a timeout value and the function executes synchronous request. If the callback is a function then response from the server will be delivered by calling callback function having following signature:
function dataArrivedCallback( data: any ); where data is either one of:
Example of server data response (type: text/javascript) : ({ id : 1234, message : "Hello from XYS server!" }) - in this case server returns object having two properties: id and message. Rationale behind of ({ and }) was explained here. |
| getState |
( [stateFlags:int] ) :int
Returns state of the element. stateFlags here is a set of bits - "ORed" constants STATE_***. stateFlags is provided then function returns int - flags of the element ANDed with the provided stateFlags variable. If no stateFlags is given then the function returns full set of flags element has at hte moment. |
| setState |
( stateFlags:int) :void
Function will set flags to the element update document on the screen accordingly (resolve styles and refresh). |
| clearState |
( stateFlags:int ) :void
Function will clear flags of the element and update document on the screen. |
| capture |
( onOff: true|false ) :void
element.capture(true) - sets the mouse capture to the element and element.capture(false) - removes the mouse capture from the element. |
| popup |
( el: Element, placement: int ) :void
Function will show element el as a popup window placed relatively to this element. Placement accepts following values:
( see keyboard numpad to get an idea of numbering). |
| timer |
( milliseconds: integer, callback: function )
If milliseconds is greater than zero the method will create timer for the DOM element with milliseconds delay. After milliseconds delay engine will call callback function with this variable set to the dom element. Return true from the callback() function if you need to continue timer ticks and false otherwise. Call of timer() with milliseconds = 0 parameter will stop the timer. |
| graphics |
( [ color: integer | #destroy ] ) : Graphics | null
Returns Graphics object of the element. Graphics is a bitmap that has dimensions of the element therefore, once drawn, image will stay on the screen. Each invocation of the graphics method with color value will return that bitmap with all bits initialized with the color. To get graphics with current bitmap use graphics() method without any parameters. To remove graphics from the element use el.graphics(#destroy) call. |
| sendEvent |
( eventCode:int [, reason: int [, owner: Element ]] ) : true | false
traverse (send) bubbling event to the parent/child chain of this element. Events generated by this method can be handled by onControlEvent() methods of elements in the chain.
The sendEvent does traversal so it returns true if the event was consumed - one of onControlEvent() handlers in parent/child chain returned true while handling this event. |
| postEvent |
( eventCode:int [, reason: int [, owner: Element ]] ) : undefined
The postEvent places event into the internal queue of posted events for future traversal by sendEvent. |
| post |
( callback: function [,only_if_not_there:boolean] ) : undefined
This method allows to delay execution of callback function. While calling the callback function engine will set this environment variable to the element this post call was invoked with. Optional parameter only_if_not_there if defined and is true allows to post delayed event only once. Multiple post with the same callback function will yield to a single entry in posted events queue. |
| url |
( [ relativeUrl: string ] ) : string
Method builds absolute url from the relativeUrl by using document url as a base. If there is no relativeUrl then the method just returns url of the document this DOM element belongs to. |
| sort |
( comparator: function ) : void
Sorts children of the element by using comparator function. comparator function has to have following signature:
that returns negative int value if el1 is less than el2, 0 if they are equal and positive value if el1 is greater than el2. |
| handler function name | event.type field | Comment |
| Events that are being traversed through DOM elements in Sinking/Bubbling fashion: | ||
| onMouse(event) : true|false | MOUSE_ENTER | Mouse/Pointer enters the element. |
| MOUSE_LEAVE | Mouse/Pointer leaves the element. | |
| MOUSE_MOVE | Mouse/Pointer moves over the element. | |
| MOUSE_DOWN | One of mouse buttons pressed in the element. event.mainButton and event.propButton will tell what button was pressed. | |
| MOUSE_UP | One of mouse buttons released in the element. event.mainButton and event.propButton will tell what button was pressed. To detect single MOUSE CLICK event use following condition: event.type == Event.MOUSE_UP && this.getState(Element.STATE_PRESSED) |
|
| MOUSE_DCLICK | Double mouse click in the element. | |
| MOUSE_WHEEL | Mouse wheel rotation. event.wheelDelta is a number of wheel ticks made. | |
| MOUSE_TICK | Repeatable event that is generated when one of mouse button pressed. | |
| MOUSE_IDLE | Pulsed event, is generated when mouse is not moving some short period of time. If it is not handled in the code then it is used by the engine to popup tooltip for the element. | |
| onKey(event) : true|false | KEY_DOWN | Keyboard key pressed. event.keyCode is virtual key code of the key. |
| KEY_UP | Keyboard key released. event.keyCode is virtual key code of the key. | |
| KEY_CHAR | Character key pressed. event.keyCode is a value of UNICODE codepoint. | |
| onFocus(event) : true|false | GOT_FOCUS | Focusable element got input focus. |
| LOST_FOCUS | Elements lost input focus. | |
|
onControlEvent(event)
: true|false Synthetic (logical) events |
BUTTON_CLICK | Click on button, generated by behaviors: button, checkbox, radio. |
| BUTTON_PRESS | Mouse/Key pressed in button, generated by behaviors: button, checkbox, radio. | |
| BUTTON_STATE_CHANGED | State (value) of button was changed, generated by behaviors: checkbox, radio. | |
| EDIT_VALUE_CHANGING | Value of editbox is about to be changed, generated by behaviors: edit, number, decimal, date, masked. element.value reflects old value. | |
| EDIT_VALUE_CHANGED | Value of editbox was just changed, generated by behaviors: edit, number, decimal, date, masked. element.value reflects new value. | |
| SELECT_SELECTION_CHANGED | Selection was changed in elements-selectors. generated by behaviors: select, dropdown-select, calendar. | |
| SELECT_STATE_CHANGED | State of item was changed in elements-selectors. generated by behaviors: select when some of the <options> are expanded/collapsed, event.target is the item that changed its state. behavior: calendar sends this event after calendar was switched to show another month so by handling this event you can update DOM inside the calendar. | |
| HYPERLINK_CLICK | Click on hyperlink. event.target is that hyperlink element. | |
| ACTIVATE_CHILD | Request to container to activate child. accesskey processor post this message if accesskey is defined for the element but element is passive, e.g. tab on Tabs control. See: extenders.js / type Tabs. | |
| POPUP_REQUEST | Secret stuff. | |
| POPUP_READY | ||
| POPUP_DISMISSED | ||
| MENU_ITEM_ACTIVE | Happens when menu item is highlighted. | |
| MENU_ITEM_CLICK | Click on menu item. event.target is the item event.owner is an owner of the popup menu. | |
| range 0x1000 .. 0x7FFF | Custom control events. Any code from this range can be used in element.sendEvent(code,...) calls. If behavior class is designed to behave like for example a button then you may use element.postEvent(Event.BUTTON_CLICK,...) to notify all parties about clicks. |
|
| Non-bubbling events | ||
| onScroll(event) : true|false | SCROLL_HOME |
Requests to scroll, typically are coming from <input type=vscrollbar> or <input type=hscrollbar>.
In case of SCROLL_POS use event.scrollPos field to get requested position to scroll.
|
| SCROLL_END | ||
| SCROLL_STEP_PLUS | ||
| SCROLL_STEP_MINUS | ||
| SCROLL_PAGE_PLUS | ||
| SCROLL_PAGE_MINUS | ||
| SCROLL_POS | ||
| attached() : void | Method of behavior class (type). If defined in the type definition then it will be invoked by the engine when DOM element will be subclassed by this class. Variable this inside this function is a reference to the DOM element this behavior was just attached to. Consider attached() as an equivalent of constructor function for other classes. | |
| onTimer() : true|false | Timer tick. To start timer on the element use element.timer(milliseconds) call. Return false from this method to stop the timer. | |
| onSize() : void | Size of the element was changed. To get dimensions use this.box() function. | |