Skip to content

Instantly share code, notes, and snippets.

@sunify
Created December 16, 2014 13:38
Show Gist options
  • Save sunify/b1347dd8f564d14b4785 to your computer and use it in GitHub Desktop.
Save sunify/b1347dd8f564d14b4785 to your computer and use it in GitHub Desktop.
OnOutClickNoCommonJS
(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