animate.js.coffee 1013 Bytes
Newer Older
1
((w) -> 
2 3
  if not w.gl? then w.gl = {}
  if not gl.animate? then gl.animate = {}
4

5 6 7
  gl.animate.animate = ($el, animation, options, done) ->
    if options?.cssStart?
      $el.css(options.cssStart)
8
    $el
9
      .removeClass(animation + ' animated')
10 11
      .addClass(animation + ' animated')
      .one 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', ->
12 13 14 15 16
        $(this).removeClass(animation + ' animated')
        if done?
          done()
        if options?.cssEnd?
          $el.css(options.cssEnd)
17 18 19
        return
    return

20 21
  gl.animate.animateEach = ($els, animation, time, options, done) ->
    dfd = $.Deferred()
22 23
    if not $els.length
      dfd.resolve()
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
    $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 
39
) window