|
7 | 7 | calculatePos: function (options, $element, $boxElement) { |
8 | 8 | var elementTop = $element.offset().top, |
9 | 9 | elementLeft = $element.offset().left, |
10 | | - docOuterWidth = $document.outerWidth(), |
11 | | - docOuterHeight = $document.outerHeight(), |
| 10 | + docClientWidth = document.documentElement.clientWidth, |
| 11 | + docClientHeight = document.documentElement.clientHeight, |
| 12 | + |
12 | 13 | elementOuterWidth = $element.outerWidth(), |
13 | 14 | elementOuterHeight = $element.outerHeight(), |
14 | 15 | boxWidth = $boxElement.outerWidth(true), |
|
20 | 21 | left = options.left; |
21 | 22 | right = options.right; |
22 | 23 | } else { |
23 | | - switch (options.placement) { |
24 | | - case "bottom": |
25 | | - top = elementTop + elementOuterHeight + options.offset; |
26 | | - if (options.align === "left") { |
27 | | - left = elementLeft; |
28 | | - } else if (options.align === "right") { |
29 | | - left = elementLeft + elementOuterWidth - boxWidth; |
| 24 | + var calLeftRight = function () { |
| 25 | + if (options.align === "left") { |
| 26 | + left = elementLeft; |
| 27 | + if (left + boxWidth > docClientWidth) { |
| 28 | + left = docClientWidth - boxWidth - options.offset; |
30 | 29 | } |
31 | | - else { |
32 | | - left = elementLeft - boxWidth / 2 + elementOuterWidth / 2; |
| 30 | + } else if (options.align === "right") { |
| 31 | + right = docClientWidth - elementLeft - elementOuterWidth; |
| 32 | + left = undefined; |
| 33 | + if (right + boxWidth > docClientWidth) { |
| 34 | + right = options.offset; |
33 | 35 | } |
34 | | - |
| 36 | + } |
| 37 | + else { |
| 38 | + left = elementLeft - boxWidth / 2 + elementOuterWidth / 2; |
35 | 39 | if (left < 0) { |
36 | 40 | left = options.offset; |
| 41 | + } else if (left + boxWidth > docClientWidth) { |
| 42 | + left = docClientWidth - boxWidth - options.offset; |
37 | 43 | } |
38 | | - if (left + boxWidth > docOuterWidth) { |
39 | | - left = docOuterWidth - boxWidth - options.offset; |
40 | | - } |
41 | | - if (top + boxHeight > docOuterHeight) { |
42 | | - top = elementTop - boxHeight - options.offset; |
| 44 | + } |
| 45 | + }; |
| 46 | + |
| 47 | + var calTopBottom = function(){ |
| 48 | + if (options.align === "top") { |
| 49 | + top = elementTop; |
| 50 | + if (top + boxHeight > docClientHeight) { |
| 51 | + top = docClientHeight - boxHeight; |
43 | 52 | } |
44 | | - break; |
45 | | - case "top": |
46 | | - top = elementTop - boxHeight - options.offset; |
47 | | - left = elementLeft; |
48 | | - if (options.align === "left") { |
49 | | - left = elementLeft; |
50 | | - } else if (options.align === "right") { |
51 | | - left = elementLeft + elementOuterWidth - boxWidth; |
| 53 | + } else if (options.align === "bottom") { |
| 54 | + bottom = docClientHeight - elementTop - elementOuterHeight; |
| 55 | + if (bottom + boxHeight > docClientHeight) { |
| 56 | + bottom = docClientHeight - boxHeight; |
52 | 57 | } |
53 | | - else { |
54 | | - left = elementLeft - boxWidth / 2 + elementOuterWidth / 2; |
| 58 | + } |
| 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; |
55 | 65 | } |
| 66 | + } |
| 67 | + }; |
56 | 68 |
|
57 | | - if (left < 0) { |
58 | | - left = options.offset; |
59 | | - } |
60 | | - if (left + boxWidth > docOuterWidth) { |
61 | | - left = docOuterWidth - boxWidth - options.offset; |
| 69 | + switch (options.placement) { |
| 70 | + case "bottom": |
| 71 | + top = elementTop + elementOuterHeight + options.offset; |
| 72 | + calLeftRight(); |
| 73 | + if (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 | + } |
62 | 80 | } |
63 | | - if (top < boxHeight) { |
| 81 | + break; |
| 82 | + case "top": |
| 83 | + bottom = docClientHeight - elementTop + options.offset; |
| 84 | + if (bottom + boxHeight > docClientHeight) { |
| 85 | + bottom = undefined; |
64 | 86 | top = elementTop + elementOuterHeight + options.offset; |
| 87 | + if (top + boxHeight > docClientWidth) { |
| 88 | + top = undefined; |
| 89 | + bottom = docClientHeight - boxHeight + options.offset; |
| 90 | + } |
65 | 91 | } |
| 92 | + calLeftRight(); |
66 | 93 | break; |
67 | 94 | case "left": |
68 | | - right = ~~(docOuterWidth - elementLeft + options.offset); |
69 | | - if (right + boxWidth + options.offset > docOuterWidth) { |
| 95 | + right = ~~(docClientWidth - elementLeft + options.offset); |
| 96 | + if (right + boxWidth + options.offset > docClientWidth) { |
70 | 97 | right = undefined; |
71 | 98 | left = ~~(elementLeft + elementOuterWidth + options.offset); |
72 | 99 | } |
73 | | - if (options.align === "top") { |
74 | | - top = elementTop; |
75 | | - } else if (options.align === "bottom") { |
76 | | - top = elementTop + elementOuterHeight - boxHeight; |
77 | | - } |
78 | | - else { |
79 | | - top = ~~(elementTop - boxHeight / 2 + elementOuterHeight / 2); |
80 | | - } |
81 | | - |
82 | | - if (top < 0) { |
83 | | - top = options.offset; |
84 | | - } else if (top + boxHeight > docOuterHeight) { |
85 | | - top = docOuterHeight - boxHeight - options.offset; |
86 | | - } |
| 100 | + calTopBottom(); |
87 | 101 | break; |
88 | 102 | case "right": |
89 | 103 | left = elementLeft + elementOuterWidth + options.offset; |
90 | | - if (left + boxWidth + options.offset > docOuterWidth) { |
| 104 | + if (left + boxWidth + options.offset > docClientWidth) { |
91 | 105 | left = undefined; |
92 | | - right = docOuterWidth - elementLeft + options.offset; |
93 | | - } |
94 | | - if (options.align === "top") { |
95 | | - top = elementTop; |
96 | | - } else if (options.align === "bottom") { |
97 | | - top = elementTop + elementOuterHeight - boxHeight; |
98 | | - } |
99 | | - else { |
100 | | - top = elementTop - boxHeight / 2 + elementOuterHeight / 2; |
101 | | - } |
102 | | - |
103 | | - if (top < 0) { |
104 | | - top = options.offset; |
105 | | - } else if (top + boxHeight > docOuterHeight) { |
106 | | - top = docOuterHeight - boxHeight - options.offset; |
| 106 | + right = docClientWidth - elementLeft + options.offset; |
107 | 107 | } |
| 108 | + calTopBottom(); |
108 | 109 | break; |
109 | 110 | default: |
110 | 111 | break; |
|
138 | 139 | .provider("$pbox", [function () { |
139 | 140 | // The default options for all popboxs. |
140 | 141 | var defaultOptions = { |
141 | | - placement: 'bottom', |
142 | | - align: null, |
143 | | - animation: false, |
| 142 | + placement : 'bottom', |
| 143 | + align : null, |
| 144 | + animation : false, |
144 | 145 | popupDelay: 0, |
145 | | - arrow: false, |
146 | | - openClass: 'pbox-open', |
| 146 | + arrow : false, |
| 147 | + openClass : 'pbox-open', |
147 | 148 | closeClass: 'pbox-close', |
148 | | - autoClose: true, |
149 | | - offset: 1, |
150 | | - resolve: {} |
| 149 | + autoClose : true, |
| 150 | + offset : 1, |
| 151 | + resolve : {} |
151 | 152 | }; |
152 | 153 |
|
153 | 154 | var globalOptions = { |
154 | | - triggerClass: "pbox-trigger", |
| 155 | + triggerClass : "pbox-trigger", |
155 | 156 | boxInstanceName: "boxInstance" |
156 | 157 | }; |
157 | 158 |
|
|
160 | 161 | }; |
161 | 162 |
|
162 | 163 | var util = { |
163 | | - hasClass: function (element, className) { |
| 164 | + hasClass : function (element, className) { |
164 | 165 | return element.hasClass(className) || element.parents("." + className).length > 0; |
165 | 166 | }, |
166 | 167 | hasClasses: function (element, classes) { |
|
173 | 174 | }); |
174 | 175 | return result; |
175 | 176 | }, |
176 | | - getTarget: function (event) { |
| 177 | + getTarget : function (event) { |
177 | 178 | var $target = angular.element(event.target); |
178 | 179 | if (!$target) { |
179 | 180 | throw new Error("The event") |
|
0 commit comments