WordPress.org

Make WordPress Core

Changeset 24005


Ignore:
Timestamp:
04/16/2013 10:35:55 PM (5 years ago)
Author:
lancewillett
Message:

Twenty Thirteen: further performance for functions.js scroll event callback, props obenland. See #23875.

Location:
trunk/wp-content/themes/twentythirteen
Files:
2 edited

Legend:

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

    r23989 r24005  
    224224
    225225    // Loads JavaScript file with functionality specific to Twenty Thirteen.
    226     wp_enqueue_script( 'twentythirteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20130211', true );
     226    wp_enqueue_script( 'twentythirteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20130416', true );
    227227
    228228    // Loads our main stylesheet.
  • trunk/wp-content/themes/twentythirteen/js/functions.js

    r24004 r24005  
    66
    77( function( $ ) {
    8     var html          = $( 'html' ),
    9         body          = $( 'body' ),
    10         navbar        = $( '#navbar' ),
    11         _window       = $( window ),
    12         navbarOffset  = -1,
    13         toolbarOffset = body.is( '.admin-bar' ) ? 28 : 0,
     8    var html               = $( 'html' ),
     9        body               = $( 'body' ),
     10        navbar             = $( '#navbar' ),
     11        _window            = $( window ),
     12        toolbarOffset      = body.is( '.admin-bar' ) ? 28 : 0,
     13        navbarOffset       = navbar.offset().top - toolbarOffset,
     14        scrollOffsetMethod = ( typeof window.scrollY === 'undefined' ),
    1415        adjustFooter,
    1516        adjustAnchor;
     
    4950     * Displays the fixed navbar based on screen position.
    5051     */
    51     _window.on( 'scroll.twentythirteen', function() {
    52         var scrollOffset = ( typeof window.scrollY === 'undefined' ) ? document.documentElement.scrollTop : window.scrollY;
    53         if ( navbarOffset < 0 )
    54             navbarOffset = navbar.offset().top - toolbarOffset;
    55 
    56         if ( scrollOffset >= navbarOffset && _window.innerWidth() > 644 )
    57             html.addClass( 'navbar-fixed' );
    58         else
    59             html.removeClass( 'navbar-fixed' );
    60     } );
     52    if ( _window.innerWidth() > 644 ) {
     53        _window.on( 'scroll.twentythirteen', function() {
     54            var scrollOffset = scrollOffsetMethod ? document.documentElement.scrollTop : window.scrollY;
     55   
     56            if ( scrollOffset > navbarOffset )
     57                html.addClass( 'navbar-fixed' );
     58            else
     59                html.removeClass( 'navbar-fixed' );
     60        } );
     61    }
    6162
    6263    /**
Note: See TracChangeset for help on using the changeset viewer.