Created
November 26, 2013 13:31
-
-
Save Geruhn/7658277 to your computer and use it in GitHub Desktop.
JavaScript: addAnimationListener (addEventListener on Animations with vendorprefixes)
This file contains hidden or 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
EventTarget.prototype.addAnimationListener = function(type, listener, useCapture, wantsUntrusted) { | |
//vendors[0][vendorIndex] = vendor-prefixes + vendors[1][vendorIndex] = vendorwrittenInCamelCase | |
//[[w3c, ff, webkit, Opera, IE],[...]] | |
var vendors = [['', '', 'webkit', 'o', 'MS'],[false, false, true, false, true]]; | |
var prefix = 'Animation'; | |
var animationTypes = ['Start', 'Iteration', 'End']; | |
var animationType = false; | |
for(var i = animationTypes.length - 1; (i >= 0) && !animationType; i--) { | |
animationType = (type.toLowerCase() === animationTypes[i].toLowerCase()) ? i : false; | |
} | |
if(animationType === false) { | |
console.log('Error: The AnimationType "' + type + '" doesn\'t exist!'); | |
return undefined; | |
} | |
animationType = prefix + animationTypes[animationType]; | |
for(var i = vendors[0].length - 1; i >= 0; i--) { | |
this.addEventListener(vendors[0][i] + (vendors[1][i] ? animationType : animationType.toLowerCase()), listener, useCapture, wantsUntrusted); | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment