summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/lib/utils/animate.js
blob: 3ccaf05f7e9c97f333bff07ae5cf668e7bf6bd27 (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
43
44
45
46
(function(w) {
  if (w.gl == null) {
    w.gl = {};
  }
  if (gl.animate == null) {
    gl.animate = {};
  }
  gl.animate.animate = function($el, animation, options, done) {
    if ((options != null ? options.cssStart : void 0) != null) {
      $el.css(options.cssStart);
    }
    $el.removeClass(animation + ' animated').addClass(animation + ' animated').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function() {
      $(this).removeClass(animation + ' animated');
      if (done != null) {
        done();
      }
      if ((options != null ? options.cssEnd : void 0) != null) {
        $el.css(options.cssEnd);
      }
    });
  };
  gl.animate.animateEach = function($els, animation, time, options, done) {
    var dfd;
    dfd = $.Deferred();
    if (!$els.length) {
      dfd.resolve();
    }
    $els.each(function(i) {
      setTimeout((function(_this) {
        return function() {
          var $this;
          $this = $(_this);
          return gl.animate.animate($this, animation, options, function() {
            if (i === $els.length - 1) {
              dfd.resolve();
              if (done != null) {
                return done();
              }
            }
          });
        };
      })(this), time * i);
    });
    return dfd.promise();
  };
})(window);