-
Notifications
You must be signed in to change notification settings - Fork 0
/
transition.coffee
executable file
·68 lines (57 loc) · 1.79 KB
/
transition.coffee
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# TRANSITION
# ==========
# Transition is a CSS3 Transition API with jQuery fallback.
"use strict"
effects = Namespace("SEQ.effects")
# class of static helper properties/methods
class effects.Transition
# list of transitionEnd event names
@TransitionEndNames =
WebkitTransition: 'webkitTransitionEnd'
MozTransition: 'transitionend'
OTransition: 'oTransitionEnd'
msTransition: 'msTransitionEnd'
transition: 'transitionEnd'
# utility function for getting vendor-prefixed property
@GetProp = (prop) ->
for prefix in ["", "Webkit", "Moz", "O", "ms", "Khtml"]
p = "#{prefix}#{prop}"
return p if document.body.style[p]?
@To: (options) =>
# apply delay, if present
t = setTimeout =>
# if browser supports CSS3 Transitions
if effects.Transition.GetProp("Transition")?
# start the magic
new effects.TransitionController(options)
else
# rock it old-skool
@jqAnimate(options)
clearTimeout(t)
, options.delay or 0
@jqAnimate: (options) =>
# if jQuery object
if options.target instanceof jQuery
# use that
target = options.target
else
# create one
target = $(options.target)
# patch opacity transitions with fadein/out
if options.props.opacity?
if options.props.opacity is 0
target.fadeOut(options.duration, options.complete)
if options.props.opacity is 1
target.fadeIn(options.duration, options.complete)
# remove opacity from property queue
delete options.opacity
# pass user options unti jQuery animation API
target.animate(
options.props
,
duration: options.duration
complete: (e) =>
# if opacity
if options.complete?
options.complete.call(@)
)