DomAPI Home
DomAPI

domapi.Elm

The Elm is the heart of DomAPI. It itself is a HTMLElement with custom properties and methods tacked on. Every component in DomAPI is made up of one or more Elms. Elms can be either be created from scratch or existing HTMLElements can be converted to Elms, either by id or reference, all using domapi.Elm().

Each Elm has a property named DA_TYPE which reports what type of Elm it is. Standard ones will have a value of "ELM", while components will usually report their component name. For instance, a Button component has a DA_TYPE of "BUTTON".
DomAPI maintains an array of every Elm created which is useful for looping through all the Elms, or for looking for Elms of a certain type. This array is named domapi.bags.elms and should be considered read-only.

Check out the tutorial on the Elm Object for more detailed information on creating and using Elms.


Elm Constructor

var elm1 = domapi.Elm({
  h            : null,
  w            : null,
  x            : null,
  y            : null,
  id           : null,
  ref          : null,
  type         : "DIV",
  color        : null,
  parent       : document.body,
  bgcolor      : null,
  skipAdd      : false,
  position     : null,
  skipStyle    : false,
  skipPosition : false 
});

Constructor Details
Parameter Type Default Description
h integer null  Height in pixels.

NOTE: If both w and h are present, the Elm's overflow is set to "hidden". 
w integer null  Width in pixels.

NOTE: If both w and h are present, the Elm's overflow is set to "hidden". 
x integer null  Left position in pixels.

NOTE: If both x and y are omitted, the Elm's style.position is undefined. If either or both are present, it's absolutely positioned. 
y integer null  Top position in pixels.

