Skip to content
This repository has been archived by the owner on Mar 15, 2023. It is now read-only.

Commit

Permalink
onViewerImageUpdate (#87)
Browse files Browse the repository at this point in the history
* onViewerImageUpdate
  • Loading branch information
lwojcik authored May 20, 2019
1 parent d52ca96 commit 2dbabac
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 4 deletions.
6 changes: 6 additions & 0 deletions dist/examples/events.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ <h3>JavaScript</h3>
onViewerImageGenerate: function() {
console.log('Viewer image generated');
},
onViewerImageUpdate: function() {
console.log('Viewer image updated');
},
onImagesPreload: function() {
console.log('Images preloaded');
},
Expand Down Expand Up @@ -103,6 +106,9 @@ <h3>JavaScript</h3>
onViewerImageGenerate: function() {
console.log('Viewer image generated');
},
onViewerImageUpdate: function() {
console.log('Viewer image updated');
},
onImagesPreload: function() {
console.log('Images preloaded');
},
Expand Down
2 changes: 2 additions & 0 deletions dist/js/tridi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface TridiOptions {
playable?: boolean;
onViewerGenerate?: Function | undefined;
onViewerImageGenerate?: Function | undefined;
onViewerImageUpdate?: Function | undefined;
onHintShow?: Function | undefined;
onHintHide?: Function | undefined;
onLoadingScreenShow: Function | undefined;
Expand Down Expand Up @@ -81,6 +82,7 @@ declare class Tridi {
inverse?: boolean;
onViewerGenerate?: Function | undefined;
onViewerImageGenerate?: Function | undefined;
onViewerImageUpdate?: Function | undefined;
onHintShow?: Function | undefined;
onHintHide?: Function | undefined;
onLoadingScreenShow: Function | undefined;
Expand Down
4 changes: 4 additions & 0 deletions dist/js/tridi.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/js/tridi.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dist/js/tridi.min.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface TridiOptions {
playable?: boolean;
onViewerGenerate?: Function | undefined;
onViewerImageGenerate?: Function | undefined;
onViewerImageUpdate?: Function | undefined;
onHintShow?: Function | undefined;
onHintHide?: Function | undefined;
onLoadingScreenShow: Function | undefined;
Expand Down Expand Up @@ -81,6 +82,7 @@ declare class Tridi {
inverse?: boolean;
onViewerGenerate?: Function | undefined;
onViewerImageGenerate?: Function | undefined;
onViewerImageUpdate?: Function | undefined;
onHintShow?: Function | undefined;
onHintHide?: Function | undefined;
onLoadingScreenShow: Function | undefined;
Expand Down
2 changes: 1 addition & 1 deletion dist/js/tridi.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/tridi.min.js.map

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion dist/notes/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,11 @@ <h2 id="events"><a href="#events">Events</a></h2>
</tr>
<tr id="onViewerImageGenerate">
<td><code>onViewerImageGenerate</code></td>
<td>First viewer image is loaded</td>
<td>First viewer image is initially loaded</td>
</tr>
<tr id="onViewerImageUpdate">
<td><code>onViewerImageUpdate</code></td>
<td>Viewer image is updated</td>
</tr>
<tr id="onHintShow">
<td><code>onHintShow</code></td>
Expand Down
5 changes: 5 additions & 0 deletions src/tridi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface TridiOptions {
playable?: boolean;
onViewerGenerate?: Function | undefined;
onViewerImageGenerate?: Function | undefined;
onViewerImageUpdate?: Function | undefined;
onHintShow?: Function | undefined;
onHintHide?: Function | undefined;
onLoadingScreenShow: Function | undefined;
Expand Down Expand Up @@ -91,6 +92,7 @@ class Tridi {
inverse?: boolean;
onViewerGenerate?: Function | undefined;
onViewerImageGenerate?: Function | undefined;
onViewerImageUpdate?: Function | undefined;
onHintShow?: Function | undefined;
onHintHide?: Function | undefined;
onLoadingScreenShow: Function | undefined;
Expand Down Expand Up @@ -151,6 +153,7 @@ class Tridi {
this.mouseleaveDetect = options.mouseleaveDetect || false;
this.onViewerGenerate = options.onViewerGenerate || undefined;
this.onViewerImageGenerate = options.onViewerImageGenerate || undefined;
this.onViewerImageUpdate = options.onViewerImageUpdate || undefined;
this.onHintShow = options.onHintShow || undefined;
this.onHintHide = options.onHintHide || undefined;
this.onLoadingScreenShow = options.onLoadingScreenShow || undefined;
Expand Down Expand Up @@ -444,6 +447,8 @@ class Tridi {
}

private updateViewerImage(whichImage: number) {
/* istanbul ignore next */
this.viewerImage().onload = () => this.trigger('onViewerImageUpdate');
this.viewerImage().src = this.image(whichImage);
}

Expand Down
13 changes: 13 additions & 0 deletions tests/tridi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,19 @@ describe('Custom events', () => {
expect(() => tridi.load()).not.toThrow();
});

test(`should accept 'onViewerImageGenerate' event callback`, () => {
const tridi = setupTridi(containerId, {
...options,
onViewerImageUpdate: () => {
return 0;
},
});

tridi.load();

expect(() => tridi.update(options)).not.toThrow();
});

test(`should accept 'onImagesPreload' event callback`, () => {
const tridi = setupTridi(containerId, {
...options,
Expand Down

0 comments on commit 2dbabac

Please sign in to comment.