vegui. std.js

Summary
holds pointers to all VegUIElement Constructor functions by their type
vegUI element type for VegUINode
vegUI element type for VegUIManager
Mouse and keyboard eventtypes that help you identify what event you’re dealing with
Url needed for xmlhttprequest to work, can leave blank if working on a local server
Bitmask flags that can be set on the flags property of each VegUIElement individually
Resizes body to manager canvas size, this is to fix text selection and onmouseout in internet explorer
Maximum element index possible, 90000 by default, increase if you need to spawn more than 90000 elements at the same time
Current vegUI version
holds browser name in its name property
Makes a vegUI module accessable by the manager.
Internet explorer 6 leaks memory in closures, in order to fix that iesucks is called when the page is unloaded if the browser is ie6
Creates a new instance of a javascript object
Attempt to append the properties of trgObj to srcObj
clones an array
checks if Node is the child of Parent somewhere up the parent chain
get mouse pointer location, sets mouseX and mouseY
Wrapper for document.createElement with the option to append the created node to another html node right away
Wrapper for document.createElement to create an image node with the option to define proportions and image source right away
Wrapper for document.createTextNode
generate a random number
Handles a certain keyboard or mouse event type that gets triggered by the VegUIElement the VegUIMouseState belongs to
(VegUIElement) VegUI element that owns this mouse state
(int) holds the type of mouse or keyboard event this state handles
(Array) properties that will be copied over to the element that owns this mouse state if the event that is handled by this mouse state is triggered
The most basic VegUI Element.
These properties are only set after certain mouse or keyboard events have been handled by this element
Template properties are properties that will get turned into real properties when the node is built.
Creates a VegUI element as a child of this element.
Adds an existing VegUI Element to this element as a child
Wrapper function to add a new vegui element to this element as a child with the ability to set the most common template properties
(Re)Aligns all child elements of this element to their margins
Attaches another VegUI element to this node.
build a HTML node from the template properties of this element.
This function triggers the ondock event on this element and all its child elements recursivly
See if this element or any of its child elements has focus.
Removes all child HTML nodes from the HTML node that is controlled by this element
Clones a vegUI event
Clones the children and properties of a template element to this element
clone multiple children that are of the same type from the same template
Takes control over an existing HTML node
Detaches an attached element that was attached to this element via attach_node.
Toggles the VUI_DISABLED flag on this element
Appends the HTML node controlled by this element to another HTMLnode
Adds a function to be executed to a vegui element event
Fires a vegUI event
Add function to event listener of the node controlled by this element
Find the first common vegui Parent that this element and Obj share
private function
toggles this element to be invisible or visible
Checks if the HTML node controlled by this element is hidden or visible
Check if a vegui element is the parent element of this element somewhere down the parent chain
Removes the HTMLnode controlled by this element and/or destroys the element it self.
Takes focus away from this element, the first parent that can have focus set on it will gain passive focus.
moves the HTML node controlled by this element to new coordinates
called when the element is moved via the set_x, set_y or move methods
called when the element is resized via the set_width, set_height or resize methods
triggered by dock method
varies from element to element
triggered by kill method
triggered when element gains focus
triggered when element loses focus
triggered after element was built
triggered by hide method
Checks if this element overlaps with another element.
resizes the HTML node controlled by this element
Gives focus to the element.
sets the height of the HTML node controlled by this element
Template Function
Template Function
sets the CSS position of the HTML node controlled by this element
Set the CSS transparency of the HTML node that is controlled by this element.
sets the width of the HTML node controlled by this element
repositions the HTML node controlled by this element on the x axis
repositions the HTML node controlled by this element on the y axis
Sticks the element to another element at a certain offset
private function
Removes the HTML node controlled by this element from its current parentNode.
Spawns and keeps track of all vegUI elements
extends vegUINode
Constructor
Attempts the prevention of the default browser action for a certain keyboard key code
builds a VegUIElement.
builds multiple vegUI elements, if the last argument submitted to the function is a HTML node then the element’s will be built as children of that node
builds the manager
clone multiple elements of the same template
evals some javascript code
Wrapper functions to create a new vegui element and clone it
private function
Creates a new VegUIElement
Includes javascript code from a file and executes is
initializes common VegUIBridge object that can be accessed by all spawned VegUIElements by accessing it over their Manager property
initializes common VegUIFXManager object that can be accessed by all spawned VegUIElements by accessing it over their Manager attribute
Check if a keycode has been blocked with <block_key>
Template function
Removes a keycode block set by <block_key> method
Bounding box for elements, limits where an element can be moved to.
Constructor
checks if the element is within the boundin box’s border, if not the element will be moved to be within the bounding box’s border
sets the bounding box up
Validates the position of the element that the bounding box belongs to
Allows to have a function with dynamic content
Constructor
Adds a function to the stack
Executes all the functions in the stack
Free a unique function id effectivly removing the function linked to it from the stack

Constants

VEGUIOBJ

holds pointers to all VegUIElement Constructor functions by their type

VUI_NODE

vegUI element type for VegUINode

VUI_MANAGER

vegUI element type for VegUIManager

Mouse and keyboard event types

Mouse and keyboard eventtypes that help you identify what event you’re dealing with

VUI_MOUSE_DOWNmouse button clicked on the vegUI element
VUI_MOUSE_UPmouse button released on the vegUI element
VUI_MOUSE_OVERmouse button entered the vegUI element
VUI_MOUSE_OUTmouse button leaves the vegUI element
VUI_MOUSE_MOVEmouse moved within the borders of vegUI element
VUI_MOUSE_WHEELmouse wheel used
VUI_KEY_DOWNkeyboard key pressed
VUI_KEY_UPkeyboard key released
VUI_FORM_BLURonblur event in form elements
VUI_FORM_FOCUSonfocus event in form elements
VUI_MOUSE_DBL_LICKdbclick event

VUI_URL

Url needed for xmlhttprequest to work, can leave blank if working on a local server

Generic directions

VUI_UPup
VUI_DOWNdown
VUI_LEFTleft
VUI_RIGHTright
VUI_BACKback
VUI_FRONTfront

Flags, Common

Bitmask flags that can be set on the flags property of each VegUIElement individually

