Added rxjs in packege.json; Added activateOnInputEvents proprierty for listen the events in input element and resize when it occurs

This commit is contained in:
Lorenzo Iovino 2017-05-19 13:17:30 +02:00
parent 9dc59fd560
commit c76d6dbb1a
2 changed files with 14 additions and 4 deletions

View file

@ -28,7 +28,8 @@
},
"homepage": "https://github.com/lokenxo/ng2-fittext#readme",
"dependencies": {
"@angular/core": "^4.0.1"
"@angular/core": "^4.0.1",
"rxjs": "^5.4.0"
},
"devDependencies": {
"typescript": "~2.2.2"

View file

@ -8,6 +8,7 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit {
@Input('fittext') fittext: any;
@Input('container') container: any;
@Input('activateOnResize') activateOnResize: boolean;
@Input('activateOnInputEvents') activateOnInputEvents: boolean;
private fontSize: number = 0;
private speed: number = 1.05;
@ -15,8 +16,8 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit {
}
setFontSize(fontSize) {
this.fontSize = fontSize;
return this.el.nativeElement.style.setProperty('font-size', (fontSize).toString()+'px');
this.fontSize = fontSize;
return this.el.nativeElement.style.setProperty('font-size', (fontSize).toString()+'px');
}
calculateFontSize(fontSize, speed){
@ -38,6 +39,14 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit {
}
}
@HostListener('input', ['$event'])
onInputEvents() {
if(this.activateOnInputEvents && this.fittext) {
this.setFontSize(this.container.clientHeight);
this.ngAfterViewInit();
}
}
ngOnInit() {
if (this.fittext) {
this.setFontSize(this.container.clientWidth);