NOTE: If both x and y are omitted, the Elm's style.position is undefined. If either or both are present, it's absolutely positioned. 
id String null  Instead of creating a new Elm, will use the HTMLElement identified by this id. 
ref HTMLElement null  Instead of creating a new Elm, will use this HTMLElement instead.  
type String DIV  Type of element to create the Elm as.
DIV, SPAN, IFRAME, P etc.... 
color String null  initial foreground color (doesn't really apply to Components, just Elms) 
parent HTMLElement document.body  Existing element you want this new Elm inserted into. Defaults to the document body. Must be a reference, not an id. Use document.getElementById(id) or domapi.getElm(id) to convert an id to a reference. 
bgcolor String null  initial background color (doesn't really apply to Components, just Elms) 
skipAdd boolean false  Whether or not to insert the Elm into the document immediately. If set to true, it is up to you to call the DOM method appendChild() when and where you want it inserted. 
position String null  Corresponds to the Elm's 'style.position' property. 
skipStyle boolean false  Skips the code that applies initial styling. This can improve performance if not needed. Currently this only includes setting the fore and background colors.

NOTE: If ref or id were passed in the arg param, skipStyle defaults to true instead. 
skipPosition boolean false  Skips the code that applies initial positioning. This can improve performance if not needed. Currently this includes setting style left, top, width, height, overflow and position.

NOTE: If ref or id were passed in the arg param, skipPosition defaults to true instead. 

Methods unique to domapi.Elm

Properties unique to domapi.Elm


Methods
alphaTo ( endAlpha, glideType, steps, speed, fn )

Requires core.loadUnit("color"); before can be used!

This method is automatically added to the Elm() prototype if the color unit is included on a page.
endA is the desired alpha transparency, zero being totally transparent and 100 being completely opaque.
The glideType parameter determines the type of fade to perform. Valid values are:

  • 1 = slow-to-fast
  • 2 = fast-to-slow
  • 3 = linear
Default is 3 (linear) which results in a gradual fade with no acceleration.
steps and speed affect how fast the fade occurs and fn is an optional function to execute after completion.

Example:
  domapi.loadUnit("color");
...
elm1.alphaTo(50);
Parameters:
Parameter Type Required Default Description
endAlpha integer   current alpha value    
glideType integer   1 = slow-to-fast
2 = fast-to-slow
3 = linear
 
steps integer   50    
speed integer   20    
fn Function     Function to execute upon completion. Can be used to chain together multiple animations. 
See also:  getAlpha
  setAlpha
back to top
bringToFront ()

Brings the element to the top of the z-index stack for it's parent container.

Example:
  elm1.bringToFront();
See also:  sendToBack
back to top
buttonDown ( borderWidth )

Sets the element's border-style to inset.

Example:
  elm1.buttonDown(5);
Parameters:
Parameter Type Required Default Description
borderWidth integer   core.theme.border.width    
See also:  buttonUp
back to top
buttonUp ( borderWidth )

Sets the element's border-style to outset.

Example:
  elm1.buttonUp();
Parameters:
Parameter Type Required Default Description
borderWidth integer   core.theme.border.width    
See also:  buttonDown
back to top
clipBy ( top, right, bottom, left )

Requires core.loadUnit("animate"); before can be used!

Similar to clipTo() but coordinates are relative to current location.

Parameters:
Parameter Type Required Default Description
top integer     
right integer     
bottom integer     
left integer     
See also:  getClip
  clipTo
  setClip
  setClipBy
back to top
clipTo ( top, right, bottom, left, growType, steps, speed, fn )

Requires core.loadUnit("animate"); before can be used!

This method clips an element to a given rectangle in timed increments.

Parameters:
Parameter Type Required Default Description
top integer     
right integer     
bottom integer     
left integer     
growType integer   1 = slow-to-fast
2 = fast-to-slow
3 = linear 
steps integer   50  size of each successive clip 
speed integer   20  the number of milliseconds between clips 
fn Function     Function to execute upon completion. Can be used to chain animations together. 
See also:  getClip
  clipBy
  setClip
  setClipBy
back to top
fadeToColor ( kind, targetColor, inc, speed, fn )

Requires core.loadUnit("color"); before can be used!

Given a target color, this routine will gradually blend the element's color to match it. Can optionally evalute a passed function upon completion.

See source and examples for more details.

Example:
  div1.fadeToColor("bg","#000000",10,10); // fade to black
div1.fadeToColor("bg","#000000",10,10,"alert('done.')"); // fade to black and tell me when it's done
Parameters:
Parameter Type Required Default Description
kind String   bg  Specify either "bg" for background color, or "fg" for foreground. Default is "bg". 
targetColor String   #000000  The target color to fade to 
inc integer   10  Number of increments between color jumps. 
speed integer   10  Time in ms between jumps. 
fn Function     Optional function to execute upon completion. 
See also:  setBgColor
  setColor
back to top
getAlpha () type : integer

Returns the elements current alpha transparency as a number between 0 and 100. Zero being totally clear and 100 completely opaque.

See also:  getBgColor
back to top
getB () type : variant

Returns a four element array containing the width of each border in pixels, starting with the top and moving clock-wise.
See domapi.boxValuesOut() for info.

Example:
  var b=this.getB();
alert("Bottom border is "+b[2]);
back to top
getBgColor () type : String

Returns the element's background color. If color_c.js was included on the page, this function will attempt to resolve color constants such as "red" into their hex equivilant.

See also:  getAlpha
  getColor
back to top
getClip () type : String

Returns a four element array containing the amount of padding in pixels, starting with the top and moving clock-wise.
See domapi.boxValuesOut() for info.

back to top
getColor () type : String

Returns the element's foreground (text) color. If color_c.js was included on the page, this function will attempt to resolve color constants such as "red" into their hex equivilant.

See also:  getBgColor
back to top
getH () type : integer

Height of element in pixels.

See also:  getW
back to top
getM () type : variant

Returns a four element array containing the width of each margin in pixels, starting with the top and moving clock-wise.
See domapi.boxValuesOut() for info.

See also:  getP
back to top
getOverflow () type : String

Returns a string representing the element's current overflow state. Valid entries are:

visibleDefault. Content is not clipped and scroll bars are not added.
scrollContent is clipped and scroll bars are added, even if the content does not exceed the dimensions of the object.
hiddenContent that exceeds the dimensions of the object is not shown.
autoContent is clipped and scrolling is added only when necessary.

See also:  setOverflow
back to top
getP () type : variant

Returns a four element array containing the width of each padding in pixels, starting with the top and moving clock-wise.
See domapi.boxValuesOut() for info.

See also:  getM
back to top
getW () type : integer

Width of element in pixels.

See also:  getH
back to top
getX () type : integer

Returns number of pixels from left side of parent container or browser window.

See also:  getY
back to top
getY () type : integer

Number of pixels from top of parent container or browser window.

See also:  getX
back to top
getZ () type : integer

The elements z-index. Elements with higher values appear on "top" of lower values.

back to top
glideBy ( X, Y, glideType, steps, speed, fn, x1, y1, x2, y2, x3, y3 )

Requires core.loadUnit("animate"); before can be used!

Same as glideTo() but coordinates are relative to current location.

Parameters:
Parameter Type Required Default Description
X integer   current location  Final location 
Y integer   current location  Final location 
glideType integer   Type of glide to perform.
1 = slow-to-fast
2 = fast-to-slow
3 = linear
4 = curve (beizer) 
steps integer   50  Number of increments to make. 
speed integer   20  Time in ms to wait between succesive steps. 
fn Function     Optional function to perform upon completion. 
x1 integer     First point for beizer curve 
y1 integer     First point for beizer curve 
x2 integer     Second point for beizer curve 
y2 integer     Second point for beizer curve 
x3 integer     Third point for beizer curve 
y3 integer     Third point for beizer curve 
See also:  glideTo
back to top
glideTo ( X, Y, glideType, steps, speed, fn, x1, y1, x2, y2, x3, y3 )

Requires core.loadUnit("animate"); before can be used!

This method moves an element to a given location in timed increments.

Parameters:
Parameter Type Required Default Description
X integer   current location  Final location 
Y integer   current location  Final location 
glideType integer   Type of glide to perform.
1 = slow-to-fast
2 = fast-to-slow
3 = linear
4 = curve (beizer) 
steps integer   50  Number of increments to make. 
speed integer   20  Time in ms to wait between succesive steps. 
fn Function     Optional function to perform upon completion. 
x1 integer     First point for beizer curve 
y1 integer     First point for beizer curve 
x2 integer     Second point for beizer curve 
y2 integer     Second point for beizer curve 
x3 integer     Third point for beizer curve 
y3 integer     Third point for beizer curve 
See also:  glideBy
back to top
hide ()

Hides the element. (style.visibility = "hidden")

See also:  visible
  show
back to top
moveBy ( x, y )

Moves the element a relative amount in pixels.

Parameters:
Parameter Type Required Default Description
x integer Y     
y integer Y     
See also:  glideBy
  glideTo
  moveTo
  moveToElm
  setX
  setY
back to top
moveTo ( x, y )

Moves the element to the specified screen location in pixels.

Parameters:
Parameter Type Required Default Description
x integer Y     
y integer Y     
See also:  glideBy
  glideTo
  moveBy
  moveToElm
  setX
  setY
back to top
moveToElm ( elm )

Moves the element to the same location of another.

Example:
  elm1.moveToElm(elm2);
Parameters:
Parameter Type Required Default Description
elm HTMLElement Y   Target MUST also be an Elm 
back to top
pathSlide ( xValues, yValues, startIndex, steps, speed )

Requires core.loadUnit("animate"); before can be used!

This method performs a series of linear slides.
Pixel locations are specified using the two array parameters - one for X and one for Y.

See the animate unit for more information.

Parameters:
Parameter Type Required Default Description
xValues Array Y   Array of horizontal positions. 
yValues Array Y   Array of vertical positions. 
startIndex integer   By default the path will start from the first pixel location in the array. You can provide a different starting index using this parameter. 
steps integer   number of steps to make during move 
speed integer   20  time in ms to wait between moves 
back to top
remove ()

Removes the elm from the page. Also deletes all references to it.
Basically, frees the Elm completely.

back to top
resizeOff ( group )

Requires core.loadUnit("resize"); before can be used!

turns off resize for an elm

Parameters:
Parameter Type Required Default Description
group Array     If you are using the groups extension, you can turn resize off for an entire group instead of just one Elm.
Optional. 
See also:  resizeOn
back to top
resizeOn ( group )

Requires core.loadUnit("resize"); before can be used!

turns on resize for an elm

Parameters:
Parameter Type Required Default Description
group Array     If you are using the groups extension, you can turn resize on for an entire group instead of just one Elm.
Optional. 
See also:  resizeOff
back to top
sendToBack ()

Sends the element to the bottom of the z-index stack for it's parent container.

See also:  bringToFront
back to top
setAlpha ( value )

Sets the elements current alpha transparency as a number between 0 and 100. Zero being totally clear and 100 completely opaque.

Parameters:
Parameter Type Required Default Description
value integer Y   0 - 100 
See also:  alphaTo
  fadeToColor
  setBgColor
back to top
setB ( value )

Sets the element's border in pixels.
The parameter can either be a single integer or an array of up to 4 integers.

See domapi.boxValuesIn() for more information on the input value.

Parameters:
Parameter Type Required Default Description
value integer Y   Single integer or 1 to 4 position array of integers. See domapi.boxValuesIn() for more info. 
back to top
setBgColor ( color )

Sets the background color of the element.

Example:
  elm1.setBgColor("black"  );
// or
elm1.setColor(  "#000000");
Parameters:
Parameter Type Required Default Description
color String Y     
See also:  fadeToColor
  setAlpha
  setColor
back to top
setClip ( top, right, bottom, left )

Sets the clip portion of the element as defined in CSS1.

The first parameter can optionally be an array of 1 to 4 integers. See domapi.boxValuesIn() for more info.

Parameters:
Parameter Type Required Default Description
top integer Y     
right integer       
bottom integer       
left integer       
See also:  setClipBy
back to top
setClipBy ( top, right, bottom, left )

Similar to setClip, but works relative with current clip values.

Parameters:
Parameter Type Required Default Description
top integer Y     
right integer       
bottom integer       
left integer       
See also:  setClip
back to top
setColor ( color )

Sets the foreground color of the element.

Example:
  elm1.setBgColor("black"  );
// or
elm1.setColor(  "#000000");
Parameters:
Parameter Type Required Default Description
color String Y     
See also:  fadeToColor
  setBgColor
back to top
setH ( value )

Sets the height of the element in pixels.

Parameters:
Parameter Type Required Default Description
value integer Y   Must be >= 0 
See also:  setSize
  setSizeBy
  setW
back to top
setM ( value )

Sets the element's margin in pixels.
The parameter can either be a single integer or an array of up to 4 integers.

See domapi.boxValuesIn() for more information.

Parameters:
Parameter Type Required Default Description
value Array Y   Array of 1 to 4 integers. See domapi.boxValuesIn() for info. 
See also:  setP
back to top
setOverflow ( value )

Sets the element's current overflow state. Valid entries are:

visibleContent is not clipped and scroll bars are not added.
scrollContent is clipped and scroll bars are added, even if the content does not exceed the dimensions of the object.
hiddenContent that exceeds the dimensions of the object is not shown.
autoContent is clipped and scrolling is added only when necessary.

Parameters:
Parameter Type Required Default Description
value String Y     
back to top
setP ( value )

Sets the element's padding in pixels.
The parameter can either be a single integer or an array of up to 4 integers.

See domapi.boxValuesIn() for more information.

Parameters:
Parameter Type Required Default Description
value Array Y   1 to 4 position array. See domapi.boxValuesIn() for info. 
See also:  setM
back to top
setSize ( width, height )

Sets the width and height in one call.

Parameters:
Parameter Type Required Default Description
width integer Y     
height integer Y     
See also:  sizeBy
  sizeTo
  setH
  setSizeBy
  setW
back to top
setSizeBy ( width, height )

Changes the width and height by a relative amount.

Parameters:
Parameter Type Required Default Description
width integer Y     
height integer Y     
See also:  sizeBy
  sizeTo
  setH
  setSize
  setW
back to top
setText ( text )

Sets the innerHTML for the element. Accepts any valid HTML.

Parameters:
Parameter Type Required Default Description
text String Y     
back to top
setW ( value )

Sets the width of the element in pixels.

Parameters:
Parameter Type Required Default Description
value integer Y   Must be >= 0 
See also:  sizeBy
  sizeTo
  setH
  setSize
  setSizeBy
back to top
setX ( value )

Moves the element to x pixels from the left side of the browser window.

Parameters:
Parameter Type Required Default Description
value integer Y     
See also:  glideBy
  glideTo
  moveBy
  moveTo
  moveToElm
  setY
back to top
setY ( value )

Moves the element to y pixels from the top of the browser window.

Parameters:
Parameter Type Required Default Description
value integer Y     
See also:  glideBy
  glideTo
  moveBy
  moveTo
  moveToElm
  setX
back to top
setZ ( value )

Sets the element's z-index.

Parameters:
Parameter Type Required Default Description
value integer     
back to top
show ()

Unhides the element. (sets style.visibility = "visible")

See also:  visible
  hide
back to top
sizeBy ( width, height, growType, steps, speed, fn )

Requires core.loadUnit("animate"); before can be used!

Same as Elm.sizeTo() but sizes are relative to current size.

Parameters:
Parameter Type Required Default Description
width integer Y   delta 
height integer Y   delta 
growType integer   1 = slow-to-fast
2 = fast-to-slow
3 = linear
 
steps integer   50  number of steps to make during sizing 
speed integer   20  time in ms to wait between steps 
fn Function     Optional function to call upon completion 
See also:  sizeTo
  setH
  setSize
  setSizeBy
  setW
back to top
sizeTo ( width, height, growType, steps, speed, fn )

Requires core.loadUnit("animate"); before can be used!

This method sizes an element to a given shape in timed increments.

Parameters:
Parameter Type Required Default Description
width integer   current width  final width 
height integer   current height  final height 
growType integer   1 = slow-to-fast
2 = fast-to-slow
3 = linear
 
steps integer   50  number of steps to make during sizing 
speed integer   20  time in ms to wait between steps 
fn Function     Optional function to call upon completion 
See also:  sizeBy
  setH
  setSize
  setSizeBy
  setW
back to top
visible () type : boolean default value : true

Returns whether or not the item is visible or hidden. (style.visibility == "visible")

See also:  hide
  show
back to top
Properties
DA_TYPE type : String

Element type.
Standard ones will have a value of "ELM", while components will usually report their component name. For instance, a Button component has a DA_TYPE of "BUTTON". For components, the element will usually have a matching CSS classname, prepended with "DA_". For example, the classname of a button will contain DA_BUTTON.

Example:
  alert(elm1.DA_TYPE);
back to top
DHTML by www.domapi.com