|
15 | 15 | boxWidth = $boxElement.outerWidth(true),
|
16 | 16 | boxHeight = $boxElement.outerHeight(true),
|
17 | 17 | top, left, right, bottom;
|
18 |
| - if ((options.top !== undefined || options.bottom !== undefined) && (options.left !== undefined || options.right !== undefined)) { |
19 |
| - top = options.top; |
20 |
| - bottom = options.bottom; |
21 |
| - left = options.left; |
22 |
| - right = options.right; |
23 |
| - } else { |
24 |
| - var calLeftRight = function () { |
25 |
| - if (options.align === "left") { |
26 |
| - left = elementLeft; |
27 |
| - if (left + boxWidth > docClientWidth) { |
28 |
| - left = docClientWidth - boxWidth - options.offset; |
29 |
| - } |
30 |
| - } else if (options.align === "right") { |
31 |
| - right = docClientWidth - elementLeft - elementOuterWidth; |
32 |
| - left = undefined; |
33 |
| - if (right + boxWidth > docClientWidth) { |
34 |
| - right = options.offset; |
35 |
| - } |
| 18 | + if (options.top !== undefined && options.left !== undefined) { |
| 19 | + elementTop = options.top; |
| 20 | + elementLeft = options.left; |
| 21 | + elementOuterWidth = 0; |
| 22 | + elementOuterHeight = 0; |
| 23 | + } |
| 24 | + |
| 25 | + var calLeftRight = function () { |
| 26 | + if (options.align === "left") { |
| 27 | + left = elementLeft; |
| 28 | + if (left + boxWidth > docClientWidth) { |
| 29 | + left = docClientWidth - boxWidth - options.offset; |
36 | 30 | }
|
37 |
| - else { |
38 |
| - left = elementLeft - boxWidth / 2 + elementOuterWidth / 2; |
39 |
| - if (left < 0) { |
40 |
| - left = options.offset; |
41 |
| - } else if (left + boxWidth > docClientWidth) { |
42 |
| - left = docClientWidth - boxWidth - options.offset; |
43 |
| - } |
| 31 | + } else if (options.align === "right") { |
| 32 | + right = docClientWidth - elementLeft - elementOuterWidth; |
| 33 | + left = undefined; |
| 34 | + if (right + boxWidth > docClientWidth) { |
| 35 | + right = options.offset; |
44 | 36 | }
|
45 |
| - }; |
| 37 | + } |
| 38 | + else { |
| 39 | + left = elementLeft - boxWidth / 2 + elementOuterWidth / 2; |
| 40 | + if (left < 0) { |
| 41 | + left = options.offset; |
| 42 | + } else if (left + boxWidth > docClientWidth) { |
| 43 | + left = docClientWidth - boxWidth - options.offset; |
| 44 | + } |
| 45 | + } |
| 46 | + }; |
46 | 47 |
|
47 |
| - var calTopBottom = function () { |
48 |
| - if (options.align === "top") { |
49 |
| - top = elementTop; |
50 |
| - if (top + boxHeight > docClientHeight) { |
51 |
| - top = docClientHeight - boxHeight; |
52 |
| - } |
53 |
| - } else if (options.align === "bottom") { |
54 |
| - bottom = docClientHeight - elementTop - elementOuterHeight; |
55 |
| - if (bottom + boxHeight > docClientHeight) { |
56 |
| - bottom = docClientHeight - boxHeight; |
57 |
| - } |
| 48 | + var calTopBottom = function () { |
| 49 | + if (options.align === "top") { |
| 50 | + top = elementTop; |
| 51 | + if (top + boxHeight > docClientHeight) { |
| 52 | + top = docClientHeight - boxHeight; |
58 | 53 | }
|
59 |
| - else { |
60 |
| - top = ~~(elementTop - boxHeight / 2 + elementOuterHeight / 2); |
61 |
| - if (top < 0) { |
62 |
| - top = options.offset; |
63 |
| - } else if (top + boxHeight > docClientHeight) { |
64 |
| - top = docClientHeight - boxHeight + options.offset; |
65 |
| - } |
| 54 | + } else if (options.align === "bottom") { |
| 55 | + bottom = docClientHeight - elementTop - elementOuterHeight; |
| 56 | + if (bottom + boxHeight > docClientHeight) { |
| 57 | + bottom = docClientHeight - boxHeight; |
66 | 58 | }
|
67 |
| - }; |
| 59 | + } |
| 60 | + else { |
| 61 | + top = ~~(elementTop - boxHeight / 2 + elementOuterHeight / 2); |
| 62 | + if (top < 0) { |
| 63 | + top = options.offset; |
| 64 | + } else if (top + boxHeight > docClientHeight) { |
| 65 | + top = docClientHeight - boxHeight + options.offset; |
| 66 | + } |
| 67 | + } |
| 68 | + }; |
68 | 69 |
|
69 |
| - switch (options.placement) { |
70 |
| - case "bottom": |
71 |
| - top = elementTop + elementOuterHeight + options.offset; |
72 |
| - calLeftRight(); |
73 |
| - if (options.autoAdapt && top + boxHeight > docClientHeight) { |
74 |
| - top = undefined; |
75 |
| - bottom = docClientHeight - elementTop + options.offset; |
76 |
| - if (bottom + boxHeight > docClientHeight) { |
77 |
| - top = options.offset; |
78 |
| - bottom = undefined; |
79 |
| - } |
80 |
| - } |
81 |
| - break; |
82 |
| - case "top": |
| 70 | + switch (options.placement) { |
| 71 | + case "bottom": |
| 72 | + top = elementTop + elementOuterHeight + options.offset; |
| 73 | + calLeftRight(); |
| 74 | + if (options.autoAdapt && top + boxHeight > docClientHeight) { |
| 75 | + top = undefined; |
83 | 76 | bottom = docClientHeight - elementTop + options.offset;
|
84 |
| - if (options.autoAdapt && bottom + boxHeight > docClientHeight) { |
| 77 | + if (bottom + boxHeight > docClientHeight) { |
| 78 | + top = options.offset; |
85 | 79 | bottom = undefined;
|
86 |
| - top = elementTop + elementOuterHeight + options.offset; |
87 |
| - if (top + boxHeight > docClientWidth) { |
88 |
| - top = undefined; |
89 |
| - bottom = docClientHeight - boxHeight + options.offset; |
90 |
| - } |
91 | 80 | }
|
92 |
| - calLeftRight(); |
93 |
| - break; |
94 |
| - case "left": |
95 |
| - right = ~~(docClientWidth - elementLeft + options.offset); |
96 |
| - if (options.autoAdapt && right + boxWidth + options.offset > docClientWidth) { |
97 |
| - right = undefined; |
98 |
| - left = ~~(elementLeft + elementOuterWidth + options.offset); |
99 |
| - } |
100 |
| - calTopBottom(); |
101 |
| - break; |
102 |
| - case "right": |
103 |
| - left = elementLeft + elementOuterWidth + options.offset; |
104 |
| - if (options.autoAdapt && left + boxWidth + options.offset > docClientWidth) { |
105 |
| - left = undefined; |
106 |
| - right = docClientWidth - elementLeft + options.offset; |
| 81 | + } |
| 82 | + break; |
| 83 | + case "top": |
| 84 | + bottom = docClientHeight - elementTop + options.offset; |
| 85 | + if (options.autoAdapt && bottom + boxHeight > docClientHeight) { |
| 86 | + bottom = undefined; |
| 87 | + top = elementTop + elementOuterHeight + options.offset; |
| 88 | + if (top + boxHeight > docClientWidth) { |
| 89 | + top = undefined; |
| 90 | + bottom = docClientHeight - boxHeight + options.offset; |
107 | 91 | }
|
108 |
| - calTopBottom(); |
109 |
| - break; |
110 |
| - default: |
111 |
| - break; |
112 |
| - } |
| 92 | + } |
| 93 | + calLeftRight(); |
| 94 | + break; |
| 95 | + case "left": |
| 96 | + right = ~~(docClientWidth - elementLeft + options.offset); |
| 97 | + if (options.autoAdapt && right + boxWidth + options.offset > docClientWidth) { |
| 98 | + right = undefined; |
| 99 | + left = ~~(elementLeft + elementOuterWidth + options.offset); |
| 100 | + } |
| 101 | + calTopBottom(); |
| 102 | + break; |
| 103 | + case "right": |
| 104 | + left = elementLeft + elementOuterWidth + options.offset; |
| 105 | + if (options.autoAdapt && left + boxWidth + options.offset > docClientWidth) { |
| 106 | + left = undefined; |
| 107 | + right = docClientWidth - elementLeft + options.offset; |
| 108 | + } |
| 109 | + calTopBottom(); |
| 110 | + break; |
| 111 | + default: |
| 112 | + break; |
113 | 113 | }
|
114 | 114 |
|
115 | 115 | if (top !== undefined) {
|
|
0 commit comments