1
|
import { isRtl, flipPosition, position, removeClass, toNumber } from '../util/index';
|
2
|
|
3
|
export default {
|
4
|
|
5
|
props: {
|
6
|
pos: String,
|
7
|
offset: null,
|
8
|
flip: Boolean,
|
9
|
clsPos: String
|
10
|
},
|
11
|
|
12
|
defaults: {
|
13
|
pos: !isRtl ? 'bottom-left' : 'bottom-right',
|
14
|
flip: true,
|
15
|
offset: false,
|
16
|
clsPos: ''
|
17
|
},
|
18
|
|
19
|
computed: {
|
20
|
|
21
|
pos() {
|
22
|
return (this.$props.pos + (!~this.$props.pos.indexOf('-') ? '-center' : '')).split('-');
|
23
|
},
|
24
|
|
25
|
dir() {
|
26
|
return this.pos[0];
|
27
|
},
|
28
|
|
29
|
align() {
|
30
|
return this.pos[1];
|
31
|
}
|
32
|
|
33
|
},
|
34
|
|
35
|
methods: {
|
36
|
|
37
|
positionAt(element, target, boundary) {
|
38
|
|
39
|
removeClass(element, `${this.clsPos}-(top|bottom|left|right)(-[a-z]+)?`).css({top: '', left: ''});
|
40
|
|
41
|
var offset = toNumber(this.offset) || 0,
|
42
|
axis = this.getAxis(),
|
43
|
flipped = position(
|
44
|
element,
|
45
|
target,
|
46
|
axis === 'x' ? `${flipPosition(this.dir)} ${this.align}` : `${this.align} ${flipPosition(this.dir)}`,
|
47
|
axis === 'x' ? `${this.dir} ${this.align}` : `${this.align} ${this.dir}`,
|
48
|
axis === 'x' ? `${this.dir === 'left' ? -1 * offset : offset}` : ` ${this.dir === 'top' ? -1 * offset : offset}`,
|
49
|
null,
|
50
|
this.flip,
|
51
|
boundary
|
52
|
);
|
53
|
|
54
|
this.dir = axis === 'x' ? flipped.target.x : flipped.target.y;
|
55
|
this.align = axis === 'x' ? flipped.target.y : flipped.target.x;
|
56
|
|
57
|
element.toggleClass(`${this.clsPos}-${this.dir}-${this.align}`, this.offset === false);
|
58
|
|
59
|
},
|
60
|
|
61
|
getAxis() {
|
62
|
return this.dir === 'top' || this.dir === 'bottom' ? 'y' : 'x';
|
63
|
}
|
64
|
|
65
|
}
|
66
|
|
67
|
}
|