dist/chirashi.common.js
function on(elements, input) {
  elements = _setEvents(elements, 'add', input);

  return function (offElements, events) {
    _setEvents(offElements || elements, 'remove', events ? defineProperty({}, events, input[events]) : input);
  };
}
function on(elements, input) {
  elements = _setEvents(elements, 'add', input);

  return function (offElements, events) {
    _setEvents(offElements || elements, 'remove', events ? defineProperty({}, events, input[events]) : input);
  };
}
function on ( elements , input ) { elements = _setEvents ( elements , 'add' , input ) ; return function ( offElements , events ) { _setEvents ( offElements || elements , 'remove' , events ? defineProperty ( { } , events , input [ events ] ) : input ) ; } ; }
Bind events listener on each element of elements.
@param {(string|Array|NodeList|HTMLCollection|EventTarget)} elements - The iterable, selector or elements.
@param {Object.<string, (eventCallback|EventObject)>} input - An object in which keys are events to bind seperated with coma and/or spaces and values are eventCallbacks or EventObjects.
@return {offCallback} off - The unbinding function.
@example //esnext
import { createElement, append, on, trigger } from 'chirashi'
const maki = createElement('a.cheese.maki')
const sushi = createElement('a.wasabi.sushi')
append(document.body, [maki, sushi])
const off = on('.cheese, .wasabi', {
click(e, target) {
console.log('clicked', target)
},
'mouseenter mousemove': {
handler: (e, target) => {
console.log('mouse in', target)
},
passive: true
}
})
trigger(maki, 'click') //simulate user's click
// LOGS: "clicked" <a class="maki cheese"></a>
trigger(sushi, 'click') //simulate user's click
// LOGS: "clicked" <a class="sushi wasabi"></a>
off(maki, 'click') //remove click event listener on maki
off() //remove all listeners from all elements
@example //es5
var off = Chirashi.bind('.cheese, .wasabi', {
'click': function (e, target) {
console.log('clicked', target)
},
'mouseenter mousemove': {
handler: (e, target) => {
console.log('mouse in', target)
},
passive: true
}
})
var maki = Chirashi.createElement('a.cheese.maki')
var sushi = Chirashi.createElement('a.wasabi.sushi')
Chirashi.append(document.body, [maki, sushi])
Chirashi.trigger(maki, 'click') //simulate user's click
// LOGS: "clicked" <a class="maki cheese"></a>
Chirashi.trigger(sushi, 'click') //simulate user's click
// LOGS: "clicked" <a class="sushi wasabi"></a>
off(maki, 'click') //remove click event listener on maki
off() //remove all listeners from all elements
Bind events listener on each element of elements .