ref: Formatted code using Prettier rules
This commit is contained in:
parent
1badcaf080
commit
1c902e2d90
3 changed files with 133 additions and 128 deletions
2
package-lock.json
generated
2
package-lock.json
generated
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "ng2-fittext",
|
||||
"version": "1.2.9",
|
||||
"version": "1.2.10",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
|
|
|||
|
|
@ -2,20 +2,21 @@ import {
|
|||
AfterViewChecked,
|
||||
AfterViewInit,
|
||||
Directive,
|
||||
ElementRef, HostListener,
|
||||
ElementRef,
|
||||
HostListener,
|
||||
Input,
|
||||
Output,
|
||||
EventEmitter,
|
||||
OnChanges,
|
||||
OnInit,
|
||||
Renderer2
|
||||
Renderer2,
|
||||
} from '@angular/core';
|
||||
|
||||
@Directive({
|
||||
selector: '[fittext]'
|
||||
selector: '[fittext]',
|
||||
})
|
||||
export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges, AfterViewChecked {
|
||||
|
||||
export class Ng2FittextDirective
|
||||
implements AfterViewInit, OnInit, OnChanges, AfterViewChecked {
|
||||
@Input('fittext') fittext: any;
|
||||
@Input('activateOnResize') activateOnResize: boolean;
|
||||
@Input('container') container: HTMLElement;
|
||||
|
|
@ -34,8 +35,7 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges, Af
|
|||
private speed = 1.05;
|
||||
private done = false;
|
||||
|
||||
constructor(public el: ElementRef,
|
||||
public renderer: Renderer2) {}
|
||||
constructor(public el: ElementRef, public renderer: Renderer2) {}
|
||||
|
||||
setFontSize(fontSize: number) {
|
||||
if (this.isVisible() && !this.done) {
|
||||
|
|
@ -48,7 +48,10 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges, Af
|
|||
|
||||
this.fontSize = fontSize;
|
||||
this.fontSizeChanged.emit(fontSize);
|
||||
return this.el.nativeElement.style.setProperty('font-size', (fontSize).toString() + 'px');
|
||||
return this.el.nativeElement.style.setProperty(
|
||||
'font-size',
|
||||
fontSize.toString() + 'px'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -59,7 +62,7 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges, Af
|
|||
checkOverflow(parent: any, children: any) {
|
||||
const overflowX = children.scrollWidth - parent.clientWidth;
|
||||
const overflowY = children.clientHeight - parent.clientHeight;
|
||||
return (overflowX > 1 || overflowY > 1);
|
||||
return overflowX > 1 || overflowY > 1;
|
||||
}
|
||||
|
||||
@HostListener('window:resize', ['$event'])
|
||||
|
|
@ -94,8 +97,12 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges, Af
|
|||
ngAfterViewInit() {
|
||||
if (this.isVisible() && !this.done) {
|
||||
if (this.fittext) {
|
||||
const overflow = this.container ? this.checkOverflow(this.container, this.el.nativeElement)
|
||||
: this.checkOverflow(this.el.nativeElement.parentElement, this.el.nativeElement);
|
||||
const overflow = this.container
|
||||
? this.checkOverflow(this.container, this.el.nativeElement)
|
||||
: this.checkOverflow(
|
||||
this.el.nativeElement.parentElement,
|
||||
this.el.nativeElement
|
||||
);
|
||||
if (overflow) {
|
||||
if (this.fontSize > this.minFontSize) {
|
||||
// iterate only until font size is bigger than minimal value
|
||||
|
|
@ -128,11 +135,15 @@ export class Ng2FittextDirective implements AfterViewInit, OnInit, OnChanges, Af
|
|||
}
|
||||
|
||||
private getStartFontSizeFromHeight(): number {
|
||||
return this.container ? this.container.clientHeight : this.el.nativeElement.parentElement.clientHeight;
|
||||
return this.container
|
||||
? this.container.clientHeight
|
||||
: this.el.nativeElement.parentElement.clientHeight;
|
||||
}
|
||||
|
||||
private getStartFontSizeFromWeight(): number {
|
||||
return this.container ? this.container.clientWidth : this.el.nativeElement.parentElement.clientWidth;
|
||||
return this.container
|
||||
? this.container.clientWidth
|
||||
: this.el.nativeElement.parentElement.clientWidth;
|
||||
}
|
||||
|
||||
private isVisible(): boolean {
|
||||
|
|
|
|||
|
|
@ -1,23 +1,17 @@
|
|||
import { Ng2FittextDirective } from './directives/ng2-fittext.directive';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import {NgModule} from "@angular/core";
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
Ng2FittextDirective
|
||||
],
|
||||
exports: [
|
||||
Ng2FittextDirective
|
||||
],
|
||||
imports: [
|
||||
CommonModule
|
||||
]
|
||||
declarations: [Ng2FittextDirective],
|
||||
exports: [Ng2FittextDirective],
|
||||
imports: [CommonModule],
|
||||
})
|
||||
export class Ng2FittextModule {
|
||||
static forRoot() {
|
||||
return {
|
||||
ngModule: Ng2FittextModule,
|
||||
providers: []
|
||||
providers: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue