Html

Html elements

Allows jQuery -type of DOM handling in PHP.

Returns eHtmlElement that can be used to define, how HTML element should be rendered: Tag name, attributes, classes, style definitions, parents and child elements...

Object can be created through resource -method: get

Arguments

$type
Type of HTML element, ie. tagName
$params
Array: List of values to be set to the element.

Example

Create Header:

$Div = $this->get('html', 'DIV', 'Hello world!');
--- $Div outputs
<DIV>Hello World!</DIV>

Creating an element

Set element attributes with second parameter as array:

$Div = $this->get('html', 'DIV', Array(
   'content' => 'Hello World!',
   'id'      => 'header',
   'role'    => 'page-header',
   'class'   => 'page__header'
));
--- $Div outputs
<DIV id="header" data-role="page-header" class="page__header">Hello World!</DIV>

Set same attributes via set -methods:

$Div = $this->get('html', 'DIV')
   ->setContent('Hello World!')
   ->setId('header')
   ...

Nesting elements

Create element and add it to another element:

$UL = $this->get('html', 'UL');
$LI = $this->get('html', 'LI', 'Line')->appendTo($UL);
--- $UL outputs
<UL>
  <LI>Line</LI>
</UL>

Create and add element using parent element:

$UL->appendElement('LI', 'Second line');
$UL->prependElement('LI', 'First line');
--- $UL outputs
<UL>
  <LI>First line</LI>
  <LI>Line</LI>
  <LI>Second line</LI>
</UL>

Full method list

Create element

Method Return Description
::create(tag,html) eHtmlElement Create new eHtmlElement.
setTag(name) this Set element tag name.
getTag() string  Get element tag name
setContent(string) this  Set string as tag html content.
addContent(string)  this  Add string to tag html content.
clearContent() this  Revoe all html content from tag.
getContent()  string Get tag html content.
html(string)  this  Set string as tag html content.
html()  string Get tag html content.

Structure

Method Return Description
append(data)  string,object  Add content inside tag.
prepend(data)  string,object  Add content in start of tag.
appendTo(eHtmlElement)  this  Add element inside other element.
prepend(eHtmlElement)  this  Add element in start of other element.
getParent() eHtmlElement Get elements parent element

Events

Method Return Description
bind(name,function)  this  Binb javascript function to event.

Style

Class

Method Return Description
setClass(name) this Set tag class, clear old definitions.
addClass(name, name...) this Add classes to tag.
removeClass(name) this Remove given class.
clearClass() this Clear all class definitions.
isClass() bool Return TRUE if element at least one class.
isClass([name]) bool REturn TRUE if element has given class.
getClass() array Classes in array.
getClassString() this Classes inspace delimited string.

CSS styles

Method Return Description
setCss(name,value) this Set CSS value.
setCss(array) array Set CSS from assoc array. Clear previous definitions.
addCss(name,value) this Add value to CSS.
addCss(array) this Add CSS values from assoc array.
clearCss(name,value) this Clear all css definitions.
getCss(name) string Get css value.
getCss() array Get all css definitions.
getCssString() string  Return CSS definitions in: style="name:value;" -string
setWidth(name,value) this Set element width. Alias to setCss('width',100), except adds missing unit.
setHeight(name,value) this Set element height. Alias to setCss('height',100), except adds missing unit.

Attr

All undedfined method clas are setName()

Method Return Description
setAttr(name,value) this Set attr variable.
setAttr(array) this Set attr values from assoc array.
addAttr(name,value) this Set value to attribute.
addAttr(array) this Set multiple attribute values vrom assoc array.
isAttr(name) bool Return TRUE, if attr is defined.
removeAttr(name) this Remove attr definition.
removeAttr() this Remove all attr definitions.
clearAttr(name) this Clear calue in attr.
getAttrDelimiter(name)  string Get delimiter used to combine multiple values. (Semicolon or space).
setAttrText() this  Additional freetext that is added in end of tag.
getAttrString() string  Return attributes n: name="value" -format.

Magic attributes

All undefined methods are cast as set/get attr method

Method Return Description
name()  string Alias to getAttr(name)
name(value) this Alias to setAttr(name,value)
getName() string Alias to getAttr(name)
setName(value) this Alias to setAttr(name,value)
addName(value) this Alias to addAttr(name,value)
isName() bool  Alias to isAttr(name)
clearName() this  Alias to isAttr(name)

Data

Data values are set in tag as:

Method Return Description
setRole(name) this Set role. Alias to setData('role',name)
setData(name,value) this Set value to variable.
setData(array) this Set values from assoc array
addData(array) this Add values from assoc array
clearData() this Clear all data definitions.
removeData(name) this Remove definition of certain value.
getData(name) mixed Get value of var.
getData() array Get all vars.
getDataString() string Get data in: data-name=value -format

Var

Var can be used to save and retrieve values that are used

Method Return Description
setVar(name,value) this Set value to variable.
setVar(array) this Set values from assoc array
getVar(name) mixed Get value of var.
getVar() array Get all vars.