VUI_HMOUSE_UPenable event handling for VUI_MOUSE_UP
VUI_HMOUSE_DOWNenable event handling for VUI_MOUSE_DOWN
VUI_HMOUSE_OVERenable event handling for VUI_MOUSE_OVER
VUI_HMOUSE_OUTenable event handling for VUI_MOUSE_OUT
VUI_HMOUSE_MOVEenable event handling for VUI_MOUSE_MOVE
VUI_HMOUSE_WHEELenable event handling for VUI_MOUSE_WHEEL
VUI_HMOUSE_DBL_CLICKenable envent handling for VUI_MOUSE_DBL_CLICK
VUI_HKEY_DOWNenable event handling for VUI_KEY_DOWN
VUI_HKEY_UPenable event handling for VUI_KE_UP
VUI_TEMPLATEflag VegUIElement as template prohibting it from being built
VUI_DISABLEDflag VegUIElement as being disabled, prohibiting any event handling

ADJUST_BODY_SIZE

Resizes body to manager canvas size, this is to fix text selection and onmouseout in internet explorer

ELEMENT_MAX_INDEX

Maximum element index possible, 90000 by default, increase if you need to spawn more than 90000 elements at the same time

Focus types

VUI_FOCUS_PASSIVEpassive focus
VUI_FOCUS_ACTIVEactive focus

VUI_VERSION

Current vegUI version

Mouse coordinates

mouseXabsolute x coordinate of the mouse pointer
mouseYabsolute y coordinate of the mouse pointer

VUI_BROWSER_INFO

holds browser name in its name property

Functions

vui_module_add

function vui_module_add(type,
module,
filename)

Makes a vegUI module accessable by the manager.  When developing addons for vegUI make sure you initialize your module using this function instead of adding it’s type directly to the VEGUIOBJ array.

If there are colliding types an error message will be displayed and the script is halted

Added in

2.0.6

Parameters

int typeunique type id of the module
func moduleconstructor function of the module
string filenamefilename that the function was called in

Returns

booltrue on success
boolfalse on error

Example

vui_module_add(VUI_NODE, VegUINode, 'vegui.std.js');

iesucks

var browser_str = navigator.userAgent.toLowerCase(); function iesucks(Node)

Internet explorer 6 leaks memory in closures, in order to fix that iesucks is called when the page is unloaded if the browser is ie6

Parameters

NodeHTML Node that needs to have events reset recursivly

Clone

function Clone(Obj)

Creates a new instance of a javascript object

Parameters

Object Objobject to be cloned

Example

In this example newObj will be an exact clone of Obj

var newObj = new Clone(Obj);

merge

function merge(srcObj,
trgObj)

Attempt to append the properties of trgObj to srcObj

Parameters

Object trgObjJavascript Object
Object srcObjJavascript Object

Example

Any non-existing properties of Obj2 will be copied to Obj1, existing properties will be overwritten

merge(Obj1, Obj2);

cloneArray

function cloneArray(Arr)

clones an array

Parameters

Array ArrArray to be cloned

Returns

ArrayNew instance of Arr

Example

newArr will be an exact copy of oldArr

var newArrr = cloneArray(oldArr);

has_parent

function has_parent(Node,
Parent)

checks if Node is the child of Parent somewhere up the parent chain

Parameters

HTMLNode NodeHTML Node
HTMLNode ParentHTML Node

Returns

booltrue if Parent is the parent node of Node directly or indirectly
boolfalse if Parent is not the parent node of Node directly or indirectly

Example

var node1 = document.createElement('div');
var node2 = document.createElement('div');
var node3 = document.createElement('div');
node1.appendChild(node2);
node2.appendChild(node3);

// as node1 is the parent node of node 2, this will return true
return has_parent(node2, node1);

// returns true as well, since node1 is the parent of node2 which
// is the parent of node3
return has_parent(node3, node1);

get_mouse

function get_mouse(e)

get mouse pointer location, sets mouseX and mouseY

Parameters

Event ejavascript event

Example

node.onmousemove = function(e) {
get_mouse((e ? e : event));
alert(mouseX+','+mouseY);
}

htmlnode

function htmlnode(nodeName,
parentNode)

Wrapper for document.createElement with the option to append the created node to another html node right away

Paramters

string nodeNamehtml name of the node (ie.  ‘div’)
<HTMLNode parentNode>created html node will be appended to this node

Returns

HTMLNodeCreated node

imgnode

function imgnode(src,
w,
h,
parentNode)

Wrapper for document.createElement to create an image node with the option to define proportions and image source right away

Parameters

string srcpath of the image
int wwidth of the image (pixels)
int hheight of the image (pixels)
<HTMLNode parentNode>created image node will be appened to this node

Returns

HTMLNodeCreated node

txtnode

function txtnode(txt)

Wrapper for document.createTextNode

Parameters

string txttext string to be created

Returns

DOMNodeCreated text node

vui_rand

function vui_rand(min,
max)

generate a random number

Parameters

int minminimum number
int maxmaximum number

Returns

intthe generated number (int)

Example

// n may be any number between 1 and 30
var n = vui_rand(1,30);

VegUIMouseState

Handles a certain keyboard or mouse event type that gets triggered by the VegUIElement the VegUIMouseState belongs to

Summary
(VegUIElement) VegUI element that owns this mouse state
(int) holds the type of mouse or keyboard event this state handles
(Array) properties that will be copied over to the element that owns this mouse state if the event that is handled by this mouse state is triggered

Functions

VegUIMouseState

function VegUIMouseState(eventType,
Parent)

Parameters

int eventTypeevent type to handle, Mouse and keyboard event types
VegUIElement ParentVegUIElement this object belongs to

Properties

Parent

(VegUIElement) VegUI element that owns this mouse state

type

(int) holds the type of mouse or keyboard event this state handles

Scripts

Properties

(Array) properties that will be copied over to the element that owns this mouse state if the event that is handled by this mouse state is triggered

VegUINode

The most basic VegUI Element.  The VegUINode is the base element for every other vegUI element.

