index.js 815 B

1234567891011121314151617181920212223242526272829303132333435
  1. var bind = window.addEventListener ? 'addEventListener' : 'attachEvent',
  2. unbind = window.removeEventListener ? 'removeEventListener' : 'detachEvent',
  3. prefix = bind !== 'addEventListener' ? 'on' : '';
  4. /**
  5. * Bind `el` event `type` to `fn`.
  6. *
  7. * @param {Element} el
  8. * @param {String} type
  9. * @param {Function} fn
  10. * @param {Boolean} capture
  11. * @return {Function}
  12. * @api public
  13. */
  14. exports.bind = function(el, type, fn, capture){
  15. el[bind](prefix + type, fn, capture || false);
  16. return fn;
  17. };
  18. /**
  19. * Unbind `el` event `type`'s callback `fn`.
  20. *
  21. * @param {Element} el
  22. * @param {String} type
  23. * @param {Function} fn
  24. * @param {Boolean} capture
  25. * @return {Function}
  26. * @api public
  27. */
  28. exports.unbind = function(el, type, fn, capture){
  29. el[unbind](prefix + type, fn, capture || false);
  30. return fn;
  31. };