Skip to content

Commit

Permalink
refactor: do not ignore close when manually calling the move method
Browse files Browse the repository at this point in the history
  • Loading branch information
fengyuanchen committed Jan 1, 2023
1 parent 6150c5b commit 299dae8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## next

- Do not close the viewer when dragging the image on the backdrop (#577).

## 1.11.1 (Nov 6, 2022)

- Add missing type definitions for `initialCoverage` option and `zoom` and `zoomTo` methods (#571).
Expand Down
17 changes: 6 additions & 11 deletions src/js/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {

export default {
click(event) {
const { options, imageData, ignoreCloseOnceMoved } = this;
const { options, imageData } = this;
let { target } = event;
let action = getData(target, DATA_ACTION);

Expand Down Expand Up @@ -63,7 +63,7 @@ export default {
break;

case 'hide':
if (ignoreCloseOnceMoved !== true) {
if (!this.pointerMoved) {
this.hide();
}
break;
Expand Down Expand Up @@ -337,6 +337,8 @@ export default {
const { options, pointers } = this;
const { buttons, button } = event;

this.pointerMoved = false;

if (
!this.viewed
|| this.showing
Expand Down Expand Up @@ -393,6 +395,7 @@ export default {
}

event.preventDefault();
this.pointerMoved = true;

if (event.changedTouches) {
forEach(event.changedTouches, (touch) => {
Expand All @@ -406,9 +409,7 @@ export default {
},

pointerup(event) {
const {
options, action, pointers, ignoreCloseOnceMoved,
} = this;
const { options, action, pointers } = this;
let pointer;

if (event.changedTouches) {
Expand All @@ -421,12 +422,6 @@ export default {
delete pointers[event.pointerId || 0];
}

if (ignoreCloseOnceMoved) {
setTimeout(() => {
this.ignoreCloseOnceMoved = false;
});
}

if (!action) {
return;
}
Expand Down
1 change: 0 additions & 1 deletion src/js/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,6 @@ export default {
imageData.left = x;
imageData.top = y;
this.moving = true;
this.ignoreCloseOnceMoved = true;
this.renderImage(() => {
this.moving = false;

Expand Down
1 change: 1 addition & 0 deletions src/js/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class Viewer {
this.viewing = false;
this.wheeling = false;
this.zooming = false;
this.pointerMoved = false;
this.id = getUniqueID();
this.init();
}
Expand Down

0 comments on commit 299dae8

Please sign in to comment.