Summary
These properties are only set after certain mouse or keyboard events have been handled by this element
Template properties are properties that will get turned into real properties when the node is built.
Creates a VegUI element as a child of this element.
Adds an existing VegUI Element to this element as a child
Wrapper function to add a new vegui element to this element as a child with the ability to set the most common template properties
(Re)Aligns all child elements of this element to their margins
Attaches another VegUI element to this node.
build a HTML node from the template properties of this element.
This function triggers the ondock event on this element and all its child elements recursivly
See if this element or any of its child elements has focus.
Removes all child HTML nodes from the HTML node that is controlled by this element
Clones a vegUI event
Clones the children and properties of a template element to this element
clone multiple children that are of the same type from the same template
Takes control over an existing HTML node
Detaches an attached element that was attached to this element via attach_node.
Toggles the VUI_DISABLED flag on this element
Appends the HTML node controlled by this element to another HTMLnode
Adds a function to be executed to a vegui element event
Fires a vegUI event
Add function to event listener of the node controlled by this element
Find the first common vegui Parent that this element and Obj share
private function
toggles this element to be invisible or visible
Checks if the HTML node controlled by this element is hidden or visible
Check if a vegui element is the parent element of this element somewhere down the parent chain
Removes the HTMLnode controlled by this element and/or destroys the element it self.
Takes focus away from this element, the first parent that can have focus set on it will gain passive focus.
moves the HTML node controlled by this element to new coordinates
called when the element is moved via the set_x, set_y or move methods
called when the element is resized via the set_width, set_height or resize methods
triggered by dock method
varies from element to element
triggered by kill method
triggered when element gains focus
triggered when element loses focus
triggered after element was built
triggered by hide method
Checks if this element overlaps with another element.
resizes the HTML node controlled by this element
Gives focus to the element.
sets the height of the HTML node controlled by this element
Template Function
Template Function
sets the CSS position of the HTML node controlled by this element
Set the CSS transparency of the HTML node that is controlled by this element.
sets the width of the HTML node controlled by this element
repositions the HTML node controlled by this element on the x axis
repositions the HTML node controlled by this element on the y axis
Sticks the element to another element at a certain offset
private function
Removes the HTML node controlled by this element from its current parentNode.

Properties

Object Properties

refNamestring, name of the object
ParentVegUIElement, Parent element of this element
ManagerVegUIElement, Manager element that spawned this element
typeint, element type VUI_NODE
CAlias for Childs
ChildsObject, Holds all child elements of this type by their element index
TAlias for Template
TemplateObject, Holds template properties
BaseHTMLNode, Holds the HTML node that is controlled by the element
CssDOMNode, Holds the style property of the HTML node that is controlled by this element
hasFocusint, Holds the focus type of the node
flagsint, Bitmask
BBoxVegUIBBox, Holds the Bounding Box object of this element
transparencyint, Holds the transparency value of this element (0-100)
StatesArray, Holds mouse/keyboard event states, one state for each event type
nodeIdstring, Holds the id of the HTML node that is controlled
noAutoShowbool, prevents the element from being flagged visible recursivly
childNamestring, child name of the node
lockFocusbool, if true focus can never be taken away from this node
Attachedobject, object holding vegui elements that were attached to this element via attach_node

Event Specific Object Properties

These properties are only set after certain mouse or keyboard events have been handled by this element

mEventEvent, Holds the javascript event object for the last mouse or key event handled by this node
deltaint, Mousewheel delta, is set whenever the mousewheel event is handled by this element
aKeyint, character code of the last key down or key up event handled by this element
aKeyCharchar, character of the last key down or key up event handled by this element
toEHTMLNode, relatedTarget / toElement from the last mouse event handled by this element
keyShiftbool, if true then shift key was held down when the last keyboard event was handled by this element
keyAltbool, if true then the alt key was held down when the last keyboard event was handled by this element
keyCtrlbool, if true then the ctrl key was held down when the last keyboard event was handled by this element

Template Properties

Template properties are properties that will get turned into real properties when the node is built.  They are stored in the Template property of the element

T.nodeTypestring, node type of the htmli node to be built (ie ‘div’)
T.xint, node position on the x axis (pixels)
T.yint, node position on the y axis (pixels)
T.wint, node width (pixels)
T.hint, node height (pixels)
T.rmargint, right margin
T.bmargint, bottom margin
T.rmarg_nrint, right margin, no resize
T.bmarg_nrint, bottom margin, no resize
T.miconstring, mouse cursor to use when the mouse enters the element (CSS cursor attribute)
T.blockIETransparencybool, if true any transparency effects will be ignored if the browser is internet explorer
T.img_srcstring, will set the HTML node’s src attribute
T.CssObject, any properties in T.Css will be copied to the HTML node’s style property
T.innerHtmlstring, The HTML Node’s innerHTML attribute will be set to this, if set
T.typestring, The HTML Node’s type attribute will be set to this if set
T.classNamestring, The HTML node will be using this CSS class if set

Functions

VegUINode

function VegUINode(refName,
Parent,
Manager)

Parameters

string refNamename of the object
VegUIElement ParentParent element of this element
VegUIElement ManagerManager element that spawned this element

abs_middle

this.abs_middle = function(stopAt)

Parameters

<HTMLNode stopAt>if submitted, the absolute position will be returned relative to the submitted node

Returns

Arrayarray holding x and y coordinates of the abolute middle of the HTML node controlled by this element

See also

abs_x, abs_y, x, y

abs_x

this.abs_x = function(stopAt)

Parameters

<HTMLNode stopAt>if submitted, the absolute position will be returned relative to the submitted node

Returns

intthe absolute position of the HTML node controlled by this element on the x axis
nullif no HTML node is controlled by this element

See also

abs_y, abs_middle, x, y

abs_y

this.abs_y = function(stopAt)
<HTMLNode stopAt>if submitted, the absolute position will be returned relative to the submitted node

Returns

intthe absolute position of the HTML node controlled by this element on the y axis
nullif no HTML node is controlled by this element

See also

abs_x, abs_middle, x, y

add_child

this.add_child = function(name,
type,
nodeName,
pos)

Creates a VegUI element as a child of this element.  Childs can be accessed over the Child or C property of this element by their unique child name

Parameters

string nameunique child name
int type<VegUI element types>
<string nodeName>if set the childs T.nodeType property will be set to this
<string pos>if set the childs T.pos property will be set to this (Css position value, ie ‘absolute’)

Returns

VegUIElementthe created element

See also

add_skin, add_child_o

Example

var c = myNode.add_child('mychild', VUI_NODE, 'div', 'absolute');

add_child_o

this.add_child_o = function(name,
Obj)

Adds an existing VegUI Element to this element as a child

Parameters

string nameunique child name
VegUIElement Objelement to add as a child

See also

add_child, add_skin

Example

var node1 = Manager.get_new(VUI_NODE);
var node2 = Manager.get_new(VUI_NODE);
node2.add_child_o(node1);

add_skin

