WordPress.org

Make WordPress Core

Changeset 24004


Ignore:
Timestamp:
04/16/2013 09:51:07 PM (5 years ago)
Author:
lancewillett
Message:

Twenty Thirteen: improvements to functions.js to add namespacing to events and simplify repeatable functions. See #23875.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-content/themes/twentythirteen/js/functions.js

    r23965 r24004  
    1212        navbarOffset  = -1,
    1313        toolbarOffset = body.is( '.admin-bar' ) ? 28 : 0,
     14        adjustFooter,
     15        adjustAnchor;
    1416
    15         twentyThirteen = {
    16         /**
    17          * Adds a top margin to the footer if the sidebar widget area is
    18          * higher than the rest of the page, to help the footer always
    19          * visually clear the sidebar.
    20          */
    21         adjustFooter : function() {
    22             var sidebar   = $( '#secondary .widget-area' ),
    23                 secondary = ( 0 == sidebar.length ) ? -40 : sidebar.height(),
    24                 margin    = $( '#tertiary .widget-area' ).height() - $( '#content' ).height() - secondary;
     17    /**
     18     * Adds a top margin to the footer if the sidebar widget area is
     19     * higher than the rest of the page, to help the footer always
     20     * visually clear the sidebar.
     21     */
     22    adjustFooter = function() {
     23        var sidebar   = $( '#secondary .widget-area' ),
     24            secondary = ( 0 == sidebar.length ) ? -40 : sidebar.height(),
     25            margin    = $( '#tertiary .widget-area' ).height() - $( '#content' ).height() - secondary;
    2526
    26             if ( margin > 0 && _window.innerWidth() > 999 )
    27                 $( '#colophon' ).css( 'margin-top', margin + 'px' );
    28         },
     27        if ( margin > 0 && _window.innerWidth() > 999 )
     28            $( '#colophon' ).css( 'margin-top', margin + 'px' );
     29    };
    2930
    30         /**
    31          * Repositions the window on jump-to-anchor to account for navbar
    32          * height.
    33          */
    34         adjustAnchor : function() {
    35             if ( window.location.hash )
    36                 window.scrollBy( 0, -49 );
    37         }
     31    /**
     32     * Repositions the window on jump-to-anchor to account for navbar
     33     * height.
     34     */
     35    adjustAnchor = function() {
     36        if ( window.location.hash )
     37            window.scrollBy( 0, -49 );
    3838    };
    3939
    4040    $( function() {
    41         twentyThirteen.adjustAnchor();
     41        adjustAnchor();
    4242
    4343        if ( body.is( '.sidebar' ) )
    44             twentyThirteen.adjustFooter();
     44            adjustFooter();
    4545    } );
    46     _window.on( 'hashchange', twentyThirteen.adjustAnchor );
     46    _window.on( 'hashchange.twentythirteen', adjustAnchor );
    4747
    4848    /**
    4949     * Displays the fixed navbar based on screen position.
    5050     */
    51     _window.scroll( function() {
     51    _window.on( 'scroll.twentythirteen', function() {
    5252        var scrollOffset = ( typeof window.scrollY === 'undefined' ) ? document.documentElement.scrollTop : window.scrollY;
    5353        if ( navbarOffset < 0 )
     
    6363     * Allows clicking the navbar to scroll to top.
    6464     */
    65     navbar.on( 'click', function( event ) {
     65    navbar.on( 'click.twentythirteen', function( event ) {
    6666        // Ensure that the navbar element was the target of the click.
    6767        if ( 'navbar' == event.target.id  || 'site-navigation' == event.target.id )
     
    8888        }
    8989
    90         $( '.menu-toggle' ).on( 'click', function() {
     90        $( '.menu-toggle' ).on( 'click.twentythirteen', function() {
    9191            nav.toggleClass( 'toggled-on' );
    9292        } );
    9393    } )();
    94 
    9594
    9695    /**
     
    10099     * @link http://www.nczonline.net/blog/2013/01/15/fixing-skip-to-content-links/
    101100     */
    102     _window.on( 'hashchange', function() {
     101    _window.on( 'hashchange.twentythirteen', function() {
    103102        var element = $( location.hash );
    104103
Note: See TracChangeset for help on using the changeset viewer.