[new feature] ImagePreview: add closeOnPopstate prop

This commit is contained in:
陈嘉涵
2019-05-24 20:13:21 +08:00
parent 30ddcb5daa
commit b572c76245
7 changed files with 53 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
import { use, range } from '../utils';
import { use, range, isServer } from '../utils';
import { preventDefault } from '../utils/event';
import { PopupMixin } from '../mixins/popup';
import { TouchMixin } from '../mixins/touch';
@@ -26,6 +26,7 @@ export default sfc({
asyncClose: Boolean,
startPosition: Number,
showIndicators: Boolean,
closeOnPopstate: Boolean,
loop: {
type: Boolean,
default: true
@@ -57,6 +58,8 @@ export default sfc({
},
data() {
this.bindStatus = false;
return {
scale: 1,
moveX: 0,
@@ -90,10 +93,30 @@ export default sfc({
startPosition(active) {
this.active = active;
},
closeOnPopstate: {
handler(val) {
this.handlePopstate(val);
},
immediate: true
}
},
methods: {
handlePopstate(bind) {
/* istanbul ignore if */
if (isServer) {
return;
}
if (this.bindStatus !== bind) {
this.bindStatus = bind;
const action = bind ? 'add' : 'remove';
window[`${action}EventListener`]('popstate', this.close);
}
},
onWrapperTouchStart() {
this.touchStartTime = new Date();
},