ric
Ricardo mini framework for DOM manipulation and other things.
Role: provide very basic functionality related to the DOM, events, the browser
and a couple of essential polyfills. Keep it simple and small.
The ric function is an instance builder or an initializer depending
of what is passed as first parameter.
ric(function() {
})
var articles = ric('#some .articles')
console.log(articles.dom)
ric(document.body).addClass('something')
ric([document.body, document.querySelector('#footer')])
Ric instance methods
Once a ric instance is created, you have a list of methods you can use.
ric.prototype.hasClass(className)
ric.prototype.get(index || 0)
ric.prototype.find(selector)
ric('#articles').find('a').hide()
ric.prototype.addClass(className)
ric.prototype.removeClass(className)
ric.prototype.each((dom, index) => {
console.log(dom, index)
})
ric.prototype.reduce((dom, index) => {
return dom.getAttribute('data-price')
})
ric.prototype.toggleClass(classA, <classB>)
ric.prototype.text(<value>)
ric.prototype.on(event, eventHandler)
var eventList = ric.prototype.delegate(event, selector, eventHandler)
ric('#article-list').delegate('click', '[data-tracking-id]', (e) => {
track(e.delegationTarget.getAttribute('data-tracking-id')
})
ric.prototype.closest(selector || predicate)
ric.prototype.hide()
ric.prototype.show(display='block')
Ric Standalone Functions
Standalone methods not associated with the DOM elements. Those can
be called from the ric function directly.
ric.closest(DOMElement, predicate)
ric.any(iterable, predicate)
ric.apply(iterable, func)
ric.each(iterable, func)
ric.each([1, 2, 3], (item, index) => { console.log(item, index) })
> 1, 0
> 2, 1
> 3, 2
ric.reduce(array, func)
var debounced = ric.debounce(decoratee, wait, immediate)
var debounced = ric.debounce(() => { console.log('blop') }, 1000)
debounced(); debounced(); debounced()
> blop
debounced.cancel()
ric.off(eventList)
ric.one(selector).addClass('blop')
ric.requestAnimationFrameThrottle(decorated)
var throtteled = ric.requestAnimationFrameThrottle(function(){ console.log('blop') })
throtteled(); throtteled(); throtteled()
> blop