ElementArray Class
Extends Array into an array with special utility-methods that can be applied upon its members. The membres should be vElement's
Copyright (c) 2014 ITSA - https://github.com/itsa
New BSD License - http://choosealicense.com/licenses/bsd-3-clause/
Item Index
Methods
append
-
content
-
escape
For all vElements of the ElementArray: Appends a HtmlElement or text at the end of HtmlElement's innerHTML.
defineInlineStyle
-
value
For all vElements of the ElementArray:
Sets the inline-style of the HtmlElement exactly to the specified value
, overruling previous values.
Making the HtmlElement's inline-style look like: style="value".
This is meant for a quick one-time setup. For individually inline style-properties to be set, you can use setInlineStyle()
.
Parameters:
-
value
Stringthe style string to be set
isPlugged
-
pluginClass
For all vElements of the ElementArray: Checks whether the plugin is plugged in at ALL the HtmlElements of the NodeList/HTMLCollection. Checks whether all its attributes are set.
Parameters:
-
pluginClass
NodePluginThe plugin that should be plugged. Needs to be the Class, not an instance!
Returns:
whether the plugin is plugged in
plug
-
pluginClass
-
options
For all vElements of the ElementArray: Plugs in the plugin on the HtmlElement, and gives is special behaviour by setting the appropriate attributes.
Parameters:
-
pluginClass
NodePluginThe plugin that should be plugged. Needs to be the Class, not an instance!
-
options
Objectany options that should be passed through when the class is instantiated.
prepend
-
content
-
[escape]
For all vElements of the ElementArray: Prepends a HtmlElement or text at the start of HtmlElement's innerHTML.
removeAttr
-
attributeName
-
[silent=false]
For all vElements of the ElementArray: Removes the attribute from the HtmlElement.
Alias for removeAttribute().
removeAttrs
-
attributeData
-
[silent=false]
For all vElements of the ElementArray: Removes multiple attributes on the Element. The argument should be one ore more AttributeNames.
Parameters:
Example:
instance.removeAttrs(['tabIndex', 'style']);
removeClass
-
className
For all vElements of the ElementArray: Removes a className from the HtmlElement.
Parameters:
-
className
Stringthe className that should be removed.
removeData
-
key
For all vElements of the ElementArray:
Removes data specified by key
. When no arguments are passed, all node-data (key-value pairs) will be removed.
Parameters:
-
key
Stringname of the key
removeInlineStyle
-
cssAttribute
For all vElements of the ElementArray: Removes a css-property (inline) out of the HtmlElement. Use camelCase.
Parameters:
-
cssAttribute
Stringthe css-property to be removed
removeNode
()
For all vElements of the ElementArray: Removes the HtmlElement from the DOM.
replaceClass
-
prevClassName
-
newClassName
-
[force
For all vElements of the ElementArray: Replaces the className of the HtmlElement with a new className. If the previous className is not available, the new className is set nevertheless.
replaceNode
-
newHtmlElement
-
[escape]
For all vElements of the ElementArray: Replaces the HtmlElement with a new HtmlElement.
setAttr
-
attributeName
-
value
-
[silent=false]
For all vElements of the ElementArray: Sets the attribute on the HtmlElement with the specified value.
Alias for setAttribute().
setAttrs
-
attributeData
-
[silent=false]
For all vElements of the ElementArray:
Sets multiple attributes on the Element with the specified value.
The argument should be one ore more Objects with the properties: name
and value
Parameters:
Example:
instance.setAttrs([ {name: 'tabIndex', value: '0'}, {name: 'style', value: 'color: #000;'} ]);
setClass
-
className
For all vElements of the ElementArray: Adds a class to the HtmlElement. If the class already exists it won't be duplicated.
Parameters:
-
className
StringclassName to be added
setData
-
key
-
value
For all vElements of the ElementArray:
Stores arbitary data
at the HtmlElement. This has nothing to do with node-attributes whatsoever,
it is just a way to bind any data to the specific Element so it can be retrieved later on with getData()
.
Parameters:
-
key
Stringname of the key
-
value
Anythe value that belongs to
key
setHTML
-
content
For all vElements of the ElementArray: Sets the content of the HtmlElement (innerHTML). Careful: only set content like this if you controll the data and are sure what is going inside. Otherwise XSS might occur. If you let the user insert, or insert right from a db, you might be better of using setContent().
Parameters:
-
content
HtmlElement | HtmlElementList | Stringcontent to append
setOuterHTML
-
val
For all vElements of the ElementArray: Gets or sets the outerHTML of both the Element as well as the representing dom-node. Goes through the vdom, so it's superfast.
Use this property instead of outerHTML
Syncs with the DOM.
Parameters:
-
val
Stringthe new value to be set
setStyle
-
cssAttribute
-
value
For all vElements of the ElementArray: Sets a css-property (inline) out of the HtmlElement. Use camelCase.
Note: no need to camelCase cssProperty: both margin-left
as well as marginLeft
are fine
setText
-
content
-
[escape]
For all vElements of the ElementArray: Sets the content of the HtmlElement. This is a safe way to set the content, because HTML is not parsed. If you do need to set HTML inside the node, use setHTML().
toggleClass
-
className
For all vElements of the ElementArray: Toggles the className of the Element.
Parameters:
-
className
Stringthe className that should be toggled
unplug
-
pluginClass
For all vElements of the ElementArray: Unplugs a NodePlugin from the HtmlElement.
Parameters:
-
pluginClass
NodePluginThe plugin that should be unplugged. Needs to be the Class, not an instance!