Skip to content

Commit

Permalink
Merge branch 'master' into add-fullscreenNavigationUI-option
Browse files Browse the repository at this point in the history
  • Loading branch information
fengyuanchen authored Jun 12, 2021
2 parents 8214a36 + cdd94b4 commit c066a63
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## next

- Enhance `fullscreen` option and `play` method to support [`FullscreenOptions`](https://developer.mozilla.org/en-US/docs/Web/API/FullscreenOptions) (#482, #483).
- Refactor the `toggle` method for toggling image between current/natural ratio (#477).

## 1.9.2 (May 29, 2021)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ Show the current ratio of the image by percentage.
### toggle()

Toggle the image size between its natural size and initial size.
Toggle the image size between its current size and natural size.

> Used by the [`toggleOnDblclick`](#toggleOnDblclick) option.
Expand Down
7 changes: 4 additions & 3 deletions src/js/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ export default {
const newHeight = naturalHeight * ratio;
const offsetWidth = newWidth - width;
const offsetHeight = newHeight - height;
const oldRatio = width / naturalWidth;
const oldRatio = imageData.ratio;

if (isFunction(options.zoom)) {
addListener(element, EVENT_ZOOM, options.zoom, {
Expand Down Expand Up @@ -739,6 +739,7 @@ export default {
imageData.top = imageData.y;
imageData.width = newWidth;
imageData.height = newHeight;
imageData.oldRatio = oldRatio;
imageData.ratio = ratio;
this.renderImage(() => {
this.zooming = false;
Expand Down Expand Up @@ -1048,10 +1049,10 @@ export default {
return this;
},

// Toggle the image size between its natural size and initial size
// Toggle the image size between its current size and natural size
toggle() {
if (this.imageData.ratio === 1) {
this.zoomTo(this.initialImageData.ratio, true);
this.zoomTo(this.imageData.oldRatio, true);
} else {
this.zoomTo(1, true);
}
Expand Down
1 change: 1 addition & 0 deletions src/js/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ export default {
y: top,
width,
height,
oldRatio: 1,
ratio: width / naturalWidth,
aspectRatio,
naturalWidth,
Expand Down
2 changes: 1 addition & 1 deletion test/specs/methods/toggle.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe('toggle (method)', () => {
it('should toggle the scale of the current viewing image between its initial ratio and 1', (done) => {
it('should toggle the scale of the current viewing image between its current ratio and 1', (done) => {
const image = window.createImage();
const viewer = new Viewer(image, {
viewed() {
Expand Down

0 comments on commit c066a63

Please sign in to comment.