example.js 638 B

12345678910111213141516171819202122
  1. void function () {
  2. 'use strict';
  3. function events (el, type, fn) {
  4. if (el.addEventListener) {
  5. el.addEventListener(type, fn);
  6. } else if (el.attachEvent) {
  7. el.attachEvent('on' + type, wrap(fn));
  8. } else {
  9. el['on' + type] = wrap(fn);
  10. }
  11. function wrap (originalEvent) {
  12. var e = originalEvent || global.event;
  13. e.target = e.target || e.srcElement;
  14. e.preventDefault = e.preventDefault || function preventDefault () { e.returnValue = false; };
  15. e.stopPropagation = e.stopPropagation || function stopPropagation () { e.cancelBubble = true; };
  16. fn.call(el, e);
  17. }
  18. }
  19. }();