// Rather than having to pass data via a components heirarchy // (passing data from the parents to children) we initialise an empty // vue component that allows us access to the event system when needed. var $eventBus = new Vue(); // Home Slider Component Vue.component('home-slider', { template: '
', data: function() { return { // The current slide to be shown... activeSlide: 0, interval: null, } }, // Called after the instance has been mounted... mounted: function() { var $this = this; $this.nextSlide(); $this.interval = setInterval(function() { $this.nextSlide(); }, 4000); $eventBus.$on('activeSlide', function (activeSlide) { $this.activeSlide = activeSlide; }); $eventBus.$on('clickSlide', function (activeSlide) { $this.reInitInterval(); $eventBus.$emit('activeSlide', activeSlide); }); }, // Essentially variables that can hold logic... computed: { slideCount: function() { return $('.home-slide').length; } }, methods: { nextSlide: function() { if(this.activeSlide == this.slideCount) { this.activeSlide = 1; } else { this.activeSlide++; } $eventBus.$emit('activeSlide', this.activeSlide); }, reInitInterval: function() { var $this = this; clearInterval($this.interval); $this.interval = setInterval(function() { $this.nextSlide(); }, 4000); } } }); // Home Slide Component Vue.component('home-slide', { template: ' ', props: ['id', 'image', 'imageAlt'], data: function() { return { activeSlide: 0 } }, mounted: function() { var $this = this; $eventBus.$on('activeSlide', function (activeSlide) { $this.activeSlide = activeSlide; }); } }); // Home Slide Button Component Vue.component('home-slide-button', { template: ' ', props: ['id', 'title', 'text'], data: function() { return { activeSlide: 0 } }, computed: { active: function() { return this.activeSlide == this.id; } }, mounted: function() { var $this = this; $eventBus.$on('activeSlide', function (activeSlide) { $this.activeSlide = activeSlide; }); }, methods: { handleClick: function() { if(this.activeSlide != this.id) { $eventBus.$emit('clickSlide', this.id); } } } }); Vue.component('progress-bar', { props: ['activeSlide', 'id'], watch: { activeSlide: function() { if(this.activeSlide == this.id) { $(this.$refs.bar).stop().animate({ width: '0%' }, 0); $(this.$refs.bar).stop().animate({ width: '100%' }, 4000); } else if(this.activeSlide > this.id) { $(this.$refs.bar).stop().animate({ width: '100%' }, 0); } else { $(this.$refs.bar).stop().animate({ width: '0%' }, 0); } } }, template: '