Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Geruhn
Created November 26, 2013 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Geruhn/7658277 to your computer and use it in GitHub Desktop.
Save Geruhn/7658277 to your computer and use it in GitHub Desktop.
JavaScript: addAnimationListener (addEventListener on Animations with vendorprefixes)
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