UNPKG

vimo-dt

Version:

A Vue2.x UI Project For Mobile & HyBrid

138 lines (119 loc) 3.41 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _focusOutActiveElement = require('./focus-out-active-element'); var _focusOutActiveElement2 = _interopRequireDefault(_focusOutActiveElement); var _urlChange = require('./url-change'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var NOOP = function NOOP() {}; exports.default = { data: function data() { return { enabled: false, disableDuring: 200, isActive: false, dismissCallback: NOOP, presentCallback: NOOP, unReg: null, $_dismissOnPageChange: true, $_recordInHistory: false }; }, props: { dismissOnPageChange: { type: Boolean, default: true }, recordInHistory: { type: Boolean, default: false }, scrollControl: { type: Boolean, default: true } }, methods: { beforeEnter: function beforeEnter() { this.$emit('popup:beforeEnter'); this.$app && this.$app.setEnabled(false, this.disableDuring); this.enabled = false; (0, _focusOutActiveElement2.default)(); }, afterEnter: function afterEnter() { this.$emit('popup:afterEnter'); this.presentCallback(); this.enabled = true; }, beforeLeave: function beforeLeave() { this.$emit('popup:beforeLeave'); this.$app && this.$app.setEnabled(false, this.disableDuring); this.enabled = false; (0, _focusOutActiveElement2.default)(); }, afterLeave: function afterLeave() { this.$emit('popup:afterLeave'); this.dismissCallback(); this.enabled = true; this.$destroy(); }, beforePresent: function beforePresent() {}, beforeDismiss: function beforeDismiss() {}, present: function present() { var _this = this; this.isActive = true; this.beforePresent(); return new Promise(function (resolve) { _this.presentCallback = resolve; }); }, dismiss: function dismiss() { var _this2 = this; if (this.isActive) { this.isActive = false; this.unReg && this.unReg(); this.beforeDismiss(); if (this.$_recordInHistory) { window.history.back(); } return new Promise(function (resolve) { _this2.dismissCallback = resolve; }); } else { return new Promise(function (resolve) { resolve(); }); } } }, created: function created() { var _this3 = this; if (this.scrollControl) { this.$app && this.$app.$_disableScroll(); } this.$app && this.$app.$_addChild(this); this.$_dismissOnPageChange = this.dismissOnPageChange; this.$_recordInHistory = this.recordInHistory; if (this.$_recordInHistory) { this.$_dismissOnPageChange = true; window.history.pushState({ id: new Date().getTime(), name: '' + this._uid }, '', ''); } if (this.$_dismissOnPageChange) { this.unReg = (0, _urlChange.urlChange)(function () { _this3.$_recordInHistory = false; _this3.isActive && _this3.dismiss(); }); } }, destroyed: function destroyed() { if (this.scrollControl) { this.$app && this.$app.$_enableScroll(); } this.$app && this.$app.$_removeChild(this); this.$el && this.$el.remove(); } };