|
9 | 9 | calculatePos: function (options, $element, $boxElement) { |
10 | 10 | var elementTop = $element.offset().top, |
11 | 11 | elementLeft = $element.offset().left, |
12 | | - dicOuterWidth = $document.outerWidth(), |
13 | | - dicOuterHeight = $document.outerHeight(), |
| 12 | + docOuterWidth = $document.outerWidth(), |
| 13 | + docOuterHeight = $document.outerHeight(), |
14 | 14 | elementOuterWidth = $element.outerWidth(), |
15 | 15 | elementOuterHeight = $element.outerHeight(), |
16 | 16 | boxWidth = $boxElement.outerWidth(true), |
|
31 | 31 | if (left < 0) { |
32 | 32 | left = options.offset; |
33 | 33 | } |
34 | | - if (left + boxWidth > dicOuterWidth) { |
35 | | - left = dicOuterWidth - boxWidth - options.offset; |
| 34 | + if (left + boxWidth > docOuterWidth) { |
| 35 | + left = docOuterWidth - boxWidth - options.offset; |
36 | 36 | } |
37 | | - if (top + boxHeight > dicOuterHeight) { |
| 37 | + if (top + boxHeight > docOuterHeight) { |
38 | 38 | top = elementTop - boxHeight - options.offset; |
39 | 39 | } |
40 | 40 | break; |
|
53 | 53 | if (left < 0) { |
54 | 54 | left = options.offset; |
55 | 55 | } |
56 | | - if (left + boxWidth > dicOuterWidth) { |
57 | | - left = dicOuterWidth - boxWidth - options.offset; |
| 56 | + if (left + boxWidth > docOuterWidth) { |
| 57 | + left = docOuterWidth - boxWidth - options.offset; |
58 | 58 | } |
59 | 59 | if (top < boxHeight) { |
60 | 60 | top = elementTop + elementOuterHeight + options.offset; |
61 | 61 | } |
62 | 62 | break; |
63 | 63 | case "left": |
64 | | - left = elementLeft - boxWidth - options.offset; |
| 64 | + right = ~~(docOuterWidth - elementLeft + options.offset); |
| 65 | + if (right + boxWidth + options.offset > docOuterWidth) { |
| 66 | + right = 0; |
| 67 | + left = ~~(elementLeft + elementOuterWidth + options.offset); |
| 68 | + } |
65 | 69 | if (options.align === "top") { |
66 | 70 | top = elementTop; |
67 | 71 | } else if (options.align === "bottom") { |
68 | 72 | top = elementTop + elementOuterHeight - boxHeight; |
69 | 73 | } |
70 | 74 | else { |
71 | | - top = elementTop - boxHeight / 2 + elementOuterHeight / 2; |
72 | | - } |
73 | | - if (left < 0) { |
74 | | - left = elementLeft + elementOuterWidth + options.offset; |
75 | | - } else if (left + boxWidth > dicOuterWidth) { |
76 | | - left = elementLeft + elementOuterWidth + options.offset; |
| 75 | + top = ~~(elementTop - boxHeight / 2 + elementOuterHeight / 2); |
77 | 76 | } |
| 77 | + |
78 | 78 | if (top < 0) { |
79 | 79 | top = options.offset; |
80 | | - } else if (top + boxHeight > dicOuterHeight) { |
81 | | - top = dicOuterHeight - boxHeight - options.offset; |
| 80 | + } else if (top + boxHeight > docOuterHeight) { |
| 81 | + top = docOuterHeight - boxHeight - options.offset; |
82 | 82 | } |
83 | 83 | break; |
84 | 84 | case "right": |
| 85 | + left = elementLeft + elementOuterWidth + options.offset; |
| 86 | + if(left + boxWidth + options.offset > docOuterWidth){ |
| 87 | + left = 0; |
| 88 | + right = docOuterWidth - elementLeft + options.offset; |
| 89 | + } |
| 90 | + if (options.align === "top") { |
| 91 | + top = elementTop; |
| 92 | + } else if (options.align === "bottom") { |
| 93 | + top = elementTop + elementOuterHeight - boxHeight; |
| 94 | + } |
| 95 | + else { |
| 96 | + top = elementTop - boxHeight / 2 + elementOuterHeight / 2; |
| 97 | + } |
| 98 | + |
| 99 | + if (top < 0) { |
| 100 | + top = options.offset; |
| 101 | + } else if (top + boxHeight > docOuterHeight) { |
| 102 | + top = docOuterHeight - boxHeight - options.offset; |
| 103 | + } |
85 | 104 | break; |
86 | 105 | default: |
87 | 106 | break; |
88 | 107 | } |
89 | 108 |
|
90 | | - if (top !== undefined) { |
| 109 | + if (top) { |
91 | 110 | $boxElement.css("top", top); |
92 | 111 | } |
93 | | - if (bottom !== undefined) { |
| 112 | + if (bottom) { |
94 | 113 | $boxElement.css("bottom", bottom); |
95 | 114 | } |
96 | | - if (left !== undefined) { |
| 115 | + if (left) { |
97 | 116 | $boxElement.css("left", left); |
98 | 117 | } |
99 | | - if (right !== undefined) { |
| 118 | + if (right) { |
100 | 119 | $boxElement.css("right", right); |
101 | 120 | } |
102 | 121 |
|
|
229 | 248 | isResult = true; |
230 | 249 | } |
231 | 250 | } |
232 | | - if(isResult){ |
| 251 | + if (isResult) { |
233 | 252 | return; |
234 | 253 | } |
235 | 254 | } |
|
244 | 263 |
|
245 | 264 | $compile(this._pboxElement)(scope); |
246 | 265 | $body.append(this._pboxElement); |
247 | | - |
248 | | - $wtPosition.calculatePos(options, $target, this._pboxElement); |
| 266 | + $timeout(function () { |
| 267 | + $wtPosition.calculatePos(options, $target, _self._pboxElement); |
| 268 | + }); |
249 | 269 | this._bindEvents(); |
250 | 270 | }; |
251 | 271 |
|
|
308 | 328 | pboxInstance.ctrlInstance = ctrlInstance; |
309 | 329 | } |
310 | 330 |
|
311 | | - pboxInstance.open(tplAndVars[0],pboxScope); |
| 331 | + pboxInstance.open(tplAndVars[0], pboxScope); |
312 | 332 |
|
313 | 333 | }, function resolveError(reason) { |
314 | 334 | pboxInstance.resultDeferred.reject(reason); |
|
0 commit comments