this.add_skin = function(n,
w,
h,
x,
y,
c,
rm,
bm,
rm_nr,
bm_nr,
nN,
i)

Wrapper function to add a new vegui element to this element as a child with the ability to set the most common template properties

Parameters

string nnode name (ie ‘div’)
int wwidth (pixels)
int hheight (pixels)
int xposition on x axis (pixels)
int yposition on y axis (pixels)
string classNamesets the T.className property (css class to use)
int rmright margin (pixels)
int bmbottom margin (pixels)
int rm_nrright margin no resize (pixels)
int bm_nrbottom margin no resize (pixels)
string nNnode name ie ‘div’
string iimage source (file path)

Returns

VegUIElementthe created element

See also

add_child, add_child_o

align_childs

this.align_childs = function(Child)

(Re)Aligns all child elements of this element to their margins

Parameters

VegUIElement <Child>if submitted only this child will be realigned

See also

set_marg

attach_node

this.attach = this.attach_node = function(Element,
offsetX,
offsetY,
direction,
z)

Attaches another VegUI element to this node.  When an element is attached it will stick to this node and move with it whenever it is moved

Alias

<attach>

Parameters

VegUIElement Elementthe element you want to attach to this node
int offsetXx offset
int offsetYy offset
<int direction>can be set to VUI_BACK or VUI_FRONT and will overwrite the z-index value of the attached element
<int z>z offset (default = 1)

See also

detach_node

Example

// yourNode will be attached to myNode at a 5 pixel offset in each
// direction. Submitting the direction as VUI_BACK causes
// yourNode to stay under myNode on the z-level

myNode.attach(yourNode, 5, 5, VUI_BACK, 2);

build_node

this.build = this.build_node = function(toNode,
takeNode)

build a HTML node from the template properties of this element.  Once the node is built it will be controlled by this element

Alias

build()

Parameters

HTMLNode toNodeif submitted the created HTMLnode will be appended as a child to this node
<HTMLNode takeNode>instead of creating a new HTMLnode an existing one will be taken over

Returns

int1 on success
nullon failure

call_ondock

this.call_ondock = function()

This function triggers the ondock event on this element and all its child elements recursivly

check_focus

this.check_focus = function(focusType)

See if this element or any of its child elements has focus.

Parameters

<int focusType>if submitted the function checks if the element has focus of the submitted type

Returns

intfocus type if element has focus
int0 if no focus is found

See also

set_focus_node, lose_focus_node

clear

this.clear = function(replacement)

Removes all child HTML nodes from the HTML node that is controlled by this element

Parameters

<HTMLNode replacement>Optional node to be added to the HTML node controlled by this element after clearing.

See also

kill

Example

// all child elements will be removed from myNode
myNode.clear();

// all child elements will be removed from myNode
// and a new div node will be appended
myNode.clear(htmlnode('div'));

clone_event

this.clone_event = function(Template)

Clones a vegUI event

Paramters

var eventcan hold a VegUIDynFunc object or a generic function

Returns

var eventcloned event

clone_node

this.clone = this.clone_node = function(Template)

Clones the children and properties of a template element to this element

Template elements are vegUI elements that have not been built.

Alias

clone()

Parameters

VegUIElement TemplateTemplate element to clone from

Returns

VegUIElementthis

Example

// yourNode will take over the template settings from myNode.
// This will only work as long as myNode is still in template
// mode and has not been built yet

yourNode.clone(myNode);

clone_children

this.clone_children = function(type,
T,
rec)

clone multiple children that are of the same type from the same template

Parameters

int typevegui type of the children (eg <VUI_NODE))
vegUIElement Ttemplate to clone from
<bool rec>if true children will be cloned recursively, else only direct children of this element will be cloned (default: false)

control

this.control = function(Node)

Takes control over an existing HTML node

Parameters

HTMLNode NodeHTML node to take control over

Returns

VegUIElementitself

Example

// myNode will take control over an existing html element

myNode.control(document.getElementById('some_element'));
myNode.move(50,50);

detach_node

this.detach_node = this.detach = function(Element)

Detaches an attached element that was attached to this element via attach_node.

Alias

detach()

Parameters

VegUIElement Elementelement you want to detach

See also

attach_node

Example

myNode.attach(yourNode);
myNode.detach(yourNode);

disable_node

this.disable = this.disable_node = function(b)

Toggles the VUI_DISABLED flag on this element

Alias

disable()

Parameters

bool bif true flag is toggled on, if false flag is toggled off

dock

this.dock = function(toNode,
insertBefore)

Appends the HTML node controlled by this element to another HTMLnode

Parameters

HTMLNode toNodethe HTMLNode that shall serve as a parent

See also

undock

Example

myNode.dock(document.body);

event_add

this.event_add = function(eventName,
func,
funcId)

Adds a function to be executed to a vegui element event

Parameters

string eventNamename of the target event
function funcfunction to be executed on the event
<var funcId>optional unique id of the function

See also

event_execute

Example

myNode.event_add('onresize', function() { alert('test'); });

event_execute

this.event_execute = function(eventName,
args)

Fires a vegUI event

Parameters

string eventNamename of the event
<array args>arguments

See also

event_execute

event_listener_set

this.event_listener_set = function(eventName,
func,
n)

Add function to event listener of the node controlled by this element

Parameters

string eventNamename of the event (ie.  ‘onclick’ or ‘onmousedown’)
function funcfunction to be added
<HTMLNode n>if submitted the event listener will be added to this node instead of the node controlled by the element

find_common_parent

this.find_common_parent = function(Obj)

Find the first common vegui Parent that this element and Obj share

Parameters

VegUIElement ObjVegUI element

Returns

VegUIEleemntparent element if one is found
nullif no parent element is found

See also

is_parent

Example

var node1 = existingNode.add_child('node1', VUI_NODE);
var node2 = existingNode.add_child('node2', VUI_NODE);
var node3 = node2.add_child('node3', VUI_NODE);

// would return a reference to existingNode
return node3.find_common_parent(node1);

height

this.height = function()

Returns

intthe height of the HTML node controlled by this element
nullif no HTML node is currently controlled

See also

width, x, y, x2, y2

hevent_node

this.hevent = this.hevent_node = function(eventType,
mEvent)

private function

This function gets called whenever a mouse or keyboard event is handled by this element.It executes all the functions stored in the VegUIMouseState State property of this element for the event in question and sets the event specific properties.

Alias

hevent()

