Created
October 9, 2014 13:02
-
-
Save rbarros/6c7888320ee0cdc3bab7 to your computer and use it in GitHub Desktop.
EventListener
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! EventListener - v1.0.0 - 2014-05-30 | |
* Controla os eventos de click | |
* Copyright (c) 2014 Ramon Barros; Licensed MIT */ | |
(function (root) { | |
'use strict'; | |
var EventListener = function () { | |
this.version = '1.0.0'; | |
}; | |
EventListener.prototype.addEvent = function(el, type, fn) { | |
var i = 0; | |
if (root.document.addEventListener) { | |
if (el && el.nodeName || el === root) { | |
el.addEventListener(type, fn, false); | |
} else if (el && el.length) { | |
for (i; i < el.length; i++) { | |
root['EventListener'].addEvent(el[i], type, fn); | |
} | |
} | |
} else { | |
if (el && el.nodeName || el === root) { | |
el.document.body.attachEvent('on' + type, function () { return fn.call(el, root.event, root['EventListener']); }); | |
} else if (el && el.length) { | |
for (i; i < el.length; i++) { | |
root['EventListener'].addEvent(el[i], type, fn); | |
} | |
} | |
} | |
}; | |
root['EventListener'] = new EventListener(); | |
}(this)); | |
/* | |
EventListener.addEvent(document.getElementsByTagName('a'), 'click', function () { | |
}); | |
EventListener.addEvent(document.getElementsByTagName('input'), 'submit', function () { | |
}); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment