Element based functions.
Members
-
<static> Events :Arrays
-
Stored Element Events.
Type:
- Arrays
Methods
-
<static> $q(selector)
-
Returns a DOM element.
Parameters:
Name Type Description selector
String The DOM selector.
Returns:
- Type
- HTMLElement
-
<static> $qAll(selectors)
-
Returns an array of DOM ellements.
Parameters:
Name Type Description selectors
String Selectors to find in the DOM.
Returns:
- Type
- Array
-
<static> addClass(elem, classN)
-
Adds a class name to the element passed.
Parameters:
Name Type Description elem
HTMLElement The element to add a class name to.
classN
String The class name to add.
-
<static> clean(node)
-
Returns an element without whitespace.
Parameters:
Name Type Description node
HTMLElement The element to remove whitespace from.
Returns:
- Type
- HTMLElement
-
<static> clicked(evt)
-
Returns element that was clicked.
Parameters:
Name Type Description evt
Event The event object.
Returns:
- Type
- HTMLElement
-
<static> collides(arg1, arg2)
-
Returns
true
orfalse
if an element collides with another one.Parameters:
Name Type Description arg1
HTMLElement | Object Element to detect collision or object with coordinates.
arg2
HTMLElement | Object Second element to detect collision or object with coordinates.
Returns:
- Type
- Boolean
Example
var elem1 = ML.El.$('test-elem-1'); var elem2 = {width: 100, height: 300, x: 0, y: 200}; // You can also pass in an var collides = ML.El.collides(elem1, elem2); // object of coordinates. // i.e. width, height, x and y. if (collides) { console.log('Elements are colliding.'); } else { console.log('No collision detected.') }
-
<static> create(element [, attrs])
-
Returns an element to be created in the DOM with attributes passed.
Parameters:
Name Type Argument Description element
HTMLElement The tag to create, i.e.
div
.attrs
Object <optional>
Attributes to add to tag.
Returns:
- Type
- HTMLElement
Example
// NOTE: When setting class name make sure to put in quotes, see example: var div = ML.El.create('div', {'id': 'test-elem', 'class': 'cool-div'});
-
<static> cssTransform(el, values)
-
Applies CSS transform to an element.
Parameters:
Name Type Description el
HTMLElement Element to apply style to.
values
String The CSS transform values to apply.
-
<static> cssTransition(el, values)
-
Applies a CSS transition to an element.
Parameters:
Name Type Description el
HTMLElement Element to apply style to.
values
String The css transition values to apply.
-
<static> customEventTrigger(name, data [, el])
-
Create a custom event.
Parameters:
Name Type Argument Default Description name
String The name of the custom event.
data
Object Data to send with the custom event.
el
HTMLElement <optional>
document Element to attach the custom event to.
-
<static> data(element, attr)
-
Returns a data attribute.
Parameters:
Name Type Description element
HTMLElement The element to get the data attribute value for.
attr
String The data attribute, excluding
data-
.Returns:
- Type
- String | Number
-
<static> dimens(elem)
-
Returns the width, height, x and y position of an element.
Parameters:
Name Type Description elem
HTMLElement The element's dimensions.
Returns:
- Type
- Object
-
<static> evt(el, type, cb [, capture])
-
Event listener bound to elements.
Parameters:
Name Type Argument Default Description el
HTMLElement The element to bind an event to.
type
String The type of event.
cb
function Callback function.
Properties
Name Type Description e
Event The Event Object.
capture
Boolean <optional>
false -
<static> findParent(el, tag, classN)
-
Returns parent element specified. Returns false if element is not found.
Parameters:
Name Type Description el
HTMLElement The child element to search for ancestor elements.
tag
String Name of tag to search for.
classN
String Class name of the tag to search for.
Returns:
- Type
- HTMLElement | Boolean
-
<static> getAttr(element, attr)
-
Returns attribute value for passed attribute.
Parameters:
Name Type Description element
HTMLElement The element to get the attribute value for.
attr
String The attribute to get a value from.
Returns:
- Type
- String | Number
-
<static> getStyle(element, styleProp)
-
Returns a style for a specific element.
Parameters:
Name Type Description element
HTMLElement The element to get styles for.
styleProp
String Style property to get the value of.
Returns:
- Type
- Object
-
<static> hasClass(elem, classN)
-
Returns
true
orfalse
if an element has a specific class name.Parameters:
Name Type Description elem
HTMLElement Element to check if it has a specific class name.
classN
String The class name to check for.
Returns:
- Type
- Boolean
-
<static> isBound(node, type, funcName)
-
Returns
true
orfalse
if an event is bound to an element.Parameters:
Name Type Description node
HTMLElement The HTML element to track.
type
String The type of event, i.e.
click
,focus
etc...funcName
String The name of the function bound to the element.
Returns:
- Type
- Boolean
-
<static> position(elem)
-
Returns the x and y position of an element.
Parameters:
Name Type Description elem
HTMLElement The element's x and y position.
Returns:
- Type
- Object
-
<static> removeClass(elem, classN [, multiple])
-
Removes a class name from an element.
Parameters:
Name Type Argument Default Description elem
HTMLElement The element of the class name to be removed.
classN
String Class name(s) to be removed.
multiple
Boolean <optional>
false If there are multiple class names to be removed.
-
<static> removeEvt(el, type, cb [, capture])
-
Remove event listener bound to an element.
Parameters:
Name Type Argument Description el
HTMLElement The element to remove the event from.
type
String The type of event.
cb
function Callback function.
Properties
Name Type Description e
Event The Event Object.
capture
Boolean <optional>
-
<static> setStyles(element, props)
-
Styles an element.
Parameters:
Name Type Description element
HTMLElement The element to set styles to.
props
Object Style properties and values.
-
<static> toggleClass(elem, classN [, cond])
-
Toggles the class name of an element.
Parameters:
Name Type Argument Description elem
HTMLElement The element to toggle class name.
classN
String The class name to toggle.
cond
Boolean <optional>
Boolean value to determine whether class name should be added or removed.