Why not just use `transitionendEvent` variable defined as follows:
```javascript
var transitionendEvent = window.ontransitionend !== undefined ?
    'transitionend' :
    window.onwebkittransitionend !== undefined ? 'webkitTransitionEnd' : undefined;
```
similarly with `animationend`? All the detection would be in one place, it would eliminate further duplication.