vimo-dt
Version:
A Vue2.x UI Project For Mobile & HyBrid
118 lines (102 loc) • 3.72 kB
JavaScript
;
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; }; }();
var _vue = require('vue');
var _vue2 = _interopRequireDefault(_vue);
var _getInsertPosition = require('./get-insert-position');
var _getInsertPosition2 = _interopRequireDefault(_getInsertPosition);
var _type = require('./type');
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"); } }
var GeneratePopUpInstance = function () {
function GeneratePopUpInstance(component, position) {
_classCallCheck(this, GeneratePopUpInstance);
this._component = component;
this._position = position || null;
this._ins = null;
}
_createClass(GeneratePopUpInstance, [{
key: 'isPresentHandled',
value: function isPresentHandled(options) {
return false;
}
}, {
key: 'isDismissHandled',
value: function isDismissHandled(options) {
return false;
}
}, {
key: 'normalizeOptions',
value: function normalizeOptions(options) {
var _args = Array.prototype.slice.call(arguments);
if ((0, _type.isObject)(_args[0])) {
return _args[0];
} else {
return {};
}
}
}, {
key: 'getInstance',
value: function getInstance() {
return this._ins;
}
}, {
key: 'generateInstance',
value: function generateInstance(options) {
var el = (0, _getInsertPosition2.default)(this._position).appendChild(document.createElement('div'));
var Component = _vue2.default.extend(this._component);
var _ins = new Component({ propsData: options });
_ins.$mount(el);
return _ins;
}
}, {
key: 'present',
value: function present() {
var _this = this;
var options = this.normalizeOptions.apply(this, arguments);
return new Promise(function (resolve) {
if (!_this.isPresentHandled(options)) {
if (_this._ins && _this._ins.isActive) {
_this._ins.dismiss().then(function () {
_this._ins = _this.generateInstance(options);
_this._ins.present().then(function () {
return resolve();
});
});
} else {
_this._ins = _this.generateInstance(options);
_this._ins.present().then(function () {
return resolve();
});
}
} else {
resolve();
}
});
}
}, {
key: 'dismiss',
value: function dismiss() {
var _this2 = this;
return new Promise(function (resolve) {
if (!_this2.isDismissHandled()) {
if (_this2._ins && _this2._ins.isActive) {
_this2._ins.dismiss().then(function () {
_this2._ins = null;
resolve();
});
} else {
_this2._ins = null;
resolve();
}
} else {
resolve();
}
});
}
}]);
return GeneratePopUpInstance;
}();
exports.default = GeneratePopUpInstance;