Parameters

int eventTypeMouse and keyboard event types
Event mEventjavascript event object

Returns

boolreturnVal property of the Scripts property of the affected VegUIMouseState

See also

tgl_event

hide

this.hide = function(b)

toggles this element to be invisible or visible

Parameters

bool bif true the element will be made invisible, if false the element will be made visible

See also

is_hidden

Example

myNode.hide(1); // node is hidden
myNode.hide(0); // node is visible again

is_hidden

this.is_hidden = function()

Checks if the HTML node controlled by this element is hidden or visible

Returns

booltrue if hidden
boolfalse if visible

See also

hide

Example

myNode.hide(1);
return myNode.is_hidden(); // returns true

is_parent

this.is_parent = function(Obj)

Check if a vegui element is the parent element of this element somewhere down the parent chain

Parameters

VegUiElement ObjVegUI element to check

Returns

int1 if Obj is the parent of this element
int0 if Obj is not the parent of this element

See also

find_common_parent

Example

myNode = pNode.add_child('myNode', VUI_NODE);
return myNode.is_parent(pNode); // returns true

kill

this.kill = function(removeSelf,
keepBase)

Removes the HTMLnode controlled by this element and/or destroys the element it self.  The onkill event is called by this function

Parameters

bool removeSelfif true this element will be unlinked from the manager and destroyed
bool keepBaseif true the HTML node controlled by this element will not be destroyed

See also

clear

Example

myNode.kill(); // only the html node is removed from the document
myNode.kill(1); // html node is removed from the document and element is destroyed
myNode.kill(1,1); // only the vegui element is destroyed

lose_focus_node

this.lose_focus = this.lose_focus_node = function(bail)

Takes focus away from this element, the first parent that can have focus set on it will gain passive focus.

Alias

lose_focus()

Paramters

<bool bail>if true the next focusable parent of this child will not gain focus

See also

set_focus_node, check_focus

move

this.move = function(x,
y)

moves the HTML node controlled by this element to new coordinates

Parameters

int xnew x position (pixels)
int ynew y position (pixels)

See also

set_x, set_y

Example

myNode.move(5, 15);

onmove

called when the element is moved via the set_x, set_y or move methods

onresize

called when the element is resized via the set_width, set_height or resize methods

ondock

triggered by dock method

onchange

varies from element to element

onkill

triggered by kill method

onfocusset

triggered when element gains focus

onfocuslose

triggered when element loses focus

onbuild

triggered after element was built

onhide

triggered by hide method

overlaps

this.overlaps = function(Node,
yDiffS,
yDiffT)

Checks if this element overlaps with another element.  Overlapping meaning they collide somewhere and one is covered by the other.

Be aware that this function only checks coordinates, it does not matter if the two nodes arent children of the same parent node, if their coordinates and proportions collide - even in theory - the function will return the overlapping percentage.

Parameters

VegUIElement Nodevegui element to check against
<int yDiffS>experimental manipulate y position of this element
<int yDiffT>experimental manipulate y position of Node

Returns

intoverlapping percentage value is returned (0-100)

resize

this.resize = function(w,
h,
noAlign)

resizes the HTML node controlled by this element

Parameters

int wwidth (pixels)
int hheight (pixels)
bool noAlignif true align_childs method will not be called

See also

set_width, set_height

set_focus_node

this.set_focus = this.set_focus_node = function(focusType)

Gives focus to the element.  When an element has focus the manager that spawned that element knows where to direct certain keyboard and mouse events to

Alias

set_focus()

Parameters

int focusType = Focus types

Returns

int1
int0 if focs is currently on a node that has it’s lockFocus property set to true

See also

lose_focus_node, check_focus

set_height

this.set_height = function(n,
noAlign)

sets the height of the HTML node controlled by this element

Parameters

int nheight (pixels)
bool noAlignif true the align_childs method will not be called

See also

set_width, resize

set_marg

this.set_marg = function(rmarg,
bmarg,
rmarg_nr,
bmarg_nr)

Template Function

Sets the margins of this element in relation to the proportions of it’s parent element

Parameters

int rmargright margin (pixels)
int bmargbottom margin (pixels)
int rmarg_nrright margin , no resize - node will be moved to meet margin (pixels)
int bmarg_nrbottom margin, no resize - node will be moved to meet margin (pixels)

Code Example

This would resize this element whenever the proportions of it’s parents change to leave a space of 5 pixels between the element’s right and bottom border and the parent’s right and bottom border

myNode.set_marg(5,5);

See also

<set>, set_node, align_childs

set_node

this.set = this.set_node = function(nodeType,
w,
h,
x,
y,
pos,
z)

Template Function

Sets the most common template properties for this element.  Properties will only be (re)set if valid values are submitted.  So if you do wish to ommit certain properties submit them as null

Alias

set()

Parameters

string nodeTypeHTML tag name (ie ‘div’)
int wwidth (pixels)
int hheight (pixels)
int xposition on the x axis (pixels)
int yposition on the y axis (pixels)
string posCSS position (ie ‘absolute’), default = ‘absolute’
int zz index

See also

set_marg

Example

myNode.set('div', 50, 50, 5, 5, 'absolute', 15);
Manager.build_element(myNode);

set_pos

this.set_pos = function(pos,
n)

sets the CSS position of the HTML node controlled by this element

Parameters

string poscss position value (ie ‘absolute’)
int nz index

Example

myNode.set_pos('absolute', 15);

set_transparency

this.set_transparency = function(n,
noIe)

Set the CSS transparency of the HTML node that is controlled by this element.

Parameters

int ntransparency value (percent, 0- 100)
bool noIedeprecated

Example

myNode.set_transparency(50); // 50% transparent

set_width

this.set_width = function(n,
noAlign)

sets the width of the HTML node controlled by this element

Parameters

int nwidth (pixels)
bool noAlignif true the align_childs method will not be called

See also

set_height, resize

set_x

this.set_x = function(n)

repositions the HTML node controlled by this element on the x axis

Parameters

int nposition (pixels)

See also

set_y, move

set_y

this.set_y = function(n)

repositions the HTML node controlled by this element on the y axis

Parameters

int nposition (pixels)

See also

set_x, move

stick

this.stick = function(toElement,
offsetX,
offsetY,
direction,
offsetZ)

Sticks the element to another element at a certain offset

Parameters

