Skip to content

Commit 4947189

Browse files
committed
2.0.2 WIP
1 parent f98d7e5 commit 4947189

File tree

2 files changed

+98
-69
lines changed

2 files changed

+98
-69
lines changed

lib/tiler.js

Lines changed: 47 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tiler.coffee

Lines changed: 51 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,21 @@
2727
widgetEventPrefix: 'tiler'
2828
options:
2929
isReversible: true
30+
startingActiveTile: 1
31+
startingPreviousTile: 2
3032

3133
_create: ->
32-
@currentTileIndex = null
34+
@currentActiveTileIndex = @options.startingActiveTile
35+
@currentPreviousTileIndex = @options.startingPreviousTile
3336

3437
_init: ->
38+
@element.addClass 'animation-disabled'
39+
3540
# Collect all the tiles, except for those nested inside another tiler instance
3641
@$tiles = $('.tiler-tile', @element).not(@element.find('.tiler-viewport .tiler-tile'))
42+
@$enterTile = @$tiles.eq @currentActiveTileIndex - 1
43+
@$exitTile = @$tiles.eq @currentPreviousTileIndex - 1
44+
3745
@_setupTiles()
3846
@_setupLinks()
3947

@@ -45,33 +53,35 @@
4553
@element.trigger 'tiler.refresh'
4654
@$enterTile?.trigger 'tiler.refresh'
4755

48-
goTo: (tile, animation = true) ->
49-
# Find tile
50-
# ...id as string
51-
$tile = if typeof tile == 'string'
52-
@$tiles.filter("##{tile}")
56+
# Find tile with various values
57+
#
58+
_getTile: (tileValue) ->
59+
# ...as a css ID (String)
60+
if typeof tileValue == 'string'
61+
$("##{tileValue}", @element)
5362

5463
# ...as jquery object
55-
else if tile?.jquery
56-
tile?.jquery
64+
else if tileValue.jquery
65+
tileValue.jquery
5766

5867
# ...as dom node
59-
else if tile.nodeType
60-
$(tile)
68+
else if tileValue.nodeType
69+
$(tileValue)
6170

6271
# ...as index (starting at 1)
6372
else
64-
@$tiles.eq tile - 1
73+
@$tiles.eq tileValue - 1
6574

66-
# Return if we are already on that tile
67-
tileIndex = @$tiles.index $tile
68-
return if !$tile.length || @currentTileIndex == tileIndex
75+
goTo: (tile, animation) ->
76+
# New active tile
77+
@$enterTile = @_getTile tile
78+
enterTileIndex = @$tiles.index @$enterTile
79+
@$exitTile = @_getTile @currentActiveTileIndex + 1
6980

70-
# Get animating tiles
71-
@$enterTile = $tile
72-
@$exitTile = @$tiles.eq @currentTileIndex
81+
# Return if we are already on that tile
82+
return if !@$enterTile.length || @currentActiveTileIndex == enterTileIndex
7383

74-
@_transitionCss @_getAnimationClass animation
84+
@_transitionCss @_getAnimationClass(), animation
7585

7686
# Fire js events
7787
# ...on viewport
@@ -84,25 +94,26 @@
8494
@$exitTile.trigger 'tiler.exit'
8595

8696
# Update the current tile id
87-
@currentTileIndex = tileIndex
97+
@currentActiveTileIndex = enterTileIndex
98+
@currentPreviousTileIndex = @currentActiveTileIndex
8899
@element.attr 'data-tiler-active-tile', @$enterTile.attr('id')
89100

90101
return @$enterTile
91102

92103
#
93104
# PRIVATE METHODS
94105
#
95-
_getAnimationClass: (animation) ->
96-
# return explicitly passed animation
97-
return animation if typeof animation == 'string'
106+
_getAnimationClass: ->
107+
@$enterTile.data('tiler-animation') || @element.data('tiler-animation') || ''
108+
109+
_transitionCss: (animationClass, animation) ->
110+
animationClass = animation if typeof animation == 'string'
98111

99-
# use animation from markup if true, and no-active-class for false
100-
if animation
101-
@$enterTile.data('tiler-animation') || @element.data('tiler-animation') || ''
112+
position = if animation == false
113+
'end'
102114
else
103-
''
115+
'start'
104116

105-
_transitionCss: (animationClass) ->
106117
enterTileIndex = @$tiles.index @$enterTile
107118

108119
# Add reverse class if supported and navigating in reverse order (according to the dom)
@@ -115,8 +126,8 @@
115126
@element.addClass 'animation-disabled'
116127

117128
# Build tile starting position animations classes
118-
enterStartClass = "tiler-tile #{animationClass} active enter #{reverseClass} start"
119-
exitStartClass = "tiler-tile #{animationClass} previous exit #{reverseClass} start"
129+
enterStartClass = "tiler-tile #{animationClass} active enter #{reverseClass} #{position}"
130+
exitStartClass = "tiler-tile #{animationClass} previous exit #{reverseClass} #{position}"
120131
otherTileClass = 'tiler-tile'
121132

122133
# Set tile classes
@@ -125,13 +136,14 @@
125136
@$tiles.not(@$enterTile).not(@$exitTile).attr 'class', otherTileClass
126137

127138
# setTimeout needed to give the browser time to repaint the tiles (if neccessary) with the animation starting position
128-
setTimeout =>
129-
# Enable transitions
130-
@element.removeClass 'animation-disabled'
139+
unless animation == false
140+
setTimeout =>
141+
# Enable transitions
142+
@element.removeClass 'animation-disabled'
131143

132-
# Replace position classes to trigger animation
133-
@$enterTile.add(@$exitTile).switchClass 'start', 'end'
134-
, 10
144+
# Replace position classes to trigger animation
145+
@$enterTile.add(@$exitTile).switchClass 'start', 'end'
146+
, 10
135147

136148
# Find possible links throughout the entire page and set meta data on them
137149
#
@@ -164,6 +176,9 @@
164176
# Add a data attribute with the viewport id
165177
$(@).attr 'data-tiler-viewport-id', self.element.attr('id')
166178

179+
# Add animation class
180+
$(@).addClass self._getAnimationClass(true)
181+
167182
# Set sizes
168183
@element.add(@$tiles).css
169184
width: @element.outerWidth()
@@ -172,4 +187,4 @@
172187
# Determine if we are advancing or retreating through our virtual tiles
173188
#
174189
_isNavigatingForward: (enterTileIndex) ->
175-
enterTileIndex > @currentTileIndex
190+
enterTileIndex > @currentActiveTileIndex

0 commit comments

Comments
 (0)