Created
December 16, 2014 13:38
-
-
Save sunify/b1347dd8f564d14b4785 to your computer and use it in GitHub Desktop.
OnOutClickNoCommonJS
This file contains 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
(function () { | |
var handlers = {}; | |
document.addEventListener('click', onDocumentClick); | |
function onDocumentClick(evt) { | |
var rid = (evt.target.dataset && evt.target.dataset.reactid) || ''; | |
Object.keys(handlers).forEach(function(key) { | |
var hnd = handlers[key]; | |
if(rid.indexOf(key) !== 0) { | |
hnd.comp[hnd.handler](evt); | |
} | |
}); | |
}; | |
window.onOutClickMixin = function(handlerName) { | |
return { | |
componentDidMount: function() { | |
if(this[handlerName]) { | |
handlers[this._rootNodeID] = { | |
comp: this, | |
handler: handlerName | |
}; | |
} | |
}, | |
componentWillUnmount: function() { | |
delete handlers[this._rootNodeID]; | |
} | |
}; | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment