Documentation
Utils
isEmpty #
el | Node Element Dom |
Returns: Boolean
Check if the node or element has empty content.
var is = this.utils.isEmpty(el);
isEmptyHtml #
html | String |
Returns: Boolean
Check as follows: if HTML contains nothing but spaces, empty tags and br tags, then the HTML string is empty.
var is = this.utils.isEmptyHtml(html);
getChildNodes #
el | Node Element Dom |
Returns: Array
Return all child nodes (with text nodes) from the element recursively.
var nodes = this.utils.getChildNodes(el);
getChildElements #
el | Node Element Dom |
Returns: Array
Return all child nodes (without text nodes) from the element recursively.
var elements = this.utils.getChildElements(el);
getFirstNode #
el | Node Element Dom |
Returns: Node
Return the first node (maybe a text node) from the element.
var node = this.utils.getFirstNode(el);
getLastNode #
el | Node Element Dom |
Returns: Node
Return the last node (maybe a text node) from the element.
var node = this.utils.getLastNode(el);
getFirstElement #
el | Node Element Dom |
Returns: Element
Return the first element (not a text node) from the element.
var element = this.utils.getFirstElement(el);
getLastElement #
el | Node Element Dom |
Returns: Element
Return the last element (not a text node) from the element.
var element = this.utils.getLastElement(el);
createTmpContainer #
html | String Nodelist Node Element Dom |
Returns: Element
Create a temporary div container that will contain the specified html. It can get both a string and DOM elements. Returns the created Dom element.
var container = this.utils.createTmpContainer(html);
createFragment #
html | String Nodelist Node Element Dom |
Returns: Object
Create the object from HTML or nodelist/node/element with following data:
- frag - documentFragment;
- nodes - the array of nodes in the fragment;
- first - the first node in the fragment;
- last - the last node in the fragment.
var frag = this.utils.createFragment(html);
console.log(frag.nodes);
isFragment #
frag | Object |
Returns: Boolean
Check if the passed object is the fragment which created with utils. createFragment
method.
var isFragment = this.utils.isFragment(frag);
parseHtml #
html | String Nodelist Node Element Dom |
Returns: Object
Create the object from HTML or nodelist/node/element with following data:
- html - HTML string
- nodes - Dom nodes from the passed argument.
var data = this.utils.parseHtml('<p>my html</p>');
var data = this.utils.parseHtml(node);
console.log(data.html, data.nodes);
ucfirst #
str | String |
Returns: String
Make the first letter of the string is upper case.
var str = this.utils.ucfirst('mystring'); // return 'Mystring'
removeFromArrayByValue #
arr | Array | |
value | Mixed |
Returns: Array
Remove item from the specified array by value.
' var arr = this.utils.removeFromArrayByValue([2, 3, 1], 1);
// returns [2, 3];
removeEmptyAttr #
el | Node Element Dom | |
name | String |
Returns: Boolean
Remove an attribute from the specified element if it has an empty value.
Return true
if the value was empty and the attribute is removed, or if the element does not have such one.
Return false
if the value was not empty and the attribute was not removed.
var isRemoved = this.utils.removeEmptyAttr(el, 'style');
cloneAttributes #
elFrom | Node Element Dom | |
elTo | Node Element Dom |
Returns: Node
Clone the attributes of one element to another. Return the element to which the attributes were cloned.
var elTo = this.utils.cloneAttributes(elFrom, elTo);
normalizeTextNodes #
el | Node Element Dom |
Glue text nodes into one in the element.
this.utils.normalizeTextNodes(el);
isRgb #
str | String |
Returns: Boolean
Check if the string is the RGB color string.
var isRgb = this.utils.isRgb('rgb(0, 0, 0);'); // true
var isRgb = this.utils.isRgb('rgba(255, 255, 255, .5);'); // true
rgb2hex #
str | String |
Returns: String
Return the RGB color string to the HEX one.
var hex = this.utils.rgb2hex('rgb(0, 0, 0);'); // #000000
var hex = this.utils.rgb2hex('rgba(255, 255, 255, .5);'); // #ffffff
replaceToTag #
el | Node Element Dom | |
tag | String |
Returns: Object
Replace the tag of passed element to the specified one with cloning all attributes. Returns the wrapped Dom object.
var $span = this.utils.replaceToTag(el, 'span');
toParams #
obj | Object |
Returns: String
Return the sring like 'key1: value1; key2: value2;'
from params object.
var obj = { color: 'red', 'font-weight': 'bold' };
var str = this.utils.toParams(obj);
// returns 'color:red;font-weight:bold;'
styleToObj #
str | String |
Returns: Object
Return the object with params from the CSS style string.
var el = document.getElementById('my-element');
var obj = this.utils.styleToObj(el.getAttribute('style'));
checkProperty #
obj | Object | |
level1 ... levelN | String Array |
Returns: Boolean
Check for the existence of keys in the most deeply nested objects.
var is = this.utils.checkProperty(obj, 'level1', 'level2', 'propertyname');
var is = this.utils.checkProperty(obj, ['level1', 'level2', 'propertyname']);
escapeRegExp #
str | String |
Returns: String
Return the escaped regular expression string.
var escapedRegExpString= this.utils.escapeRegExp(str);
extendData #
data | Object | |
extraData | Object |
Extend an object with values, including values in the input and form fields if the additional object has key elements
with field and form selectors.
The values of the input and form fields are appended as values: field-name: value
.
var data = {
name: 'my-name'
};
var extraData = {
id: 10,
elements: '#my-input-1, #my-input-2, #my-form'
};
data = this.utils.extendData(data, extraData);