dist/chirashi.common.js
function delegate(selector, input) {
  var target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : document.body;

  target = getElement(target);

  var eventsObj = {};
  forIn(input, _wrapOptions.bind(null, selector, target, eventsObj));

  var off = on(target, eventsObj);

  return function (events) {
    off(target, events);
  };
}
function delegate(selector, input) {
  var target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : document.body;

  target = getElement(target);

  var eventsObj = {};
  forIn(input, _wrapOptions.bind(null, selector, target, eventsObj));

  var off = on(target, eventsObj);

  return function (events) {
    off(target, events);
  };
}
function delegate ( selector , input ) { var target = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : document . body ; target = getElement ( target ) ; var eventsObj = { } ; forIn ( input , _wrapOptions . bind ( null , selector , target , eventsObj ) ) ; var off = on ( target , eventsObj ) ; return function ( events ) { off ( target , events ) ; } ; }
Called to remove one or all events listeners of one or all elements.
@callback offCallback
@param {(string|Array|NodeList|HTMLCollection|EventTarget)} [offElements] - The iterable, selector or elements to unbind.
@param {string} [events] - The events to unbind. Must be provided in the same syntax as in input.
 
Delegate events listener on delegate and execute callback when target matches selector (targets doesn't have to be in the DOM).
@param {string} selector - The selector to match.
@param {Object.<string, delegateCallback>} input - An object in which keys are events to delegate seperated with coma and/or spaces and values are delegateCallbacks.
@param {(string|Array|NodeList|HTMLCollection|EventTarget)} [target=document.body] - The event target. Note that it'll be passed to getElement to ensure there's only one.
@return {offCallback} off - The unbind function.
@example //esnext
import { createElement, append, delegate, trigger } from 'chirashi'
const off = delegate('.cheese, .wasabi', {
click(e, target) => {
console.log('clicked', target)
},
'mouseenter mousemove': (e, target) => {
console.log('mouse in', target)
}
})
const maki = createElement('a.cheese.maki')
const sushi = createElement('a.wasabi.sushi')
append(document.body, [maki, sushi])
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('mouseenter mousemove') //remove mouseenter and mousemove listeners
off() //remove all listeners
@example //es5
var off = Chirashi.delegate('.cheese, .wasabi', {
'click': function (e, target) {
console.log('clicked', target)
},
'mouseenter mousemove': function(e, target) {
console.log('mouse in', target)
}
})
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('mouseenter mousemove') //remove mouseenter and mousemove listeners
off() //remove all listeners
Called to remove one or all events listeners of one or all elements .