Skip to content

Instantly share code, notes, and snippets.

@hbrysiewicz
Created January 9, 2014 19:55
Show Gist options
  • Save hbrysiewicz/8340824 to your computer and use it in GitHub Desktop.
Save hbrysiewicz/8340824 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Content Carousel" />
<meta charset="utf-8">
<title>Ember Starter Kit</title>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/normalize/2.1.0/normalize.css">
</head>
<body>
<script type="text/x-handlebars">
<h2>Welcome to Ember.js</h2>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="index">
{{view App.ComponentContainer}}
</script>
<script type="text/x-handlebars" data-template-name="apple">
Apple
</script>
<script type="text/x-handlebars" data-template-name="banana">
Banana
</script>
<script type="text/x-handlebars" data-template-name="cantelope">
Cantelope
</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v1.2.1.js"></script>
<script src="http://builds.emberjs.com/tags/v1.3.0/ember.js"></script>
</body>
</html>
App = Ember.Application.create();
App.ComponentView = Ember.Component.extend({
contentIndex: function() {
return this.get('parentView.childViews').indexOf(this);
}.property('parentView.childViews'),
isVisible: function() {
return this.get('parentView.currentIndex') === this.get('contentIndex');
}.property('parentView.currentIndex','contentIndex')
});
App.ComponentContainer = Ember.ContainerView.extend({
currentIndex: 0,
transitionInterval: 6000,
childViews: [
App.ComponentView.create({
templateName: 'apple'
}),
App.ComponentView.create({
templateName: 'banana'
}),
App.ComponentView.create({
templateName: 'cantelope'
})
],
childLength: function() {
return this.get('childViews.length');
}.property('childViews'),
didInsertElement: function() {
var _this = this;
setInterval(function() {
var nextIndex = _this.get('currentIndex') + 1;
if (nextIndex === _this.get('childLength')) nextIndex = 0;
_this.set('currentIndex', nextIndex);
}, _this.get('transitionInterval'));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment