7570318b
梁灏
fixed Tooltip pla...
|
1
2
3
|
/**
* https://github.com/freeze-component/vue-popper
* */
|
a68c11a5
梁灏
support Nuxt.js
|
4
5
|
import Vue from 'vue';
const isServer = Vue.prototype.$isServer;
|
3684e716
Aresn
SSR support
|
6
|
const Popper = isServer ? function() {} : require('popper.js/dist/umd/popper.js'); // eslint-disable-line
|
dce3e753
梁灏
add Tooltip compo...
|
7
|
|
dce3e753
梁灏
add Tooltip compo...
|
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
export default {
props: {
placement: {
type: String,
default: 'bottom'
},
boundariesPadding: {
type: Number,
default: 5
},
reference: Object,
popper: Object,
offset: {
default: 0
},
|
d6f644e1
梁灏
support Tooltip
|
23
24
25
26
|
value: {
type: Boolean,
default: false
},
|
dce3e753
梁灏
add Tooltip compo...
|
27
28
29
30
|
transition: String,
options: {
type: Object,
default () {
|
7570318b
梁灏
fixed Tooltip pla...
|
31
|
return {
|
130ea92a
huanghong
update popper.js
|
32
33
34
|
modifiers: {
computeStyle:{
gpuAcceleration: false,
|
81f88959
梁灏
update Poptip opt...
|
35
36
|
},
preventOverflow :{
|
354254b4
梁灏
change popper.js ...
|
37
|
boundariesElement: 'window'
|
130ea92a
huanghong
update popper.js
|
38
|
}
|
130ea92a
huanghong
update popper.js
|
39
|
}
|
b0893113
jingsam
add eslint
|
40
|
};
|
dce3e753
梁灏
add Tooltip compo...
|
41
|
}
|
9699c270
梁灏
add Poptip component
|
42
|
},
|
d6f644e1
梁灏
support Tooltip
|
43
44
45
46
47
48
49
50
|
// visible: {
// type: Boolean,
// default: false
// }
},
data () {
return {
visible: this.value
|
79288d43
梁灏
support Poptip & ...
|
51
|
};
|
dce3e753
梁灏
add Tooltip compo...
|
52
|
},
|
dce3e753
梁灏
add Tooltip compo...
|
53
54
55
56
|
watch: {
value: {
immediate: true,
handler(val) {
|
9699c270
梁灏
add Poptip component
|
57
|
this.visible = val;
|
dce3e753
梁灏
add Tooltip compo...
|
58
59
60
|
this.$emit('input', val);
}
},
|
9699c270
梁灏
add Poptip component
|
61
|
visible(val) {
|
7f1edb6a
梁灏
Poptip、Tooltip ad...
|
62
|
if (val) {
|
a809f2a4
梁灏
update popper.js ...
|
63
|
if (this.handleIndexIncrease) this.handleIndexIncrease(); // just use for Poptip
|
7f1edb6a
梁灏
Poptip、Tooltip ad...
|
64
|
this.updatePopper();
|
62f5dd0c
梁灏
fixed #1684
|
65
|
this.$emit('on-popper-show');
|
7f1edb6a
梁灏
Poptip、Tooltip ad...
|
66
|
} else {
|
7f1edb6a
梁灏
Poptip、Tooltip ad...
|
67
68
|
this.$emit('on-popper-hide');
}
|
dce3e753
梁灏
add Tooltip compo...
|
69
70
71
72
73
|
this.$emit('input', val);
}
},
methods: {
createPopper() {
|
a68c11a5
梁灏
support Nuxt.js
|
74
|
if (isServer) return;
|
dce3e753
梁灏
add Tooltip compo...
|
75
76
77
78
79
|
if (!/^(top|bottom|left|right)(-start|-end)?$/g.test(this.placement)) {
return;
}
const options = this.options;
|
d6f644e1
梁灏
support Tooltip
|
80
81
|
const popper = this.popper || this.$refs.popper;
const reference = this.reference || this.$refs.reference;
|
dce3e753
梁灏
add Tooltip compo...
|
82
83
|
if (!popper || !reference) return;
|
dce3e753
梁灏
add Tooltip compo...
|
84
85
86
87
88
89
|
if (this.popperJS && this.popperJS.hasOwnProperty('destroy')) {
this.popperJS.destroy();
}
options.placement = this.placement;
|
81f88959
梁灏
update Poptip opt...
|
90
|
|
e8139eac
huanghong
update popper
|
91
|
if (!options.modifiers.offset) {
|
130ea92a
huanghong
update popper.js
|
92
93
|
options.modifiers.offset = {};
}
|
9734ab0f
Chuanfeng
update popper.js ...
|
94
|
options.modifiers.offset.offset = this.offset;
|
130ea92a
huanghong
update popper.js
|
95
|
options.onCreate =()=>{
|
755df66c
梁灏
update Tooltip
|
96
97
|
this.$nextTick(this.updatePopper);
this.$emit('created', this);
|
130ea92a
huanghong
update popper.js
|
98
99
100
|
};
this.popperJS = new Popper(reference, popper, options);
|
9734ab0f
Chuanfeng
update popper.js ...
|
101
|
|
dce3e753
梁灏
add Tooltip compo...
|
102
103
|
},
updatePopper() {
|
a68c11a5
梁灏
support Nuxt.js
|
104
|
if (isServer) return;
|
755df66c
梁灏
update Tooltip
|
105
|
this.popperJS ? this.popperJS.update() : this.createPopper();
|
dce3e753
梁灏
add Tooltip compo...
|
106
107
|
},
doDestroy() {
|
a68c11a5
梁灏
support Nuxt.js
|
108
|
if (isServer) return;
|
9699c270
梁灏
add Poptip component
|
109
|
if (this.visible) return;
|
dce3e753
梁灏
add Tooltip compo...
|
110
111
|
this.popperJS.destroy();
this.popperJS = null;
|
dce3e753
梁灏
add Tooltip compo...
|
112
113
|
}
},
|
f0116c03
huanghong
update poptip con...
|
114
115
|
updated (){
this.$nextTick(()=>this.updatePopper());
|
9734ab0f
Chuanfeng
update popper.js ...
|
116
|
|
f0116c03
huanghong
update poptip con...
|
117
|
},
|
dce3e753
梁灏
add Tooltip compo...
|
118
|
beforeDestroy() {
|
a68c11a5
梁灏
support Nuxt.js
|
119
|
if (isServer) return;
|
dce3e753
梁灏
add Tooltip compo...
|
120
121
122
123
|
if (this.popperJS) {
this.popperJS.destroy();
}
}
|
b0893113
jingsam
add eslint
|
124
|
};
|