VegUIElement toElementelement to stick to
int offsetXx axis offset (px)
int offsetYy axis offset (px)
int directionVUI_FRONT or VUI_BACK
int offsetZz offset

tgl_event

this.tgl_event = function(b,
eventType,
nodeProp,
ret)

private function

Toggles event handling for a certain mouse or keyboard event on or off.  This function is called automatically by the <build> method if the flags property of this element has event handling enabled for a certain keyboard or mouse event

Parameters

bool btoggle on or off (true / false)
int eventTypeMouse and keyboard event types
string nodePropdom event name (ie onmousemove for VEGUI_MOUSE_MOVE)
bool retthis will be returned by the mouse event on the node

See also

hevent_node

undock

this.undock = function()

Removes the HTML node controlled by this element from its current parentNode.

Returns

HTMLNodethe parentNode the HTML node was attached to

See also

dock

Example

myNode.dock(document.body);
myNode.undock();

width

this.width = function()

Returns

intthe width of the HTML node controlled by this element
nullif no HTML node is currently controlled

See also

height, x, y, x2, y2

x

this.x = function()

Returns

intthe x position of the HTML node controlled by this element
nullif no HTML node is controlled by this element

See Also

y, x2, y2, abs_x, abs_y

x2

this.x2 = function()

Returns

intthe right position of the HTML node controlled by this element
nullif no HTML node is controlled by this element

See also

y2, x, y, abs_x, abs_y

y

this.y = function()

Returns

intthe y position of the HTML node controlled by this element
nullif no HTML node is controlled by this element

See also

x, x2, y2, abs_x, <abs y>

y2

this.y2 = function()

Returns

intthe bottom position of the HTML node controlled by this element
nullif no HTML node is controlled by this element

See also

x2, x, y, abs_x, abs_y

VegUIManager

Spawns and keeps track of all vegUI elements

Summary
extends vegUINode
Constructor
Attempts the prevention of the default browser action for a certain keyboard key code
builds a VegUIElement.
builds multiple vegUI elements, if the last argument submitted to the function is a HTML node then the element’s will be built as children of that node
builds the manager
clone multiple elements of the same template
evals some javascript code
Wrapper functions to create a new vegui element and clone it
private function
Creates a new VegUIElement
Includes javascript code from a file and executes is
initializes common VegUIBridge object that can be accessed by all spawned VegUIElements by accessing it over their Manager property
initializes common VegUIFXManager object that can be accessed by all spawned VegUIElements by accessing it over their Manager attribute
Check if a keycode has been blocked with <block_key>
Template function
Removes a keycode block set by <block_key> method

Hierarchy

extends vegUINode

VegUINode
|
|
+-- VegUIManager

Type

VUI_MANAGER

Child Elements

WinShadowVUI_NODE, Window ‘shadow’ that the user sees while resizing or dragging window elements

Properties

Object Properties

eleIdxint, element index counter
winIdxint, special index counter for elements of type VUI_WIN
ElementsArray, Holds all currently spawned elements
WindowsArray Holds all currently spawned windows
BridgeVegUIBridge, common VegUIBridge object, null until init_bridge method is called
VegUIFX FXVegUIFXManager, common VegUIFXManager object, null until init_fx method is called
VegUITaskbar Taskbarlink to a taskbar element that shell hold the windows spawned by this manager

Functions

VegUIManager

function VegUIManager(refName)

Constructor

Parameters

string refNamename of the object

block key

Attempts the prevention of the default browser action for a certain keyboard key code

Paramters

array keyCodekey codes to block

See also

unblock_key

Example

// user should not be able to scroll the browser window using
// the arrow keys anylonger

Manager.block_key([37,38,39,40]);

build_element

this.build_element = function(VegUIObj,
toNode)

builds a VegUIElement.  This is the function that should be used to build vegui elements, instead of calling the element’s build method whenever possible

Parameters

VegUIElement VegUIObjvegui element to build
<HTMLNode toNode>if submitted the html node will be appended to toNode

Returns

int1 on success
int0 on failure

See also

build_elements, VegUINode::build_node

Example

myNode = Manager.get_new(VUI_NODE);
myNode.set('div',50,50);
myNode.T.Css.backgroundColor = 'black';
Manager.build_element(myNode);

build_elements

this.build_elements = function()

builds multiple vegUI elements, if the last argument submitted to the function is a HTML node then the element’s will be built as children of that node

Added in

2.0.6

Parameters

VegUIElement ...VegUIElement to be built
<HTMLNode toNode>if submitted the elements will be built as children of this node

See also

build_element

Example

// myNode, myNode2 and myNode3 will be built from their template
// properties and then be appended to document.body

Manager.build_elements(myNode, myNode2, myNode3, document.body);

build_manager

this.build = this.build_manager = function(toNode,
takeBody)

builds the manager

Alias

build()

Parameters

<HTMLNode toNode>if submitted the created HTML node will be appended to toNode
<bool takeBody>instead of building a new node, the manager will take over the body element instead.

Returns

nullon failure
int1 on success

See also

VegUINode::build_node

clone_elements

this.clone_elements = function(T)

clone multiple elements of the same template

Parameters

VegUIElement Tthe template you wish to clone from
VegUIElement ...elements

Example

//myNode and myNode2 will be cloned from myTemplate
Manager.clone_elemebnts(myTemplate, myNode, myNode2);

evalme

this.evalme = function(code)

evals some javascript code

Parameters

string codecode to evaluate

get_clone

this.get_clone = function(Template,
Parent)

Wrapper functions to create a new vegui element and clone it

Parameters

VegUIElement Templatetemplate element to clone from
<VegUIElement Parent>parent of the created element

Returns

VegUIElementthe created element

See also

get_new

Example

myNode = Manager.get_new(VUI_NODE);
myNode2 = Manager.get_clone(myNode);

get_free_idx

this.get_free_idx = function()

private function

Returns a free element index, which is a ranom unused number between 0 and ELEMENT_MAX_INDEX

Returns

intunused element index number
nullif no unused element index number could be found

get_new

this.get_new = function(type,
Parent,
Template)

Creates a new VegUIElement

Parameters

int type<VegUI Element Types>
<VegUIElement Parent>Parent element of the element to be created
<VegUIElement Template>Template to clone the element from

Note

This is the function that should be used to create new vegui elements that are not the children of other vegui elements.

Returns

VegUIElementthe created vegui element

See also

get_clone

Example

myNode = Manager.get_new(VUI_Node);

include

