[improvement] add closeOnPopstate mixin (#3708)
This commit is contained in:
@@ -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();
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user