[improvement] add closeOnPopstate mixin (#3708)

This commit is contained in:
neverland
2019-07-01 16:29:47 +08:00
committed by GitHub
parent 3eb802a689
commit 2df51f5aef
4 changed files with 52 additions and 26 deletions
+7 -23
View File
@@ -1,8 +1,9 @@
import { createNamespace, isServer } from '../utils';
import { createNamespace } from '../utils';
import { range } from '../utils/format/number';
import { preventDefault } from '../utils/dom/event';
import { PopupMixin } from '../mixins/popup';
import { TouchMixin } from '../mixins/touch';
import { CloseOnPopstateMixin } from '../mixins/close-on-popstate';
import Swipe from '../swipe';
import SwipeItem from '../swipe-item';
@@ -18,7 +19,11 @@ function getDistance(touches) {
}
export default createComponent({
mixins: [PopupMixin, TouchMixin],
mixins: [
PopupMixin,
TouchMixin,
CloseOnPopstateMixin
],
props: {
images: Array,
@@ -27,7 +32,6 @@ export default createComponent({
asyncClose: Boolean,
startPosition: Number,
showIndicators: Boolean,
closeOnPopstate: Boolean,
loop: {
type: Boolean,
default: true
@@ -94,30 +98,10 @@ export default createComponent({
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();
},