Skip to content

Instantly share code, notes, and snippets.

@barneycarroll
Created August 22, 2014 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save barneycarroll/16cdf52722f6addbdcd9 to your computer and use it in GitHub Desktop.
Save barneycarroll/16cdf52722f6addbdcd9 to your computer and use it in GitHub Desktop.
Event capturing in Mithril.js
// Event capturing for Mithril.js
// Demo here: http://jsfiddle.net/barney/vsw8r3Lh/
m.capture = function capturingEventHandler( eventName, handler ){
function bindCapturingHandler( element ){
element.addEventListener( eventName, handler, true );
}
return function config( element, init ){
if( !init ) bindCapturingHandler( element );
};
};
@sdemjanenko
Copy link

Cool. You should add a context.onunload to the config function to prevent event leakage.

@saniko
Copy link

saniko commented Dec 19, 2014

something wrong with the jsfiddle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment