| 1401 | | // Get the element window. |
| 1402 | | var win = this.getWindow(), |
| 1403 | | winHeight = win.getViewPaneSize().height; |
| 1404 | | |
| 1405 | | // Starts from the offset that will be scrolled with the negative value of |
| 1406 | | // the visible window height. |
| 1407 | | var offset = winHeight * -1; |
| 1408 | | |
| 1409 | | // Append the view pane's height if align to top. |
| 1410 | | // Append element height if we are aligning to the bottom. |
| 1411 | | if ( alignTop ) |
| 1412 | | offset += winHeight; |
| 1413 | | else |
| 1414 | | { |
| 1415 | | offset += this.$.offsetHeight || 0; |
| 1416 | | |
| 1417 | | // Consider the margin in the scroll, which is ok for our current needs, but |
| 1418 | | // needs investigation if we will be using this function in other places. |
| 1419 | | offset += parseInt( this.getComputedStyle( 'marginBottom' ) || 0, 10 ) || 0; |
| 1420 | | } |
| 1421 | | |
| 1422 | | // Append the offsets for the entire element hierarchy. |
| 1423 | | var elementPosition = this.getDocumentPosition(); |
| 1424 | | offset += elementPosition.y; |
| 1425 | | |
| 1426 | | // offset value might be out of range(nagative), fix it(#3692). |
| 1427 | | offset = offset < 0 ? 0 : offset; |
| 1428 | | |
| 1429 | | // Scroll the window to the desired position, if not already visible(#3795). |
| 1430 | | var currentScroll = win.getScrollPosition().y; |
| 1431 | | if ( offset > currentScroll || offset < currentScroll - winHeight ) |
| 1432 | | win.$.scrollTo( 0, offset ); |
| | 1405 | this.$.scrollIntoView.apply( this.$, arguments ); |