summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/lib/utils/animate.js.coffee
blob: ec3b44d61263374ce7e5d8b5f01535cd0afbc3bd (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
((w) -> 
  if not w.gl? then w.gl = {}
  if not gl.animate? then gl.animate = {}

  gl.animate.animate = ($el, animation, options, done) ->
    if options?.cssStart?
      $el.css(options.cssStart)
    $el
      .removeClass(animation + ' animated')
      .addClass(animation + ' animated')
      .one 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', ->
        $(this).removeClass(animation + ' animated')
        if done?
          done()
        if options?.cssEnd?
          $el.css(options.cssEnd)
        return
    return

  gl.animate.animateEach = ($els, animation, time, options, done) ->
    dfd = $.Deferred()
    if not $els.length
      dfd.resolve()
    $els.each((i) ->
      setTimeout(=>
        $this = $(@)
        gl.animate.animate($this, animation, options, =>
          if i is $els.length - 1
            dfd.resolve()
            if done?
              done()
        )
      ,time * i
      )
      return
    )
    return dfd.promise()
  return 
) window