summaryrefslogtreecommitdiffstats
path: root/client/lib/cssEvents.js
blob: 1cf6b8e8f1279884499674dfdfa7cae060457622 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// XXX Should we use something like Moderniz instead of our custom detector?

function whichTransitionEvent() {
  const el = document.createElement('fakeelement');
  const transitions = {
    transition: 'transitionend',
    OTransition: 'oTransitionEnd',
    MSTransition: 'msTransitionEnd',
    MozTransition: 'transitionend',
    WebkitTransition: 'webkitTransitionEnd',
  };

  for (const t in transitions) {
    if (el.style[t] !== undefined) {
      return transitions[t];
    }
  }
  return null;
}

function whichAnimationEvent() {
  const el = document.createElement('fakeelement');
  const transitions = {
    animation: 'animationend',
    OAnimation: 'oAnimationEnd',
    MSTransition: 'msAnimationEnd',
    MozAnimation: 'animationend',
    WebkitAnimation: 'webkitAnimationEnd',
  };

  for (const t in transitions) {
    if (el.style[t] !== undefined) {
      return transitions[t];
    }
  }
  return null;
}

CSSEvents = {
  transitionend: whichTransitionEvent(),
  animationend: whichAnimationEvent(),
};