Skip to content

Commit

Permalink
updated to fix universal support
Browse files Browse the repository at this point in the history
  • Loading branch information
codeveins committed Nov 28, 2017
1 parent 31ace6a commit e006f6b
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngu-carousel",
"version": "0.1.0",
"version": "1.3.4",
"description": "Angular Universal carousel",
"scripts": {
"transpile": "ngc ",
Expand Down
9 changes: 1 addition & 8 deletions src/ngu-carousel.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ import { CommonModule } from '@angular/common';
import { NguCarouselComponent } from './ngu-carousel/ngu-carousel.component';
import { NguTileComponent } from './ngu-tile/ngu-tile.component';

export class MyHammerConfig extends HammerGestureConfig {
overrides = <any>{
swipe: { velocity: 0.4, threshold: 20 }, // override default settings
pan: { velocity: 0.4, threshold: 20 }
};
}

@NgModule({
imports: [CommonModule],
exports: [
Expand All @@ -36,6 +29,6 @@ export class MyHammerConfig extends HammerGestureConfig {
NguCarouselNextDirective,
NguCarouselPrevDirective
],
providers: [{ provide: HAMMER_GESTURE_CONFIG, useClass: MyHammerConfig }]
providers: []
})
export class NguCarouselModule {}
74 changes: 67 additions & 7 deletions src/ngu-carousel/ngu-carousel.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,64 @@ import { Subscription } from 'rxjs/Subscription';
@Component({
// tslint:disable-next-line:component-selector
selector: 'ngu-carousel',
templateUrl: './ngu-carousel.component.html',
styleUrls: ['./ngu-carousel.component.scss']
template: `<div #ngucarousel class="ngucarousel"><div #forTouch class="ngucarousel-inner"><div #nguitems class="ngucarousel-items"><ng-content select="[NguCarouselItem]"></ng-content></div><div style="clear: both"></div></div><ng-content select="[NguCarouselPrev]"></ng-content><ng-content select="[NguCarouselNext]"></ng-content></div><div #points *ngIf="userData.point.visible"><ul class="ngucarouselPoint"><li #pointInner *ngFor="let i of pointNumbers; let i = index" [class.active]="i==pointers" (click)="moveTo(i)"></li></ul></div>`,
styles: [`
:host {
display: block;
position: relative;
}
.ngucarousel .ngucarousel-inner {
position: relative;
overflow: hidden;
}
.ngucarousel .ngucarousel-inner .ngucarousel-items {
white-space: nowrap;
position: relative;
}
.banner .ngucarouselPointDefault .ngucarouselPoint {
position: absolute;
width: 100%;
bottom: 20px;
}
.banner .ngucarouselPointDefault .ngucarouselPoint li {
background: rgba(255, 255, 255, 0.55);
}
.banner .ngucarouselPointDefault .ngucarouselPoint li.active {
background: white;
}
.banner .ngucarouselPointDefault .ngucarouselPoint li:hover {
cursor: pointer;
}
.ngucarouselPointDefault .ngucarouselPoint {
list-style-type: none;
text-align: center;
padding: 12px;
margin: 0;
white-space: nowrap;
overflow: auto;
box-sizing: border-box;
}
.ngucarouselPointDefault .ngucarouselPoint li {
display: inline-block;
border-radius: 50%;
background: rgba(0, 0, 0, 0.55);
padding: 4px;
margin: 0 4px;
transition-timing-function: cubic-bezier(0.17, 0.67, 0.83, 0.67);
transition: 0.4s;
}
.ngucarouselPointDefault .ngucarouselPoint li.active {
background: #6b6b6b;
transform: scale(1.8);
}
.ngucarouselPointDefault .ngucarouselPoint li:hover {
cursor: pointer;
}
`]
})
export class NguCarouselComponent
implements OnInit, AfterContentInit, AfterViewInit, OnDestroy, OnChanges {
Expand Down Expand Up @@ -62,7 +118,7 @@ export class NguCarouselComponent

@ViewChild('ngucarousel', { read: ElementRef })
private carouselMain1: ElementRef;
@ViewChild('ngxitems', { read: ElementRef })
@ViewChild('nguitems', { read: ElementRef })
private carouselInner1: ElementRef;
@ViewChild('main', { read: ElementRef })
private carousel1: ElementRef;
Expand Down Expand Up @@ -122,7 +178,7 @@ export class NguCarouselComponent

ngOnChanges(changes: SimpleChanges) {
// tslint:disable-next-line:no-unused-expression
this.moveToSlide &&
this.moveToSlide > -1 &&
!changes.moveToSlide.firstChange &&
this.moveTo(changes.moveToSlide.currentValue);
}
Expand Down Expand Up @@ -173,7 +229,7 @@ export class NguCarouselComponent
this.buttonControl();
});
// tslint:disable-next-line:no-unused-expression
this.moveToSlide && this.moveTo(this.moveToSlide);
this.moveToSlide > -1 && this.moveTo(this.moveToSlide);
}

ngAfterViewInit() {
Expand Down Expand Up @@ -339,9 +395,13 @@ export class NguCarouselComponent
const Nos = this.items.length - (this.data.items - this.data.slideItems);
this.pointIndex = Math.ceil(Nos / this.data.slideItems);
const pointers = [];
for (let i = 0; i < this.pointIndex; i++) {
pointers.push(i);

if (this.pointIndex > 1 || !this.userData.point.hideOnSingleSlide) {
for (let i = 0; i < this.pointIndex; i++) {
pointers.push(i);
}
}

this.pointNumbers = pointers;
this.carouselPointActiver();
if (this.pointIndex <= 1) {
Expand Down
1 change: 1 addition & 0 deletions src/ngu-carousel/ngu-carousel.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export type Animate = 'lazy';
export interface Point {
visible: boolean;
pointStyles?: string;
hideOnSingleSlide?: boolean;
}

export interface Animation {
Expand Down
10 changes: 8 additions & 2 deletions src/ngu-item/ngu-item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ import { Component, HostBinding } from '@angular/core';

@Component({
selector: 'ngu-item',
templateUrl: './ngu-item.component.html',
styleUrls: ['./ngu-item.component.scss']
template: `<ng-content></ng-content>`,
styles: [`
:host {
display: inline-block;
white-space: initial;
vertical-align: top;
}
`]
})
export class NguItemComponent {
@HostBinding('class') classes = 'item';
Expand Down
20 changes: 18 additions & 2 deletions src/ngu-tile/ngu-tile.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,24 @@ import { Component, HostBinding } from '@angular/core';

@Component({
selector: 'ngu-tile',
templateUrl: './ngu-tile.component.html',
styleUrls: ['./ngu-tile.component.scss']
template: `<div class="tile"><ng-content></ng-content></div>`,
styles: [`
:host {
display: inline-block;
white-space: initial;
padding: 10px;
box-sizing: border-box;
vertical-align: top;
}
.tile {
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
}
* {
box-sizing: border-box;
}
`]
})
export class NguTileComponent {
@HostBinding('class') classes = 'item';
Expand Down

0 comments on commit e006f6b

Please sign in to comment.