Ref: clean code
Ref: update examples
This commit is contained in:
parent
43d4cf66f4
commit
ca1576015d
6 changed files with 196 additions and 198 deletions
|
|
@ -1,4 +1,4 @@
|
|||
<h2>Add text or remove text from div</h2>
|
||||
<h2>Add text or remove text from div (max and min font size)</h2>
|
||||
<div style="border: 2px solid; overflow:hidden; width:100%; height:300px; font-size:520px;">
|
||||
<div [fittext]="true"
|
||||
[modelToWatch]="title"
|
||||
|
|
@ -7,8 +7,17 @@
|
|||
[activateOnResize]="true">{{title}}</div>
|
||||
</div>
|
||||
|
||||
|
||||
<h2>Add text or remove text from div (no max and no min font size)</h2>
|
||||
<div style="border: 2px solid; overflow:hidden; width:100%; height:300px; font-size:520px;">
|
||||
<div [fittext]="true"
|
||||
[modelToWatch]="title"
|
||||
[activateOnResize]="true">{{title}}</div>
|
||||
</div>
|
||||
|
||||
<button (click)="click('add')"> ADD text</button>
|
||||
<button (click)="click('remove')"> REMOVE text</button>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
<h2>Write text in input box (text fit inside without overflowing)</h2>
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges, Af
|
|||
setFontSize(fontSize: number) {
|
||||
if (this.isVisible() && !this.done) {
|
||||
if (fontSize < this.minFontSize) {
|
||||
// force that font size will never be lower than minimal allowed font size
|
||||
fontSize = this.minFontSize;
|
||||
}
|
||||
if(fontSize > this.maxFontSize){
|
||||
|
|
@ -44,7 +43,6 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges, Af
|
|||
}
|
||||
|
||||
calculateFontSize(fontSize: number, speed: number) {
|
||||
// TODO Do with Gauss
|
||||
return Math.floor(fontSize / speed);
|
||||
}
|
||||
|
||||
|
|
@ -79,14 +77,6 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges, Af
|
|||
|
||||
ngOnInit() {
|
||||
this.done = false;
|
||||
const fontSize = this.getComputetStyle().fontSize;
|
||||
if (fontSize) {
|
||||
this.maxFontSize = parseInt(fontSize, undefined);
|
||||
}
|
||||
if (this.fittext) {
|
||||
this.setFontSize(this.maxFontSize);
|
||||
}
|
||||
|
||||
this.el.nativeElement.style.setProperty('will-change', 'content');
|
||||
this.ngAfterViewInit();
|
||||
}
|
||||
|
|
@ -103,13 +93,6 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges, Af
|
|||
this.ngAfterViewInit();
|
||||
}
|
||||
} else {
|
||||
if (this.fontSize > this.maxFontSize) {
|
||||
const fontSize = this.getComputetStyle().fontSize;
|
||||
if (fontSize) {
|
||||
this.maxFontSize = parseInt(fontSize, undefined);
|
||||
this.setFontSize(this.maxFontSize);
|
||||
}
|
||||
}
|
||||
this.done = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -134,10 +117,6 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges, Af
|
|||
}
|
||||
}
|
||||
|
||||
private getComputetStyle(): CSSStyleDeclaration {
|
||||
return window.getComputedStyle(this.container ? this.container : this.el.nativeElement.parentElement);
|
||||
}
|
||||
|
||||
private getStartFontSizeFromHeight(): number {
|
||||
return this.container ? this.container.clientHeight : this.el.nativeElement.parentElement.clientHeight;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue