UNPKG

sohelp-ele

Version:

SohelpEle Library

79 lines (78 loc) 2.21 kB
"use strict"; var Vue = require("vue"); var sohelpVformModal = require("../sohelp-vform-modal"); function _interopDefaultLegacy(e) { return e && typeof e === "object" && "default" in e ? e : { "default": e }; } var Vue__default = /* @__PURE__ */ _interopDefaultLegacy(Vue); var sohelpVformModal__default = /* @__PURE__ */ _interopDefaultLegacy(sohelpVformModal); const ModalPoolDiv = (() => { const _poolDiv = document.createElement("div"); _poolDiv.className = ".modal-pool"; document.body.appendChild(_poolDiv); return _poolDiv; })(); const SohelpModals = { _pool: {}, _createInstance(refid) { const uuid = "modal-" + Math.floor(Math.random() * 100 + 1) + new Date().getTime(); const sohelpVformModalConstructor = Vue__default["default"].extend(sohelpVformModal__default["default"]); const instance = new sohelpVformModalConstructor({ propsData: { refid } }); Object.assign(instance, { close: () => { alert(1); SohelpModals.close(refid); }, uuid }); instance.$on("close", () => { alert(2); }); instance.$mount(); instance.$el.classList.add(uuid); ModalPoolDiv.appendChild(instance.$el); return instance; }, open(refid) { let instance = SohelpModals._pool[refid]; if (!instance) { instance = SohelpModals._createInstance(refid); SohelpModals._pool[refid] = instance; } instance.show(); return instance; }, get: function(refid) { return SohelpModals._pool[refid]; }, hide: function(refid) { const instance = SohelpModals._pool[refid]; if (instance) { instance.hide(); } }, show: function(refid) { const instance = SohelpModals._pool[refid]; if (instance) { instance.show(); } }, close: function(refid) { const instance = SohelpModals._pool[refid]; if (instance.uuid) { let _p = document.querySelector("." + instance.uuid); if (_p) { document.querySelector(".modal-pool").removeChild(_p); } } }, destroyAll: function() { this._pool = {}; document.body.removeChild(document.querySelector(".modal-pool")); } }; module.exports = SohelpModals;