mindoc/static/element-ui/lib/message-box.js
2017-04-19 18:19:27 +08:00

819 lines
20 KiB
JavaScript

module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "/dist/";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ({
/***/ 0:
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(199);
/***/ },
/***/ 3:
/***/ function(module, exports) {
module.exports = function normalizeComponent (
rawScriptExports,
compiledTemplate,
scopeId,
cssModules
) {
var esModule
var scriptExports = rawScriptExports = rawScriptExports || {}
// ES6 modules interop
var type = typeof rawScriptExports.default
if (type === 'object' || type === 'function') {
esModule = rawScriptExports
scriptExports = rawScriptExports.default
}
// Vue.extend constructor export interop
var options = typeof scriptExports === 'function'
? scriptExports.options
: scriptExports
// render functions
if (compiledTemplate) {
options.render = compiledTemplate.render
options.staticRenderFns = compiledTemplate.staticRenderFns
}
// scopedId
if (scopeId) {
options._scopeId = scopeId
}
// inject cssModules
if (cssModules) {
var computed = options.computed || (options.computed = {})
Object.keys(cssModules).forEach(function (key) {
var module = cssModules[key]
computed[key] = function () { return module }
})
}
return {
esModule: esModule,
exports: scriptExports,
options: options
}
}
/***/ },
/***/ 9:
/***/ function(module, exports) {
module.exports = require("element-ui/lib/input");
/***/ },
/***/ 56:
/***/ function(module, exports) {
module.exports = require("vue");
/***/ },
/***/ 60:
/***/ function(module, exports) {
module.exports = require("element-ui/lib/mixins/locale");
/***/ },
/***/ 61:
/***/ function(module, exports) {
module.exports = require("element-ui/lib/locale");
/***/ },
/***/ 117:
/***/ function(module, exports) {
module.exports = require("element-ui/lib/utils/dom");
/***/ },
/***/ 132:
/***/ function(module, exports) {
module.exports = require("element-ui/lib/utils/popup");
/***/ },
/***/ 137:
/***/ function(module, exports) {
module.exports = require("element-ui/lib/button");
/***/ },
/***/ 164:
/***/ function(module, exports) {
module.exports = require("element-ui/lib/utils/merge");
/***/ },
/***/ 199:
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
var _main = __webpack_require__(200);
var _main2 = _interopRequireDefault(_main);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = _main2.default;
/***/ },
/***/ 200:
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
exports.MessageBox = undefined;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _vue = __webpack_require__(56);
var _vue2 = _interopRequireDefault(_vue);
var _main = __webpack_require__(201);
var _main2 = _interopRequireDefault(_main);
var _merge = __webpack_require__(164);
var _merge2 = _interopRequireDefault(_merge);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var defaults = {
title: undefined,
message: '',
type: '',
showInput: false,
showClose: true,
modalFade: true,
lockScroll: true,
closeOnClickModal: true,
closeOnPressEscape: true,
inputValue: null,
inputPlaceholder: '',
inputPattern: null,
inputValidator: null,
inputErrorMessage: '',
showConfirmButton: true,
showCancelButton: false,
confirmButtonPosition: 'right',
confirmButtonHighlight: false,
cancelButtonHighlight: false,
confirmButtonText: '',
cancelButtonText: '',
confirmButtonClass: '',
cancelButtonClass: '',
customClass: '',
beforeClose: null
};
var MessageBoxConstructor = _vue2.default.extend(_main2.default);
var currentMsg = void 0,
instance = void 0;
var msgQueue = [];
var defaultCallback = function defaultCallback(action) {
if (currentMsg) {
var callback = currentMsg.callback;
if (typeof callback === 'function') {
if (instance.showInput) {
callback(instance.inputValue, action);
} else {
callback(action);
}
}
if (currentMsg.resolve) {
var $type = currentMsg.options.$type;
if ($type === 'confirm' || $type === 'prompt') {
if (action === 'confirm') {
if (instance.showInput) {
currentMsg.resolve({ value: instance.inputValue, action: action });
} else {
currentMsg.resolve(action);
}
} else if (action === 'cancel' && currentMsg.reject) {
currentMsg.reject(action);
}
} else {
currentMsg.resolve(action);
}
}
}
};
var initInstance = function initInstance() {
instance = new MessageBoxConstructor({
el: document.createElement('div')
});
instance.callback = defaultCallback;
};
var showNextMsg = function showNextMsg() {
if (!instance) {
initInstance();
}
instance.action = '';
if (!instance.value || instance.closeTimer) {
if (msgQueue.length > 0) {
(function () {
currentMsg = msgQueue.shift();
var options = currentMsg.options;
for (var prop in options) {
if (options.hasOwnProperty(prop)) {
instance[prop] = options[prop];
}
}
if (options.callback === undefined) {
instance.callback = defaultCallback;
}
var oldCb = instance.callback;
instance.callback = function (action, instance) {
oldCb(action, instance);
showNextMsg();
};
['modal', 'showClose', 'closeOnClickModal', 'closeOnPressEscape'].forEach(function (prop) {
if (instance[prop] === undefined) {
instance[prop] = true;
}
});
document.body.appendChild(instance.$el);
_vue2.default.nextTick(function () {
instance.value = true;
});
})();
}
}
};
var MessageBox = function MessageBox(options, callback) {
if (_vue2.default.prototype.$isServer) return;
if (typeof options === 'string') {
options = {
message: options
};
if (arguments[1]) {
options.title = arguments[1];
}
if (arguments[2]) {
options.type = arguments[2];
}
} else if (options.callback && !callback) {
callback = options.callback;
}
if (typeof Promise !== 'undefined') {
return new Promise(function (resolve, reject) {
// eslint-disable-line
msgQueue.push({
options: (0, _merge2.default)({}, defaults, MessageBox.defaults, options),
callback: callback,
resolve: resolve,
reject: reject
});
showNextMsg();
});
} else {
msgQueue.push({
options: (0, _merge2.default)({}, defaults, MessageBox.defaults, options),
callback: callback
});
showNextMsg();
}
};
MessageBox.setDefaults = function (defaults) {
MessageBox.defaults = defaults;
};
MessageBox.alert = function (message, title, options) {
if ((typeof title === 'undefined' ? 'undefined' : _typeof(title)) === 'object') {
options = title;
title = '';
}
return MessageBox((0, _merge2.default)({
title: title,
message: message,
$type: 'alert',
closeOnPressEscape: false,
closeOnClickModal: false
}, options));
};
MessageBox.confirm = function (message, title, options) {
if ((typeof title === 'undefined' ? 'undefined' : _typeof(title)) === 'object') {
options = title;
title = '';
}
return MessageBox((0, _merge2.default)({
title: title,
message: message,
$type: 'confirm',
showCancelButton: true
}, options));
};
MessageBox.prompt = function (message, title, options) {
if ((typeof title === 'undefined' ? 'undefined' : _typeof(title)) === 'object') {
options = title;
title = '';
}
return MessageBox((0, _merge2.default)({
title: title,
message: message,
showCancelButton: true,
showInput: true,
$type: 'prompt'
}, options));
};
MessageBox.close = function () {
instance.value = false;
msgQueue = [];
currentMsg = null;
};
exports.default = MessageBox;
exports.MessageBox = MessageBox;
/***/ },
/***/ 201:
/***/ function(module, exports, __webpack_require__) {
var Component = __webpack_require__(3)(
/* script */
__webpack_require__(202),
/* template */
__webpack_require__(203),
/* scopeId */
null,
/* cssModules */
null
)
module.exports = Component.exports
/***/ },
/***/ 202:
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
var _popup = __webpack_require__(132);
var _popup2 = _interopRequireDefault(_popup);
var _locale = __webpack_require__(60);
var _locale2 = _interopRequireDefault(_locale);
var _input = __webpack_require__(9);
var _input2 = _interopRequireDefault(_input);
var _button = __webpack_require__(137);
var _button2 = _interopRequireDefault(_button);
var _dom = __webpack_require__(117);
var _locale3 = __webpack_require__(61);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
var typeMap = {
success: 'circle-check',
info: 'information',
warning: 'warning',
error: 'circle-cross'
};
exports.default = {
mixins: [_popup2.default, _locale2.default],
props: {
modal: {
default: true
},
lockScroll: {
default: true
},
showClose: {
type: Boolean,
default: true
},
closeOnClickModal: {
default: true
},
closeOnPressEscape: {
default: true
}
},
components: {
ElInput: _input2.default,
ElButton: _button2.default
},
computed: {
typeClass: function typeClass() {
return this.type && typeMap[this.type] ? 'el-icon-' + typeMap[this.type] : '';
},
confirmButtonClasses: function confirmButtonClasses() {
return 'el-button--primary ' + this.confirmButtonClass;
},
cancelButtonClasses: function cancelButtonClasses() {
return '' + this.cancelButtonClass;
}
},
methods: {
getSafeClose: function getSafeClose() {
var _this = this;
var currentId = this.uid;
return function () {
_this.$nextTick(function () {
if (currentId === _this.uid) _this.doClose();
});
};
},
doClose: function doClose() {
var _this2 = this;
if (!this.value) return;
this.value = false;
this._closing = true;
this.onClose && this.onClose();
if (this.lockScroll) {
setTimeout(function () {
if (_this2.modal && _this2.bodyOverflow !== 'hidden') {
document.body.style.overflow = _this2.bodyOverflow;
document.body.style.paddingRight = _this2.bodyPaddingRight;
}
_this2.bodyOverflow = null;
_this2.bodyPaddingRight = null;
}, 200);
}
this.opened = false;
if (!this.transition) {
this.doAfterClose();
}
if (this.action) this.callback(this.action, this);
},
handleWrapperClick: function handleWrapperClick() {
if (this.closeOnClickModal) {
this.action = '';
this.doClose();
}
},
handleAction: function handleAction(action) {
if (this.$type === 'prompt' && action === 'confirm' && !this.validate()) {
return;
}
this.action = action;
if (typeof this.beforeClose === 'function') {
this.close = this.getSafeClose();
this.beforeClose(action, this, this.close);
} else {
this.doClose();
}
},
validate: function validate() {
if (this.$type === 'prompt') {
var inputPattern = this.inputPattern;
if (inputPattern && !inputPattern.test(this.inputValue || '')) {
this.editorErrorMessage = this.inputErrorMessage || (0, _locale3.t)('el.messagebox.error');
(0, _dom.addClass)(this.$refs.input.$el.querySelector('input'), 'invalid');
return false;
}
var inputValidator = this.inputValidator;
if (typeof inputValidator === 'function') {
var validateResult = inputValidator(this.inputValue);
if (validateResult === false) {
this.editorErrorMessage = this.inputErrorMessage || (0, _locale3.t)('el.messagebox.error');
(0, _dom.addClass)(this.$refs.input.$el.querySelector('input'), 'invalid');
return false;
}
if (typeof validateResult === 'string') {
this.editorErrorMessage = validateResult;
return false;
}
}
}
this.editorErrorMessage = '';
(0, _dom.removeClass)(this.$refs.input.$el.querySelector('input'), 'invalid');
return true;
}
},
watch: {
inputValue: {
immediate: true,
handler: function handler(val) {
var _this3 = this;
this.$nextTick(function (_) {
if (_this3.$type === 'prompt' && val !== null) {
_this3.validate();
}
});
}
},
value: function value(val) {
var _this4 = this;
if (val) this.uid++;
if (this.$type === 'alert' || this.$type === 'confirm') {
this.$nextTick(function () {
_this4.$refs.confirm.$el.focus();
});
}
if (this.$type !== 'prompt') return;
if (val) {
setTimeout(function () {
if (_this4.$refs.input && _this4.$refs.input.$el) {
_this4.$refs.input.$el.querySelector('input').focus();
}
}, 500);
} else {
this.editorErrorMessage = '';
(0, _dom.removeClass)(this.$refs.input.$el.querySelector('input'), 'invalid');
}
}
},
data: function data() {
return {
uid: 1,
title: undefined,
message: '',
type: '',
customClass: '',
showInput: false,
inputValue: null,
inputPlaceholder: '',
inputPattern: null,
inputValidator: null,
inputErrorMessage: '',
showConfirmButton: true,
showCancelButton: false,
action: '',
confirmButtonText: '',
cancelButtonText: '',
confirmButtonLoading: false,
cancelButtonLoading: false,
confirmButtonClass: '',
confirmButtonDisabled: false,
cancelButtonClass: '',
editorErrorMessage: null,
callback: null
};
}
};
/***/ },
/***/ 203:
/***/ function(module, exports) {
module.exports={render:function (){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;
return _c('transition', {
attrs: {
"name": "msgbox-fade"
}
}, [_c('div', {
directives: [{
name: "show",
rawName: "v-show",
value: (_vm.value),
expression: "value"
}],
staticClass: "el-message-box__wrapper",
on: {
"click": function($event) {
if ($event.target !== $event.currentTarget) { return; }
_vm.handleWrapperClick($event)
}
}
}, [_c('div', {
staticClass: "el-message-box",
class: _vm.customClass
}, [(_vm.title !== undefined) ? _c('div', {
staticClass: "el-message-box__header"
}, [_c('div', {
staticClass: "el-message-box__title"
}, [_vm._v(_vm._s(_vm.title || _vm.t('el.messagebox.title')))]), (_vm.showClose) ? _c('i', {
staticClass: "el-message-box__close el-icon-close",
on: {
"click": function($event) {
_vm.handleAction('cancel')
}
}
}) : _vm._e()]) : _vm._e(), (_vm.message !== '') ? _c('div', {
staticClass: "el-message-box__content"
}, [_c('div', {
staticClass: "el-message-box__status",
class: [_vm.typeClass]
}), _c('div', {
staticClass: "el-message-box__message",
style: ({
'margin-left': _vm.typeClass ? '50px' : '0'
})
}, [_c('p', [_vm._v(_vm._s(_vm.message))])]), _c('div', {
directives: [{
name: "show",
rawName: "v-show",
value: (_vm.showInput),
expression: "showInput"
}],
staticClass: "el-message-box__input"
}, [_c('el-input', {
directives: [{
name: "model",
rawName: "v-model",
value: (_vm.inputValue),
expression: "inputValue"
}],
ref: "input",
attrs: {
"placeholder": _vm.inputPlaceholder
},
domProps: {
"value": (_vm.inputValue)
},
on: {
"input": function($event) {
_vm.inputValue = $event
}
},
nativeOn: {
"keyup": function($event) {
if (_vm._k($event.keyCode, "enter", 13)) { return; }
_vm.handleAction('confirm')
}
}
}), _c('div', {
staticClass: "el-message-box__errormsg",
style: ({
visibility: !!_vm.editorErrorMessage ? 'visible' : 'hidden'
})
}, [_vm._v(_vm._s(_vm.editorErrorMessage))])], 1)]) : _vm._e(), _c('div', {
staticClass: "el-message-box__btns"
}, [_c('el-button', {
directives: [{
name: "show",
rawName: "v-show",
value: (_vm.showCancelButton),
expression: "showCancelButton"
}],
class: [_vm.cancelButtonClasses],
attrs: {
"loading": _vm.cancelButtonLoading
},
nativeOn: {
"click": function($event) {
_vm.handleAction('cancel')
}
}
}, [_vm._v("\n " + _vm._s(_vm.cancelButtonText || _vm.t('el.messagebox.cancel')) + "\n ")]), _c('el-button', {
directives: [{
name: "show",
rawName: "v-show",
value: (_vm.showConfirmButton),
expression: "showConfirmButton"
}],
ref: "confirm",
class: [_vm.confirmButtonClasses],
attrs: {
"loading": _vm.confirmButtonLoading
},
nativeOn: {
"click": function($event) {
_vm.handleAction('confirm')
}
}
}, [_vm._v("\n " + _vm._s(_vm.confirmButtonText || _vm.t('el.messagebox.confirm')) + "\n ")])], 1)])])])
},staticRenderFns: []}
/***/ }
/******/ });