code improvements
This commit is contained in:
		@@ -1,39 +1,5 @@
 | 
			
		||||
// import { async, ComponentFixture, TestBed } from '@angular/core/testing';
 | 
			
		||||
//
 | 
			
		||||
// import { ImgMagnifierComponent } from './img-magnifier.component';
 | 
			
		||||
//
 | 
			
		||||
// // TODO
 | 
			
		||||
//
 | 
			
		||||
// let windowServiceSpy: jasmine.SpyObj<Window>;
 | 
			
		||||
//
 | 
			
		||||
// describe('ImgMagnifierComponent', () => {
 | 
			
		||||
//   let component: ImgMagnifierComponent;
 | 
			
		||||
//   let fixture: ComponentFixture<ImgMagnifierComponent>;
 | 
			
		||||
//
 | 
			
		||||
//   beforeEach(async(() => {
 | 
			
		||||
//     const windowSpy = jasmine.createSpyObj('Window', ['pageXOffset', 'pageYOffset']);
 | 
			
		||||
//
 | 
			
		||||
//     TestBed.configureTestingModule({
 | 
			
		||||
//       declarations: [ ImgMagnifierComponent ],
 | 
			
		||||
//       imports: [
 | 
			
		||||
//       ],
 | 
			
		||||
//       providers: [
 | 
			
		||||
//         {provide: Window, useValue: windowSpy}
 | 
			
		||||
//       ]
 | 
			
		||||
//     })
 | 
			
		||||
//     .compileComponents();
 | 
			
		||||
//
 | 
			
		||||
//     windowServiceSpy = TestBed.inject(Window) as jasmine.SpyObj<Window>;
 | 
			
		||||
//   }));
 | 
			
		||||
//
 | 
			
		||||
//   beforeEach(() => {
 | 
			
		||||
//     fixture = TestBed.createComponent(ImgMagnifierComponent);
 | 
			
		||||
//     component = fixture.componentInstance;
 | 
			
		||||
//     component.ngOnInit();
 | 
			
		||||
//     fixture.detectChanges();
 | 
			
		||||
//   });
 | 
			
		||||
//
 | 
			
		||||
//   it('should create', () => {
 | 
			
		||||
//     expect(component).toBeTruthy();
 | 
			
		||||
//   });
 | 
			
		||||
// });
 | 
			
		||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
 | 
			
		||||
 | 
			
		||||
describe('ImgMagnifierComponent', () => {
 | 
			
		||||
 | 
			
		||||
});
 | 
			
		||||
 
 | 
			
		||||
@@ -7,13 +7,13 @@ import {AfterViewInit, Component, ElementRef, Input, OnInit, ViewChild} from '@a
 | 
			
		||||
})
 | 
			
		||||
export class ImgMagnifierComponent implements OnInit, AfterViewInit {
 | 
			
		||||
 | 
			
		||||
  @Input() src: string;
 | 
			
		||||
  @Input() zoom: number;
 | 
			
		||||
  @Input() magnifierSize: {width: number, height: number};
 | 
			
		||||
  @Input() src: string;   // image source
 | 
			
		||||
  @Input() zoom: number;  // zoom level
 | 
			
		||||
  @Input() magnifierSize: {width: number, height: number};  // size of the magnifier
 | 
			
		||||
  @ViewChild('mainImg') mainImg: ElementRef;
 | 
			
		||||
 | 
			
		||||
  backgroundSize;
 | 
			
		||||
  magnifierPos = {x: 0, y: 0};
 | 
			
		||||
  magnifierPos = {x: 0, y: 0};  // position of the magnifier
 | 
			
		||||
  showMagnifier = false;
 | 
			
		||||
 | 
			
		||||
  constructor(
 | 
			
		||||
@@ -29,7 +29,7 @@ export class ImgMagnifierComponent implements OnInit, AfterViewInit {
 | 
			
		||||
    }, 1);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  calcPos(event) {
 | 
			
		||||
  calcPos(event) {  // calculate the current magnifier position
 | 
			
		||||
    const img = this.mainImg.nativeElement.getBoundingClientRect();
 | 
			
		||||
    this.magnifierPos.x = Math.min(
 | 
			
		||||
      img.width - this.magnifierSize.width,
 | 
			
		||||
@@ -42,7 +42,7 @@ export class ImgMagnifierComponent implements OnInit, AfterViewInit {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  calcBackgroundSize() {
 | 
			
		||||
    this.backgroundSize = this.mainImg ? (this.mainImg.nativeElement.width * this.zoom - this.magnifierSize.width) + 'px ' +
 | 
			
		||||
      (this.mainImg.nativeElement.height * this.zoom - this.magnifierSize.height) + 'px ' : '0 0';
 | 
			
		||||
    this.backgroundSize = this.mainImg ? (this.mainImg.nativeElement.width * this.zoom - this.magnifierSize.width) +
 | 
			
		||||
      'px ' + (this.mainImg.nativeElement.height * this.zoom - this.magnifierSize.height) + 'px ' : '0 0';
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user