Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix problem when multiple images have the same src #18

Merged
merged 1 commit into from
Jun 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class AppComponent {
}

open(index: number): void {
this._subscription = this._lightboxEvent.lightboxEvent$.subscribe(event => this._onReceivedEvent(event));
this._subscription = this._lightboxEvent.lightboxEvent$.subscribe((event: IEvent) => this._onReceivedEvent(event));

// override the default config
this._lightbox.open(this._albums, index, { wrapAround: true, showImageNumberLabel: true });
Expand Down
1 change: 0 additions & 1 deletion src/lightbox.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ describe('[ Unit - LightboxComponent ]', () => {
fixture.componentInstance.options.disableKeyboardNav = false;
fixture.componentInstance.ngOnDestroy();
expect(fixture.componentInstance['_event'].keyup).toHaveBeenCalledTimes(1);
expect(fixture.componentInstance['_event'].load).toHaveBeenCalledTimes(1);
expect(fixture.componentInstance['_event'].subscription.unsubscribe).toHaveBeenCalledTimes(1);
});

Expand Down
20 changes: 5 additions & 15 deletions src/lightbox.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,6 @@ export class LightboxComponent implements AfterViewInit, OnDestroy {
this._disableKeyboardNav();
}

if (this._event.load) {
// unbind all the event
this._event.load();
}

this._event.subscription.unsubscribe();
}

Expand Down Expand Up @@ -201,11 +196,12 @@ export class LightboxComponent implements AfterViewInit, OnDestroy {
}

private _registerImageLoadingEvent(): void {
// start to register the event and
// be ready for callback
this._event.load = this._rendererRef.listen(this._imageElem.nativeElement, 'load', () => {
const preloader = new Image();

preloader.onload = () => {
this._onLoadImageSuccess();
});
}
preloader.src = this.album[this.currentImageIndex].src;
}

/**
Expand Down Expand Up @@ -386,12 +382,6 @@ export class LightboxComponent implements AfterViewInit, OnDestroy {

private _changeImage(newIndex: number): void {
this.currentImageIndex = newIndex;

// unbind load event from image first before bind it again
if (this._event.load) {
this._event.load();
}

this._hideImage();
this._registerImageLoadingEvent();
this._lightboxEvent.broadcastLightboxEvent({ id: LIGHTBOX_EVENT.CHANGE_PAGE, data: newIndex });
Expand Down