Skip to content

Commit

Permalink
iteration sensation
Browse files Browse the repository at this point in the history
  • Loading branch information
dmotz committed Sep 15, 2013
1 parent 71ead1b commit 23a8e32
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions oridomi.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ class OriDomi
return fn() if @_lastOp.angle is 0
@_panels[@_lastOp.anchor][0].addEventListener css.transitionEnd, fn, false

for panel, i in @_panels[@_lastOp.anchor]
@_iterate @_lastOp.anchor, (panel, i) =>
panel.style[css.transform] = @_transform 0, @_lastOp.anchor
@_setShader i, @_lastOp.anchor, 0 if @_shading

Expand Down Expand Up @@ -736,7 +736,7 @@ class OriDomi
for eventPair in eventPairs
for eString in eventPair
unless eString is 'TouchLeave' and not mouseLeaveSupport
@stageHolder[listenFn] eString.toLowerCase(), @['_on' + eventPair[0]], false
@_stageHolder[listenFn] eString.toLowerCase(), @['_on' + eventPair[0]], false
else
@_stageHolder[listenFn] 'mouseout', @_onMouseOut, false
break
Expand Down Expand Up @@ -834,11 +834,9 @@ class OriDomi
_unfold: (callback) ->
return callback?() unless @isFoldedUp
@_inTrans = true
len = @_panels[anchor].length

for panel, i in @_panels[anchor]
delay = @_settings.speed / len * i
panel.style[css.transitionDelay] = delay + 'ms'
@_iterate @_lastOp.anchor, (panel, i, len) =>
delay = @_setPanelTrans arguments..., @_settings.speed, 2

do (panel, i, delay) =>
defer =>
Expand All @@ -853,6 +851,10 @@ class OriDomi
, delay + @_settings.speed * .25


_iterate: (anchor, fn) ->
fn.call @, panel, i, panels.length for panel, i in panels = @_panels[anchor]


# Public Methods
# ==============

Expand Down Expand Up @@ -944,7 +946,7 @@ class OriDomi
# oriDomi's most basic effect. Transforms the target like its namesake.
accordion: prep (angle, anchor, options) ->
# Loop through the panels in this stage.
for panel, i in @_panels[anchor]
@_iterate anchor, (panel, i) =>
# If it's an odd-numbered panel, reverse the angle.
if i % 2 isnt 0 and not options.twist
deg = -angle
Expand All @@ -970,44 +972,35 @@ class OriDomi
if @_shading and !(i is 0 and options.sticky) and Math.abs(deg) isnt 180
@_setShader i, anchor, deg

@


# `curl` appears to bend rather than fold the paper. Its curves can appear smoother
# with higher panel counts.
curl: prep (angle, anchor, options) ->
# Reduce the angle based on the number of panels in this axis.
angle /= if anchor in anchorListV then @_settings.vPanels else @_settings.hPanels

for panel, i in @_panels[anchor]
@_iterate anchor, (panel, i) =>
panel.style[css.transform] = @_transform angle, anchor
@_setShader i, anchor, 0 if @_shading

@


# `ramp` lifts up all panels after the first one.
ramp: prep (angle, anchor, options) ->
# Rotate the second panel for the lift up.
@_panels[anchor][1].style[css.transform] = @_transform angle, anchor

# For all but the first two panels, set the angle to 0.
for panel, i in @_panels[anchor]
@_iterate anchor, (panel, i) =>
@_panels[anchor][i].style[css.transform] = @_transform 0, anchor if i > 1
@_setShader i, anchor, 0 if @_shading

@


# Hides the element by folding each panel in a cascade of animations.
foldUp: prep (anchor, callback) ->
@_stageReset anchor, =>
return callback?() if @isFoldedUp
@_inTrans = @isFoldedUp = true
len = @_panels[anchor].length

for panel, i in @_panels[anchor]
delay = @_settings.speed / len * (len - i - 1)
panel.style[css.transitionDelay] = delay + 'ms'
panel.style[css.transitionDuration] = @_settings.speed / 2 + 'ms' if i is 0

Expand Down

0 comments on commit 23a8e32

Please sign in to comment.