Skip to content

Commit 12d9925

Browse files
'message' support HTML template
1 parent 1f4dd3c commit 12d9925

File tree

2 files changed

+34
-29
lines changed

2 files changed

+34
-29
lines changed

src/index.js

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -50,39 +50,41 @@ var MessageBoxConstructor = Vue.extend(msgboxVue);
5050
var currentMsg, instance;
5151
var msgQueue = [];
5252

53-
var initInstance = function() {
54-
instance = new MessageBoxConstructor({
55-
el: document.createElement('div')
56-
});
57-
58-
instance.callback = function(action) {
59-
if (currentMsg) {
60-
var callback = currentMsg.callback;
61-
if (typeof callback === 'function') {
62-
if (instance.showInput) {
63-
callback(instance.inputValue, action);
64-
} else {
65-
callback(action);
66-
}
53+
const defaultCallback = action => {
54+
if (currentMsg) {
55+
var callback = currentMsg.callback;
56+
if (typeof callback === 'function') {
57+
if (instance.showInput) {
58+
callback(instance.inputValue, action);
59+
} else {
60+
callback(action);
6761
}
68-
if (currentMsg.resolve) {
69-
var $type = currentMsg.options.$type;
70-
if ($type === 'confirm' || $type === 'prompt') {
71-
if (action === 'confirm') {
72-
if (instance.showInput) {
73-
currentMsg.resolve({ value: instance.inputValue, action });
74-
} else {
75-
currentMsg.resolve(action);
76-
}
77-
} else if (action === 'cancel' && currentMsg.reject) {
78-
currentMsg.reject(action);
62+
}
63+
if (currentMsg.resolve) {
64+
var $type = currentMsg.options.$type;
65+
if ($type === 'confirm' || $type === 'prompt') {
66+
if (action === 'confirm') {
67+
if (instance.showInput) {
68+
currentMsg.resolve({ value: instance.inputValue, action });
69+
} else {
70+
currentMsg.resolve(action);
7971
}
80-
} else {
81-
currentMsg.resolve(action);
72+
} else if (action === 'cancel' && currentMsg.reject) {
73+
currentMsg.reject(action);
8274
}
75+
} else {
76+
currentMsg.resolve(action);
8377
}
8478
}
85-
};
79+
}
80+
};
81+
82+
var initInstance = function() {
83+
instance = new MessageBoxConstructor({
84+
el: document.createElement('div')
85+
});
86+
87+
instance.callback = defaultCallback;
8688
};
8789

8890
var showNextMsg = function() {
@@ -100,6 +102,9 @@ var showNextMsg = function() {
100102
instance[prop] = options[prop];
101103
}
102104
}
105+
if (options.callback === undefined) {
106+
instance.callback = defaultCallback;
107+
}
103108
['modal', 'showClose', 'closeOnClickModal', 'closeOnPressEscape'].forEach(prop => {
104109
if (instance[prop] === undefined) {
105110
instance[prop] = true;

src/msgbox.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<div class="mint-msgbox-title">{{ title }}</div>
77
</div>
88
<div class="mint-msgbox-content" v-if="message !== ''">
9-
<div class="mint-msgbox-message"><p>{{ message }}</p></div>
9+
<div class="mint-msgbox-message" v-html="message"></div>
1010
<div class="mint-msgbox-input" v-show="showInput">
1111
<input v-model="inputValue" :placeholder="inputPlaceholder" ref="input">
1212
<div class="mint-msgbox-errormsg" :style="{ visibility: !!editorErrorMessage ? 'visible' : 'hidden' }">{{ editorErrorMessage }}</div>

0 commit comments

Comments
 (0)