this.include = function(path,
ondone,
async)

Includes javascript code from a file and executes is

Requires

actioninit_bridge needs to have been called

Parameters

string pathrelative file path
<function ondone>function to execute when the include is done
<bool async>if true, server request will be async to the execution of the script allowing the execution of the script to continue while the request is being sent

Example

Manager.init_bridge(); // only needs to be called once, not everytime
Manager.include('helloworld.js');

init_bridge

this.init_bridge = function()

initializes common VegUIBridge object that can be accessed by all spawned VegUIElements by accessing it over their Manager property

Requires

vegui.bridge.class.js

myNode.Manager.Bridge.dostuff()

Returns

VegUIBridgethe created VegUIBridge object

See also

init_fx

Example

Manager.init_bridge();
Manager.Bridge.send('somefile.txt', '', 'GET');

init_fx

this.init_fx = function(interval)

initializes common VegUIFXManager object that can be accessed by all spawned VegUIElements by accessing it over their Manager attribute

Requires

vegui.fx.class.js

myNode.Manager.FX.dostuff()

Parameters

int intervalfx timer interval (ms)

Returns

VegUIFXManagerthe created VegUIFXManager object

See also

init_bridge

key_is_blocked

this.key_is_blocked = function(keyCode)

Check if a keycode has been blocked with <block_key>

Parameters

int keyCodekey code to check

Returns

booltrue if key is blocked
boolfalse if key is not blocked

See also

<block_key>, unblock_key

Example

Manager.block_key([38]);
return Manager.key_is_blocked(38); // true

set_manager

this.set = this.set_manager = function(w,
h,
x,
y)

Template function

sets the most common template properties for the element

Alias

set()

Parameters

int wwidth (pixels)
int hheight (pixels)
int xposition on the x axis (pixels)
int yposition on the y axis (pixels)

See also

VegUINode::set_node

unblock_key

this.unblock_key = function(keyCode)

Removes a keycode block set by <block_key> method

Parameters

array keyCodekey codes to unblock

See also

<block_key>

Example

Manager.unblock_key([37,38,39,40]);

VegUIBBox

Bounding box for elements, limits where an element can be moved to.  Every VegUIElement has a bounding box located at its BBox property

Summary
Constructor
checks if the element is within the boundin box’s border, if not the element will be moved to be within the bounding box’s border
sets the bounding box up
Validates the position of the element that the bounding box belongs to

Properties

Object Properties

xint, x position (pixels)
yint, y position (pixels)
wint, width (pixels)
hint, height (pixels)
x2int, right position (pixels)
y2int, bottom position (pixels)
enabledbool, true if bounding box is enabled
cbool, true if auto correct mode is enabled
bumpedint, holds the direction where the last collision happened

Auto correct mode

if auto correct mode is on the element the bounding box is linked to will be moved back inside the bounding box should it happen to be located outside of the bounding box

Functions

VegUIBBox

function VegUIBBox(VegUIElement)

Constructor

Parameters

VegUIElement Elementthe vegui element this bounding box belongs to

correct

this.correct = function()

checks if the element is within the boundin box’s border, if not the element will be moved to be within the bounding box’s border

set

this.set = function(x,
y,
w,
h,
b,
c)

sets the bounding box up

Parameters

int xposition on the x coordinate (pixels)
int yposition on the y coordinate (pixels)
int wwidth (pixels)
int hheight (pixels)
bool benable or disable the bounding box
boolc cenable or disable auto correct mode

validate

this.validate = function(x,
y)

Validates the position of the element that the bounding box belongs to

Parameters

<int x>x position to check, if ommited this.Parent.x() is used
<int y>y position to check, if ommited this.Parent.y() is used

Returns

intn if position of the element is invalid then the direction of the collision will be returned (Generic directions)
int0 if position of the element is valid

VegUIDynFunc

Allows to have a function with dynamic content

Summary
Constructor
Adds a function to the stack
Executes all the functions in the stack
Free a unique function id effectivly removing the function linked to it from the stack

Properties

Object Properties

FuncsArray, holds the functions
returnValvariable, holds the value that will be returned by the execute method

Functions

VegUIDynFunc

function VegUIDynFunc(returnVal)

Constructor

Parameters

var returnValvalue to be returned by the execute method

add

this.add = function(fn,
id)

Adds a function to the stack

Parameters

function fnfunction to be added to the stack
var idunique id string

Code example

myDynFunc.add(function() { alert('hi'); }, 'hi');

See also

free

execute

this.execute = function(argArr)

Executes all the functions in the stack

Parameters

<Array ArgArr>Array that can hold various parameters.  In order for functions in the stack to be able to work with the argArr argument they need to be defined with it in mind

Code example

myDynFunc.add( function(argArr) { alert(argArr[0]); } );
myDynFunc.execute(['hello world']);

Returns

variablereturns the value of this.returnValue

free

this.free = function(id)

Free a unique function id effectivly removing the function linked to it from the stack

Parameters

variable idunique function id

See also

add

