Make WordPress Core

Ticket #23557: 23557.2.diff

File 23557.2.diff, 1.5 KB (added by obenland, 12 years ago)

Cleaned up version of sbrajesh's approach.

  • wp-content/themes/twentythirteen/js/functions.js

     
    55 */
    66
    77( function( $ ) {
    8         /**
    9          * Repositions the window on jump-to-anchor to account for
    10          * navbar height.
    11          */
    12         var twentyThirteenAdjustAnchor = function() {
    13                 if ( window.location.hash )
    14                         window.scrollBy( 0, -49 );
     8        var twentyThirteen = {
     9                /**
     10                 * Sets the content area to the same hight as the sidebar, if the
     11                 * sidebar is higher, to avoid overflow.
     12                 */
     13                adjustFooter : function() {
     14                        var content = $( '#content' ),
     15                            height  = $( '#tertiary .widget-area' ).height() + 40; // 40px padding top.
     16
     17                        if ( height > content.height() )
     18                                content.css( 'height', height + 'px' );
     19                },
     20
     21                /**
     22                 * Repositions the window on jump-to-anchor to account for navbar
     23                 * height.
     24                 */
     25                adjustAnchor : function() {
     26                        if ( window.location.hash )
     27                                window.scrollBy( 0, -49 );
     28                }
    1529        };
    1630
    17         $( document ).on( 'ready',    twentyThirteenAdjustAnchor );
    18         $( window ).on( 'hashchange', twentyThirteenAdjustAnchor );
     31        $( document ).on( 'ready', function() {
     32                twentyThirteen.adjustAnchor();
     33
     34                if ( body.is( '.sidebar' ) )
     35                        twentyThirteen.adjustFooter();
     36        } );
     37        $( window ).on( 'hashchange', twentyThirteen.adjustAnchor );
    1938
    2039        /**
    2140         * Displays the fixed navbar based on screen position.