Skip to content

Instantly share code, notes, and snippets.

@dohoons
Last active November 3, 2017 05:29
Show Gist options
  • Save dohoons/46163c4739831dfb19fa66eaa7d05554 to your computer and use it in GitHub Desktop.
Save dohoons/46163c4739831dfb19fa66eaa7d05554 to your computer and use it in GitHub Desktop.
addDocumentEvent
// document 이벤트
var addDocumentEvent = function(eventList) {
return function(types, cb) {
var typeList = types.split(' ');
var type = '';
if(typeof cb !== 'function') return false;
for(var i = typeList.length; i--;) {
type = typeList[i];
if(eventList.hasOwnProperty(type)) {
eventList[type].push(cb);
} else {
eventList[type] = [cb];
document.addEventListener(type, function(e) {
for(var j = eventList[type].length; j--;) {
eventList[type][j].call(this, e);
}
});
}
}
};
}({});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment