-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransitioncontroller.coffee
executable file
·48 lines (38 loc) · 1.47 KB
/
transitioncontroller.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
# TRANSITIONDELEGATE
# ==========
# Transition is CSS3 Transition engine with jQuery fallback.
"use strict"
effects = Namespace("SEQ.effects")
class effects.TransitionController
constructor:(@options) ->
@transitionEndStr = effects.Transition.TransitionEndNames[effects.Transition.GetProp('Transition')]
@numTransitions = 0
@numTransitionsComplete = 0
elements = []
# if jQuery object
if @options.target instanceof jQuery
for element, i in @options.target
elements.push(@options.target.get(i))
# if an Array
else if @options.target.constructor is Array
elements = @options.target
# otherwise target was a HTMLElement in the first place
else
elements = [@options.target]
@transition(elements)
transition: (elements) =>
for element in elements
# iterate over each CSS property and apply to HTMLElement
for prop, value of @options.props
@numTransitions++
if @options.duration > 0
element.addEventListener(@transitionEndStr, @onTransitionEnd, false)
else
@onTransitionEnd(target: element)
new effects.TransitionDelegate(element, prop, value, @options.duration)
onTransitionEnd: (e) =>
e.target.removeEventListener(@transitionEndStr, @onTransitionEnd, false)
@numTransitionsComplete++
if @numTransitionsComplete is @numTransitions
if @options.complete?
@options.complete.call(@)