The only DOM abstraction you will need
Just import methods you need
import { get } from 'uc-dom'
Runs the fn
when DOM is ready
returns:
Element
if selector is an idHTMLCollection
if selector is a classNodeList
for everything else
Parameters:
selector
— css selectorroot
— default is document. root element to look in
Returns the closest ancestor of the current element (or the current element itself) which matches the selector
Creates and return an element from selector
. If content
is present, it will be added as innerHTML.
Creates an element with the specified namespace URI and qualified selector.
Sets the value of an attribute on the specified element. If value is undefined
returns the value of the attribute.
appends or prepends the el
to the parent
appends or prepends the el
to the parent
Inserts a node
before the el
as a child of its parent node
Inserts a node
after the el
as a child of its parent node
Removes all the child elements from the el
element
Removes el
from the DOM
Sets up a handler
function to be called whenever the specified event is delivered to the el
. If selector
is present will call the function if event target matches the selector
Returns a handler
function
Sets up a handler
function to be called whenever the specified event is delivered to the el
. The handler
function will be called only once.
Returns a handler
function
Removes previously registered an event
listener from the el
. Returns a handler
function.
Addes all event handlers from events
object to ctx.el
.
Removes all event handlers for ctx.el
added with onEvents
method.
Adds classes to the el
.
Removes classes from the el
.
Toggle cls
value. When the force
is present, if is is evaluates to true, adds specified class value, and if it evaluates to false, removes it.
Replace all classes that match the rx
regexp with newClass
. Returns the number of new classes.
Adds cls
, waits delay
ms and then removes
it. Returns timeoutID, it can be passed to clearTimeout() to cancel the timeout. The optional cb
function will be called after class is removed.
import compose from 'uc-compose';
import domMethods from 'uc-dom/methods';
const MyUIComponent = function() {}
MyUIComponent.prototype = compose(
domMethods,
{
componentMethod: function() {
// add class active to this.el
this.addClass('active');
}
}
)
This mixin adds following methods to your class (all the methods use this.el
):
- addClass
- removeClass
- toggleClass
- replaceClass
- appendTo
- prependTo
- insertBefore
- insertAfter
- find
- attr
License MIT
© velocityzen