vant/packages/mixins/popup/popup-manager.js
neverland ccf868c239
[bugfix] Popup: update overlay style & class (#349)
* fix: Tabbar icon line-height

* [new feature] progress add showPivot prop

* [new feature] TabItem support vue-router

* [new feature] update document header style

* [Doc] add toast english ducoment

* [bugfix] Search box-sizing wrong

* [Doc] update vant-demo respo

* [Doc] translate theme & demo pages

* [Doc] add Internationalization document

* [bugfix] remove unnecessary props

* [fix] optimize clickoutside

* [new feature] optimize find-parent

* [new feature]: change document title accordinng to language

* [new feature] Pagination code review

* [improvement] adjust icon-font unicode

* [improvement] Icon spinner color inherit

* [improvement] icon default width

* [bugfix] DateTimePicker validate date props

* [bugfix] Tab item text ellipsis

* [improvement] optimize single line ellipsis

* [Improvement] optimzie staticClass

* [Improvement] Button: use sfc instread of jsx

* [Improvement] update actionsheet close icon style

* fix: yarn.lock

* fix: icon test cases

* [bugfix] errors during ssr

* [Improvement] SubmitBar add left slot

* [new feature] ImagePreview support manually close

* fix: ImagePreview test case

* [Doc] add switch lang button in mobile

* [bugfix] Popup overlay style update
2017-11-24 14:18:14 +08:00

85 lines
1.8 KiB
JavaScript

import Vue from 'vue';
import Modal from './Modal';
import context from './popup-context';
const modalDefaultConfig = {
className: '',
customStyle: {}
};
const PopupManager = {
getModal() {
let { modal } = context;
if (!modal) {
const ModalConstructor = Vue.extend(Modal);
modal = new ModalConstructor({
el: document.createElement('div')
});
modal.$on('click', () => {
PopupManager.handleOverlayClick();
});
context.modal = modal;
}
return modal;
},
// close popup when click modal && closeOnClickOverlay is true
handleOverlayClick() {
const { top } = context;
if (top) {
const instance = context.instances[top.id];
if (instance && instance.closeOnClickOverlay) {
instance.close();
}
}
},
openModal(config) {
const { id, dom } = config;
const exist = context.stack.some(item => item.id === id);
if (!exist) {
const targetNode = dom && dom.parentNode && dom.parentNode.nodeType !== 11 ? dom.parentNode : document.body;
context.stack.push({ id, config, targetNode });
this.updateModal();
};
},
closeModal(id) {
const { stack } = context;
if (stack.length) {
if (context.top.id === id) {
stack.pop();
this.updateModal();
} else {
context.stack = stack.filter(item => item.id !== id);
}
}
},
updateModal() {
const modal = this.getModal();
const el = modal.$el;
if (el.parentNode) {
el.parentNode.removeChild(el);
}
if (context.top) {
const { targetNode, config } = context.top;
targetNode.appendChild(el);
Object.assign(modal, {
...modalDefaultConfig,
...config
});
}
}
};
export default PopupManager;