Skip to content

Commit

Permalink
Merge pull request #11 from brewster1134/animation_boolean
Browse files Browse the repository at this point in the history
animation boolean
  • Loading branch information
brewster1134 committed May 5, 2016
2 parents 03fc069 + a1067ec commit e3d22d5
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#### CHANGE LOG

###### 1.0.4
* allow passing a boolean for `goTo` method's animation argument

###### 1.0.3
* improved sizing of viewport

Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GEM
remote: https://rubygems.org/
specs:
sass (3.4.19)
sass (3.4.22)

PLATFORMS
ruby
Expand All @@ -10,4 +10,4 @@ DEPENDENCIES
sass (~> 3.4)

BUNDLED WITH
1.10.6
1.12.1
2 changes: 1 addition & 1 deletion Newfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
sources:
default: ~/Code/ruby/new-tasks
name: Tiler
version: 1.0.1
version: 1.0.4
tasks:
changelog:
git:
Expand Down
20 changes: 16 additions & 4 deletions lib/tiler.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions spec/tiler_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,25 @@ describe 'Tiler', ->
it 'should add the active class', ->
expect($('#go-to #tile-1').hasClass('foo-animation')).to.be.true

context 'when passing a boolean to active class', ->
before ->
$('#tile-1', '#go-to').data 'tiler-animation', 'goto-animate-1'
$('#tile-2', '#go-to').data 'tiler-animation', 'goto-animate-2'

context 'when passing true', ->
before ->
$('#go-to').tiler('goTo', 2, true)

it 'should add the active class from the first tile', ->
expect($('#go-to #tile-2').hasClass('goto-animate-2')).to.be.true

context 'when passing false', ->
before ->
$('#go-to').tiler('goTo', 1, false)

it 'should add the active class', ->
expect($('#go-to #tile-1').hasClass('no-active-class')).to.be.true

describe 'refresh', ->
newWidth = null
newHeight = null
Expand Down
22 changes: 13 additions & 9 deletions src/tiler.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# * tiler
# * https://github.com/brewster1134/tiler
# *
# * @version 1.0.3
# * @version 1.0.4
# * @author Ryan Brewster
# * Copyright (c) 2014
# * Licensed under the MIT license.
Expand Down Expand Up @@ -45,7 +45,7 @@
@element.trigger 'tiler.refresh'
@$enterTile?.trigger 'tiler.refresh'

goTo: (tile, animation) ->
goTo: (tile, animation = true) ->
# Find tile
# Tile id as string
$tile = if typeof tile == 'string'
Expand All @@ -70,14 +70,8 @@
# Set the active tile id to the viewport
@element.attr 'data-tiler-active-tile', @$enterTile.attr('id')

# Set tile class
animationClass = if animation == false
'no-active-class'
else
animation || @$enterTile.data('tiler-animation') || ''

# Manage css classes if an one is specified
@_transitionCss animationClass
@_transitionCss @_getAnimationClass animation

# Fire js events
# Trigger on viewport
Expand All @@ -97,6 +91,16 @@
#
# PRIVATE METHODS
#
_getAnimationClass: (animation) ->
# return explicitly passed animation
return animation if typeof animation == 'string'

# use animaton from markup if true, and no-active-class for false
if animation
@$enterTile.data('tiler-animation') || ''
else
'no-active-class'

_transitionCss: (animationClass) ->
enterTileId = @$tiles.index(@$enterTile, @$exitTile) + 1

Expand Down

0 comments on commit e3d22d5

Please sign in to comment.