Created
October 7, 2012 19:45
-
-
Save bloodyowl/3849358 to your computer and use it in GitHub Desktop.
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
/* toHandler function | |
* returns a handler with cross browser preventDefault and cancelPropagation options | |
* @func : function called with eventObject and the handler itself | |
* @preventDefault : boolean | |
* @cancelPropagation : boolean | |
*/ | |
function toHandler(func, preventDefault, cancelPropagation){ | |
var cache; | |
return cache = function(object){ | |
func.call(this, object, cache); | |
if(window.addEventListener !== undefined) { | |
if(preventDefault) object.preventDefault(); | |
if(cancelPropagation) object.stopPropagation(); | |
} else { | |
if(cancelPropagation) object.cancelBubble = true; | |
if(preventDefault) return false | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment