| 444 | /* |
| 445 | * Check if any part of the sidebar is visible in |
| 446 | * the viewport. If it is, don't scroll. Otherwise, |
| 447 | * scroll up to so the sidebar is in view. |
| 448 | * |
| 449 | * We do this by comparing the top, right, bottom, |
| 450 | * and left bounds of the sidebar so see if they |
| 451 | * are within the bounds of the viewport. |
| 452 | */ |
| 453 | var viewport = { |
| 454 | top: $(window).scrollTop(), |
| 455 | left: $(window).scrollLeft() |
| 456 | }; |
| 457 | viewport.right = viewport.left + $(window).width(); |
| 458 | viewport.bottom = viewport.top + $(window).height(); |
| 459 | |
| 460 | var sidebar_bounds = sidebar.offset(); |
| 461 | sidebar_bounds.right = sidebar_bounds.left + sidebar.outerWidth(); |
| 462 | sidebar_bounds.bottom = sidebar_bounds.top + sidebar.outerHeight(); |
| 463 | |
| 464 | if ( viewport.top > sidebar_bounds.bottom || viewport.right < sidebar_bounds.left || viewport.bottom < sidebar_bounds.top || viewport.left > sidebar_bounds.right ) { |
| 465 | $( 'html, body' ).animate({ |
| 466 | scrollTop: sidebar.offset().top - 130 |
| 467 | }, 200 ); |
| 468 | } |
| 469 | |