Last active
December 20, 2015 10:19
-
-
Save halan/6114406 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CarouselCollection extends Backbone.Collection | |
initialize: -> | |
@currentIndex = 0 | |
@step = 1 | |
current: (value = null)-> | |
@changeIndex @indexOf(value) if value | |
@at @currentIndex | |
changeIndex: (newIndex)-> | |
@currentIndex = newIndex | |
@trigger 'current:changed' | |
newIndex | |
isFirst: -> | |
@current() == @first() | |
isLast: -> | |
@current() == @last() | |
next: -> | |
@nextOrFirstIndex() | |
@trigger 'current:next' | |
@current() | |
prev: -> | |
@prevOrLastIndex() | |
@trigger 'current:prev' | |
@current() | |
nextOrFirstIndex: -> | |
if @isLast() then @_goToFirst() else @_step() | |
prevOrLastIndex: -> | |
if @isFirst() then @_goToLast() else @_step -1 | |
_goToLast: -> | |
@changeIndex @indexOf(@last()) | |
@trigger 'current:prev:loop' | |
_goToFirst: -> | |
@changeIndex 0 | |
@trigger 'current:next:loop' | |
_step: (factor = 1)-> | |
@changeIndex @currentIndex + (@step * factor) |
Tem razão!
fixed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Na linha 2 tu ta pondo a propriedade no prototype.