forked from selvagsz/ember-carousel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
selvaganesh.b
committed
Jul 29, 2015
1 parent
bad64e1
commit afb0532
Showing
13 changed files
with
88 additions
and
139 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,80 @@ | ||
import Ember from 'ember'; | ||
import layout from '../templates/components/carousel-container'; | ||
|
||
const { on } = Ember; | ||
const { computed, on, run } = Ember; | ||
|
||
export default Ember.Component.extend({ | ||
layout: layout, | ||
carousel: Ember.inject.service(), | ||
classNames: ['carousel-container'], | ||
|
||
// Initialize the `service:carousel` with the carousel items | ||
isCarouselParentContainer: true, | ||
|
||
carouselItems: null, | ||
totalCarouselItems: computed.reads('carouselItems.length'), | ||
|
||
initializeCarouselItems: on('init', function() { | ||
this.set('carousel.carouselItems', Ember.A()); | ||
this.set('carouselItems', Ember.A()); | ||
}), | ||
|
||
activeCarouselItem: computed('carouselItems.length', 'carouselItems.@each.isActive', { | ||
get() { | ||
return this.get('carouselItems').findBy('isActive'); | ||
} | ||
}), | ||
|
||
resetCarousel: on('willDestroyElement', function() { | ||
this.initializeCarouselItems(); | ||
}) | ||
registerCarouselItem(carouselItem) { | ||
this.get('carouselItems').pushObject(carouselItem); | ||
}, | ||
|
||
slide(newActiveIndex, direction) { | ||
var carouselItems = this.get('carouselItems'); | ||
var activeCarouselItem = this.get('activeCarouselItem'); | ||
var newActiveCarouselItem = carouselItems[newActiveIndex]; | ||
|
||
run(function() { | ||
activeCarouselItem.set('from', direction); | ||
newActiveCarouselItem.set('from', direction); | ||
}); | ||
|
||
run.later(function() { | ||
activeCarouselItem.set('slidingOut', true); | ||
newActiveCarouselItem.set('slidingIn', true); | ||
}, 50); | ||
|
||
run.later(function() { | ||
activeCarouselItem.setProperties({ | ||
slidingOut: false, | ||
from: null, | ||
isActive: false | ||
}); | ||
|
||
newActiveCarouselItem.setProperties({ | ||
slidingIn: false, | ||
from: null, | ||
isActive: true | ||
}); | ||
}, 550); | ||
}, | ||
|
||
slideRight() { | ||
var activeIndex = this.get('activeCarouselItem.index'); | ||
let newActiveIndex = activeIndex - 1; | ||
|
||
if(activeIndex === 0) { | ||
newActiveIndex = this.get('totalCarouselItems') - 1; | ||
} | ||
|
||
this.slide(newActiveIndex, 'right'); | ||
}, | ||
|
||
slideLeft() { | ||
var activeIndex = this.get('activeCarouselItem.index'); | ||
let newActiveIndex = activeIndex + 1; | ||
|
||
if(activeIndex === (this.get('totalCarouselItems') - 1)) { | ||
newActiveIndex = 0; | ||
} | ||
|
||
this.slide(newActiveIndex, 'left'); | ||
} | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.