UNPKG

vimo-dt

Version:

A Vue2.x UI Project For Mobile & HyBrid

118 lines (99 loc) 3.35 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); exports.default = recordMenuInstance; var _urlChange = require('../../util/url-change'); var _urlChange2 = _interopRequireDefault(_urlChange); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function recordMenuInstance(instance) { var proto = Reflect.getPrototypeOf(Reflect.getPrototypeOf(instance)); if (!proto.$menu) { proto.$menu = new Menu(); } proto.$menu.record(instance); } var Menu = function () { function Menu() { _classCallCheck(this, Menu); this.currentMenuId = null; this.menuIns = {}; this._unReg = null; } _createClass(Menu, [{ key: 'record', value: function record(instance) { this.menuIns[instance.id] = instance; } }, { key: 'open', value: function open(id) { var _this2 = this; var _successCb = void 0; var _errorCb = void 0; if (this.currentMenuId) { this.close().then(function () { window.setTimeout(function () { _openMenu(_this2, id); }, 16 * 10); }); } else { _openMenu(this, id); } function _openMenu(_this, id) { if (_this.menuIns[id]) { _this.currentMenuId = id; _this.menuIns[id].openMenu(); _successCb && _successCb(); } else { _errorCb && _errorCb(); } _this._unReg && _this._unReg(); _this._unReg = (0, _urlChange2.default)(function () { _this.close(); }); } return new Promise(function (resolve, reject) { _successCb = resolve; _errorCb = reject; }); } }, { key: 'close', value: function close() { var _this3 = this; var currentMenuId = this.currentMenuId; var _successCb = void 0; var _errorCb = void 0; if (!currentMenuId) { _errorCb && _errorCb(); } else { this.currentMenuId = null; if (this.menuIns[currentMenuId]) { this.menuIns[currentMenuId].closeMenu().then(function () { _successCb && _successCb(); }); } else { _errorCb && _errorCb(); } } return new Promise(function (resolve, reject) { _this3._unReg && _this3._unReg(); _successCb = resolve; _errorCb = reject; }); } }, { key: 'toggle', value: function toggle(id) { if (this.currentMenuId) { return this.close(); } else { return this.open(id); } } }]); return Menu; }();