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

git-svn-id: http://core.svn.wordpress.org/trunk@24005 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Lance Willett 2013-04-16 22:35:55 +00:00
parent e4248830a8
commit 7ed04565bb
2 changed files with 18 additions and 17 deletions

View File

@ -223,7 +223,7 @@ function twentythirteen_scripts_styles() {
wp_enqueue_script( 'jquery-masonry' );
// Loads JavaScript file with functionality specific to Twenty Thirteen.
wp_enqueue_script( 'twentythirteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20130211', true );
wp_enqueue_script( 'twentythirteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20130416', true );
// Loads our main stylesheet.
wp_enqueue_style( 'twentythirteen-style', get_stylesheet_uri() );

View File

@ -5,12 +5,13 @@
*/
( function( $ ) {
var html = $( 'html' ),
body = $( 'body' ),
navbar = $( '#navbar' ),
_window = $( window ),
navbarOffset = -1,
toolbarOffset = body.is( '.admin-bar' ) ? 28 : 0,
var html = $( 'html' ),
body = $( 'body' ),
navbar = $( '#navbar' ),
_window = $( window ),
toolbarOffset = body.is( '.admin-bar' ) ? 28 : 0,
navbarOffset = navbar.offset().top - toolbarOffset,
scrollOffsetMethod = ( typeof window.scrollY === 'undefined' ),
adjustFooter,
adjustAnchor;
@ -48,16 +49,16 @@
/**
* Displays the fixed navbar based on screen position.
*/
_window.on( 'scroll.twentythirteen', function() {
var scrollOffset = ( typeof window.scrollY === 'undefined' ) ? document.documentElement.scrollTop : window.scrollY;
if ( navbarOffset < 0 )
navbarOffset = navbar.offset().top - toolbarOffset;
if ( scrollOffset >= navbarOffset && _window.innerWidth() > 644 )
html.addClass( 'navbar-fixed' );
else
html.removeClass( 'navbar-fixed' );
} );
if ( _window.innerWidth() > 644 ) {
_window.on( 'scroll.twentythirteen', function() {
var scrollOffset = scrollOffsetMethod ? document.documentElement.scrollTop : window.scrollY;
if ( scrollOffset > navbarOffset )
html.addClass( 'navbar-fixed' );
else
html.removeClass( 'navbar-fixed' );
} );
}
/**
* Allows clicking the navbar to scroll to top.