The most basic VegUI Element.
Spawns and keeps track of all vegUI elements
function vui_module_add(type,
module,
filename)
Makes a vegUI module accessable by the manager.
var browser_str = navigator.userAgent.toLowerCase(); function iesucks(Node)
Internet explorer 6 leaks memory in closures, in order to fix that iesucks is called when the page is unloaded if the browser is ie6
function Clone(Obj)
Creates a new instance of a javascript object
function merge(srcObj,
trgObj)
Attempt to append the properties of trgObj to srcObj
function cloneArray(Arr)
clones an array
function has_parent(Node,
Parent)
checks if Node is the child of Parent somewhere up the parent chain
function get_mouse(e)
get mouse pointer location, sets mouseX and mouseY
absolute x coordinate of the mouse pointer
absolute y coordinate of the mouse pointer
function htmlnode(nodeName,
parentNode)
Wrapper for document.createElement with the option to append the created node to another html node right away
function imgnode(src,
w,
h,
parentNode)
Wrapper for document.createElement to create an image node with the option to define proportions and image source right away
function txtnode(txt)
Wrapper for document.createTextNode
function vui_rand(min,
max)
generate a random number
function VegUIMouseState(eventType,
Parent)
Allows to have a function with dynamic content
function VegUINode(refName,
Parent,
Manager)
this.abs_middle = function(stopAt)
this.abs_x = function(stopAt)
this.abs_y = function(stopAt)
this.add_child = function(name,
type,
nodeName,
pos)
Creates a VegUI element as a child of this element.
this.add_child_o = function(name,
Obj)
Adds an existing VegUI Element to this element as a child
this.add_skin = function(n,
w,
h,
x,
y,
c,
rm,
bm,
rm_nr,
bm_nr,
nN,
i)
Wrapper function to add a new vegui element to this element as a child with the ability to set the most common template properties
this.align_childs = function(Child)
(Re)Aligns all child elements of this element to their margins
this.attach = this.attach_node = function(Element,
offsetX,
offsetY,
direction,
z)
Attaches another VegUI element to this node.
this.build = this.build_node = function(toNode,
takeNode)
build a HTML node from the template properties of this element.
this.call_ondock = function()
This function triggers the ondock event on this element and all its child elements recursivly
triggered by dock method
this.check_focus = function(focusType)
See if this element or any of its child elements has focus.
this.clear = function(replacement)
Removes all child HTML nodes from the HTML node that is controlled by this element
this.clone_event = function(Template)
Clones a vegUI event
this.clone = this.clone_node = function(Template)
Clones the children and properties of a template element to this element
this.clone_children = function(type,
T,
rec)
clone multiple children that are of the same type from the same template
this.control = function(Node)
Takes control over an existing HTML node
this.detach_node = this.detach = function(Element)
Detaches an attached element that was attached to this element via attach_node.
this.disable = this.disable_node = function(b)
Toggles the VUI_DISABLED flag on this element
flag VegUIElement as being disabled, prohibiting any event handling
this.dock = function(toNode,
insertBefore)
Appends the HTML node controlled by this element to another HTMLnode
this.event_add = function(eventName,
func,
funcId)
Adds a function to be executed to a vegui element event
this.event_execute = function(eventName,
args)
Fires a vegUI event
this.event_listener_set = function(eventName,
func,
n)
Add function to event listener of the node controlled by this element
this.find_common_parent = function(Obj)
Find the first common vegui Parent that this element and Obj share
this.height = function()
this.hevent = this.hevent_node = function(eventType,
mEvent)
private function
this.hide = function(b)
toggles this element to be invisible or visible
this.is_hidden = function()
Checks if the HTML node controlled by this element is hidden or visible
this.is_parent = function(Obj)
Check if a vegui element is the parent element of this element somewhere down the parent chain
this.kill = function(removeSelf,
keepBase)
Removes the HTMLnode controlled by this element and/or destroys the element it self.
this.lose_focus = this.lose_focus_node = function(bail)
Takes focus away from this element, the first parent that can have focus set on it will gain passive focus.
this.move = function(x,
y)
moves the HTML node controlled by this element to new coordinates
this.set_x = function(n)
repositions the HTML node controlled by this element on the x axis
this.set_y = function(n)
repositions the HTML node controlled by this element on the y axis
this.set_width = function(n,
noAlign)
sets the width of the HTML node controlled by this element
this.set_height = function(n,
noAlign)
sets the height of the HTML node controlled by this element
this.resize = function(w,
h,
noAlign)
resizes the HTML node controlled by this element
this.overlaps = function(Node,
yDiffS,
yDiffT)
Checks if this element overlaps with another element.
this.set_focus = this.set_focus_node = function(focusType)
Gives focus to the element.
this.set_marg = function(rmarg,
bmarg,
rmarg_nr,
bmarg_nr)
Template Function
this.set = this.set_node = function(nodeType,
w,
h,
x,
y,
pos,
z)
Template Function
this.set_pos = function(pos,
n)
sets the CSS position of the HTML node controlled by this element
this.set_transparency = function(n,
noIe)
Set the CSS transparency of the HTML node that is controlled by this element.
this.stick = function(toElement,
offsetX,
offsetY,
direction,
offsetZ)
Sticks the element to another element at a certain offset
this.tgl_event = function(b,
eventType,
nodeProp,
ret)
private function
this.undock = function()
Removes the HTML node controlled by this element from its current parentNode.
this.width = function()
this.x = function()
this.x2 = function()
this.y = function()
this.y2 = function()
function VegUIManager(refName)
Constructor
this.build_element = function(VegUIObj,
toNode)
builds a VegUIElement.
this.build_elements = function()
builds multiple vegUI elements, if the last argument submitted to the function is a HTML node then the element’s will be built as children of that node
this.build = this.build_manager = function(toNode,
takeBody)
builds the manager
this.clone_elements = function(T)
clone multiple elements of the same template
this.evalme = function(code)
evals some javascript code
this.get_clone = function(Template,
Parent)
Wrapper functions to create a new vegui element and clone it
this.get_free_idx = function()
private function
this.get_new = function(type,
Parent,
Template)
Creates a new VegUIElement
this.include = function(path,
ondone,
async)
Includes javascript code from a file and executes is
this.init_bridge = function()
initializes common VegUIBridge object that can be accessed by all spawned VegUIElements by accessing it over their Manager property
this.init_fx = function(interval)
initializes common VegUIFXManager object that can be accessed by all spawned VegUIElements by accessing it over their Manager attribute
Effect manager
this.key_is_blocked = function(keyCode)
Check if a keycode has been blocked with block_key
this.set = this.set_manager = function(w,
h,
x,
y)
Template function
this.unblock_key = function(keyCode)
Removes a keycode block set by block_key method
function VegUIBBox(VegUIElement)
Constructor
this.correct = function()
checks if the element is within the boundin box’s border, if not the element will be moved to be within the bounding box’s border
this.set = function(x,
y,
w,
h,
b,
c)
sets the bounding box up
this.validate = function(x,
y)
Validates the position of the element that the bounding box belongs to
function VegUIDynFunc(returnVal)
Constructor
this.add = function(fn,
id)
Adds a function to the stack
this.execute = function(argArr)
Executes all the functions in the stack
this.free = function(id)
Free a unique function id effectivly removing the function linked to it from the stack
holds pointers to all VegUIElement Constructor functions by their type
Mouse and keyboard eventtypes that help you identify what event you’re dealing with
vegUI element type for VegUINode
Bounding box for elements, limits where an element can be moved to.
back
front
Handles a certain keyboard or mouse event type that gets triggered by the VegUIElement the VegUIMouseState belongs to
triggered by kill method
vegUI element type for VegUIManager
VegUI element type for VegUIWindow
Maximum element index possible, 90000 by default, increase if you need to spawn more than 90000 elements at the same time