252 | | windowScroll = panelWindow.getScrollPosition(), |
253 | | viewportSize = panelWindow.getViewPaneSize(), |
254 | | panelSize = |
255 | | { |
256 | | 'height' : panelElement.$.offsetHeight, |
257 | | 'width' : panelElement.$.offsetWidth |
258 | | }; |
| 257 | rect = element.$.getBoundingClientRect(), |
| 258 | viewportSize = panelWindow.getViewPaneSize(); |
| 259 | |
| 260 | // Compensation for browsers that dont support "width" and "height". |
| 261 | var rectWidth = rect.width || rect.right - rect.left, |
| 262 | rectHeight = rect.height || rect.bottom - rect.top; |
| 263 | |
| 264 | // Check if default horizontal layout is impossible. |
| 265 | var spaceAfter = rtl ? rect.right : viewportSize.width - rect.left, |
| 266 | spaceBefore = rtl ? viewportSize.width - rect.right : rect.left; |
| 267 | |
| 268 | if ( rtl ) |
| 269 | { |
| 270 | if ( spaceAfter < rectWidth ) |
| 271 | { |
| 272 | // Flip to show on right. |
| 273 | if ( spaceBefore > rectWidth ) |
| 274 | left += rectWidth; |
| 275 | // Align to window left. |
| 276 | else if ( viewportSize.width > rectWidth ) |
| 277 | left = left - rect.left; |
| 278 | // Align to window right, never cutting the panel at right. |
| 279 | else |
| 280 | left = left - rect.right + viewportSize.width; |
| 281 | } |
| 282 | } |
| 283 | else if ( spaceAfter < rectWidth ) |
| 284 | { |
| 285 | // Flip to show on left. |
| 286 | if ( spaceBefore > rectWidth ) |
| 287 | left -= rectWidth; |
| 288 | // Align to window right. |
| 289 | else if ( viewportSize.width > rectWidth ) |
| 290 | left = left - rect.right + viewportSize.width; |
| 291 | // Align to window left, never cutting the panel at left. |
| 292 | else |
| 293 | left = left - rect.left; |
| 294 | } |
265 | | // Vertical off screen is simpler. |
266 | | if ( top + panelSize.height > viewportSize.height + windowScroll.y ) |
267 | | top -= panelSize.height; |
| 297 | // Check if the default vertical layout is possible. |
| 298 | var spaceBelow = viewportSize.height - rect.top, |
| 299 | spaceAbove = rect.top; |
| 300 | |
| 301 | if ( spaceBelow < rectHeight ) |
| 302 | { |
| 303 | // Flip to show above. |
| 304 | if ( spaceAbove > rectHeight ) |
| 305 | top -= rectHeight; |
| 306 | // Align to window bottom. |
| 307 | else if ( viewportSize.height > rectHeight ) |
| 308 | top = top - rect.bottom + viewportSize.height; |
| 309 | // Align to top, never cutting the panel at top. |
| 310 | else |
| 311 | top = top - rect.top; |
| 312 | } |