Twenty Thirteen: adjust JavaScript handling for scrolling and finding viewport heigh/width to better support various IE versions. Also consolidate variables at the top of the file per best practices. Fixes #23841, props obenland.

git-svn-id: http://core.svn.wordpress.org/trunk@23965 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Lance Willett 2013-04-11 16:11:46 +00:00
parent 2d85b8eb46
commit 2fe90e6312

View File

@ -5,7 +5,14 @@
*/ */
( function( $ ) { ( function( $ ) {
var twentyThirteen = { var html = $( 'html' ),
body = $( 'body' ),
navbar = $( '#navbar' ),
_window = $( window ),
navbarOffset = -1,
toolbarOffset = body.is( '.admin-bar' ) ? 28 : 0,
twentyThirteen = {
/** /**
* Adds a top margin to the footer if the sidebar widget area is * Adds a top margin to the footer if the sidebar widget area is
* higher than the rest of the page, to help the footer always * higher than the rest of the page, to help the footer always
@ -16,7 +23,7 @@
secondary = ( 0 == sidebar.length ) ? -40 : sidebar.height(), secondary = ( 0 == sidebar.length ) ? -40 : sidebar.height(),
margin = $( '#tertiary .widget-area' ).height() - $( '#content' ).height() - secondary; margin = $( '#tertiary .widget-area' ).height() - $( '#content' ).height() - secondary;
if ( margin > 0 && window.innerWidth > 999 ) if ( margin > 0 && _window.innerWidth() > 999 )
$( '#colophon' ).css( 'margin-top', margin + 'px' ); $( '#colophon' ).css( 'margin-top', margin + 'px' );
}, },
@ -36,22 +43,17 @@
if ( body.is( '.sidebar' ) ) if ( body.is( '.sidebar' ) )
twentyThirteen.adjustFooter(); twentyThirteen.adjustFooter();
} ); } );
$( window ).on( 'hashchange', twentyThirteen.adjustAnchor ); _window.on( 'hashchange', twentyThirteen.adjustAnchor );
/** /**
* Displays the fixed navbar based on screen position. * Displays the fixed navbar based on screen position.
*/ */
var html = $( 'html' ), _window.scroll( function() {
body = $( 'body' ), var scrollOffset = ( typeof window.scrollY === 'undefined' ) ? document.documentElement.scrollTop : window.scrollY;
navbar = $( '#navbar' ),
navbarOffset = -1,
toolbarOffset = body.is( '.admin-bar' ) ? 28 : 0;
$( window ).scroll( function() {
if ( navbarOffset < 0 ) if ( navbarOffset < 0 )
navbarOffset = navbar.offset().top - toolbarOffset; navbarOffset = navbar.offset().top - toolbarOffset;
if ( window.scrollY >= navbarOffset && 644 < window.innerWidth ) if ( scrollOffset >= navbarOffset && _window.innerWidth() > 644 )
html.addClass( 'navbar-fixed' ); html.addClass( 'navbar-fixed' );
else else
html.removeClass( 'navbar-fixed' ); html.removeClass( 'navbar-fixed' );
@ -97,7 +99,7 @@
* *
* @link http://www.nczonline.net/blog/2013/01/15/fixing-skip-to-content-links/ * @link http://www.nczonline.net/blog/2013/01/15/fixing-skip-to-content-links/
*/ */
$( window ).on( 'hashchange', function() { _window.on( 'hashchange', function() {
var element = $( location.hash ); var element = $( location.hash );
if ( element ) { if ( element ) {