From 76d65584fe9a667a4c6cef3415b50e523ee21427 Mon Sep 17 00:00:00 2001 From: Przemyslaw Olszewski Date: Thu, 27 Oct 2016 00:14:29 +0200 Subject: [PATCH 1/8] One active slide which is changed via model - outside carouselComponent. --- src/carousel/carousel.component.ts | 39 ++++++++++++------------------ src/carousel/slide.component.ts | 20 ++++++--------- 2 files changed, 22 insertions(+), 37 deletions(-) diff --git a/src/carousel/carousel.component.ts b/src/carousel/carousel.component.ts index c9999722bf..baab643280 100644 --- a/src/carousel/carousel.component.ts +++ b/src/carousel/carousel.component.ts @@ -31,11 +31,11 @@ export enum Direction {UNKNOWN, NEXT, PREV}
  • - + Previous - + Next @@ -69,7 +69,8 @@ export class CarouselComponent implements OnDestroy { protected isPlaying:boolean; protected destroyed:boolean = false; protected currentSlide:SlideComponent; - protected _interval:number; + protected _interval:number = 5000; + private _lastAddedSlide:SlideComponent; public get isBs4():boolean { return !isBs3(); @@ -79,14 +80,9 @@ export class CarouselComponent implements OnDestroy { this.destroyed = true; } - public select(nextSlide:SlideComponent, direction:Direction = Direction.UNKNOWN):void { + public select(nextSlide: SlideComponent):void { let nextIndex = nextSlide.index; - if (direction === Direction.UNKNOWN) { - direction = nextIndex > this.getCurrentIndex() - ? Direction.NEXT - : Direction.PREV; - } - + let direction = nextIndex > this.getCurrentIndex() ? Direction.NEXT : Direction.PREV; // Prevent this user-triggered transition from occurring if there is // already one in progress if (nextSlide && nextSlide !== this.currentSlide) { @@ -116,7 +112,7 @@ export class CarouselComponent implements OnDestroy { return; } - return this.select(this.getSlideByIndex(newIndex), Direction.NEXT); + return this.select(this.getSlideByIndex(newIndex)); } public prev():any { @@ -129,20 +125,21 @@ export class CarouselComponent implements OnDestroy { return; } - return this.select(this.getSlideByIndex(newIndex), Direction.PREV); + return this.select(this.getSlideByIndex(newIndex)); } public addSlide(slide:SlideComponent):void { slide.index = this.slides.length; this.slides.push(slide); if (this.slides.length === 1 || slide.active) { - this.select(this.slides[this.slides.length - 1]); - if (this.slides.length === 1) { - this.play(); - } - } else { - slide.active = false; + this.select(slide); + this.play(); + } + slide.previousSiblingSlide = this._lastAddedSlide; + if (this._lastAddedSlide) { + this._lastAddedSlide.nextSiblingSlide = slide; } + this._lastAddedSlide = slide; } public removeSlide(slide:SlideComponent):void { @@ -165,12 +162,6 @@ export class CarouselComponent implements OnDestroy { slide.direction = direction; slide.active = true; - - if (this.currentSlide) { - this.currentSlide.direction = direction; - this.currentSlide.active = false; - } - this.currentSlide = slide; // every time you change slides, reset the timer diff --git a/src/carousel/slide.component.ts b/src/carousel/slide.component.ts index b4cf0a146b..acf8d6fe42 100644 --- a/src/carousel/slide.component.ts +++ b/src/carousel/slide.component.ts @@ -1,13 +1,7 @@ -/*** - * todo: - * direction (?string) (not yet supported) - actual (not yet supported) (?any) - will be bind to slider context, to be used from template - */ -import { Component, HostBinding, Input, OnDestroy, OnInit } from '@angular/core'; +import { Component, HostBinding, OnDestroy, Input, OnInit } from '@angular/core'; -import { CarouselComponent, Direction } from './carousel.component'; +import { CarouselComponent } from './carousel.component'; -/** Wrap your content with `slide` component */ @Component({ selector: 'slide', template: ` @@ -17,28 +11,28 @@ import { CarouselComponent, Direction } from './carousel.component'; ` }) export class SlideComponent implements OnInit, OnDestroy { - /** index of slide in carousel's slides */ - @Input() public index:number; - @Input() public direction:Direction; - - /** does current slide is active */ + /** Specified slide as currently displayed */ @HostBinding('class.active') @Input() public active:boolean; + /** Wraps element by appropriate CSS classes */ @HostBinding('class.item') @HostBinding('class.carousel-item') public addClass:boolean = true; + /** Link to Parent(container-collection) component */ protected carousel:CarouselComponent; public constructor(carousel:CarouselComponent) { this.carousel = carousel; } + /** Fires changes in container collection after adding a new slide instance */ public ngOnInit():void { this.carousel.addSlide(this); } + /** Fires changes in container collection after removing of this slide instance */ public ngOnDestroy():void { this.carousel.removeSlide(this); } From 35102e67404ac446a3491298555f4ea702d2a62c Mon Sep 17 00:00:00 2001 From: "oleg.rybnikov" Date: Tue, 13 Dec 2016 14:41:57 +0200 Subject: [PATCH 2/8] feat(carousel): Changed data structure to linked list. --- .../demos/carousel-demo.component.html | 16 +- .../carousel/demos/carousel-demo.component.ts | 10 +- src/carousel/carousel.component.ts | 184 +++++++------ src/carousel/carousel.config.ts | 8 + src/carousel/carousel.module.ts | 4 +- src/carousel/index.ts | 1 + src/spec/carousel.component.spec.ts | 12 +- .../ng-bootstrap/utils/linkedlist.spec.ts | 159 +++++++++++ src/utils/linked-list.class.ts | 258 ++++++++++++++++++ 9 files changed, 552 insertions(+), 100 deletions(-) create mode 100644 src/carousel/carousel.config.ts create mode 100644 src/spec/ng-bootstrap/utils/linkedlist.spec.ts create mode 100644 src/utils/linked-list.class.ts diff --git a/demo/src/app/components/carousel/demos/carousel-demo.component.html b/demo/src/app/components/carousel/demos/carousel-demo.component.html index 977637c912..ea71e9ce52 100644 --- a/demo/src/app/components/carousel/demos/carousel-demo.component.html +++ b/demo/src/app/components/carousel/demos/carousel-demo.component.html @@ -1,8 +1,7 @@
    - - + +