# All files / src/utils events.js

75% Statements 9/12
50% Branches 5/10
50% Functions 1/2
75% Lines 9/12

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    3917x
    17x
    17x
    17x

    17x
    397x
    397x
    106x

    17x

     var bind = window.addEventListener ? 'addEventListener' : 'attachEvent',
        unbind = window.removeEventListener ? 'removeEventListener' : 'detachEvent',
        prefix = bind !== 'addEventListener' ? 'on' : '',
        toArray = require('./to-array');

    /**
     * Bind `el` event `type` to `fn`.
     *
     * @param {Element} el, NodeList, HTMLCollection or Array
     * @param {String} type
     * @param {Function} fn
     * @param {Boolean} capture
     * @api public
     */

    exports.bind = function(el, type, fn, capture){
      el = toArray(el);
      for ( var i = 0; i < el.length; i++ ) {
        el[i][bind](prefix + type, fn, capture || false);
      }
    };

    /**
     * Unbind `el` event `type`'s callback `fn`.
     *
     * @param {Element} el, NodeList, HTMLCollection or Array
     * @param {String} type
     * @param {Function} fn
     * @param {Boolean} capture
     * @api public
     */

    exports.unbind = function(el, type, fn, capture){
      el = toArray(el);
      for ( var i = 0; i < el.length; i++ ) {
        el[i][unbind](prefix + type, fn, capture || false);
      }
    };