2013-02-19 00:08:56 +01:00
|
|
|
/**
|
|
|
|
* Functionality specific to Twenty Thirteen.
|
|
|
|
*
|
|
|
|
* Provides helper functions to enhance the theme experience.
|
|
|
|
*/
|
|
|
|
|
|
|
|
( function( $ ) {
|
2013-04-17 00:35:55 +02:00
|
|
|
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' ),
|
2013-04-16 23:51:07 +02:00
|
|
|
adjustFooter,
|
|
|
|
adjustAnchor;
|
2013-04-11 18:11:46 +02:00
|
|
|
|
2013-04-16 23:51:07 +02:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* visually clear the sidebar.
|
|
|
|
*/
|
|
|
|
adjustFooter = function() {
|
|
|
|
var sidebar = $( '#secondary .widget-area' ),
|
|
|
|
secondary = ( 0 == sidebar.length ) ? -40 : sidebar.height(),
|
|
|
|
margin = $( '#tertiary .widget-area' ).height() - $( '#content' ).height() - secondary;
|
|
|
|
|
|
|
|
if ( margin > 0 && _window.innerWidth() > 999 )
|
|
|
|
$( '#colophon' ).css( 'margin-top', margin + 'px' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Repositions the window on jump-to-anchor to account for navbar
|
|
|
|
* height.
|
|
|
|
*/
|
|
|
|
adjustAnchor = function() {
|
|
|
|
if ( window.location.hash )
|
|
|
|
window.scrollBy( 0, -49 );
|
2013-02-19 00:08:56 +01:00
|
|
|
};
|
|
|
|
|
2013-04-03 19:29:59 +02:00
|
|
|
$( function() {
|
2013-04-16 23:51:07 +02:00
|
|
|
adjustAnchor();
|
2013-03-12 22:42:53 +01:00
|
|
|
|
|
|
|
if ( body.is( '.sidebar' ) )
|
2013-04-16 23:51:07 +02:00
|
|
|
adjustFooter();
|
2013-03-12 22:42:53 +01:00
|
|
|
} );
|
2013-04-16 23:51:07 +02:00
|
|
|
_window.on( 'hashchange.twentythirteen', adjustAnchor );
|
2013-02-19 00:08:56 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays the fixed navbar based on screen position.
|
|
|
|
*/
|
2013-04-17 00:35:55 +02:00
|
|
|
if ( _window.innerWidth() > 644 ) {
|
|
|
|
_window.on( 'scroll.twentythirteen', function() {
|
|
|
|
var scrollOffset = scrollOffsetMethod ? document.documentElement.scrollTop : window.scrollY;
|
2013-04-23 18:30:03 +02:00
|
|
|
|
2013-04-17 00:35:55 +02:00
|
|
|
if ( scrollOffset > navbarOffset )
|
|
|
|
html.addClass( 'navbar-fixed' );
|
|
|
|
else
|
|
|
|
html.removeClass( 'navbar-fixed' );
|
|
|
|
} );
|
|
|
|
}
|
2013-02-19 00:08:56 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allows clicking the navbar to scroll to top.
|
|
|
|
*/
|
2013-04-16 23:51:07 +02:00
|
|
|
navbar.on( 'click.twentythirteen', function( event ) {
|
2013-02-19 00:08:56 +01:00
|
|
|
// Ensure that the navbar element was the target of the click.
|
|
|
|
if ( 'navbar' == event.target.id || 'site-navigation' == event.target.id )
|
|
|
|
$( 'html, body' ).animate( { scrollTop: 0 }, 'fast' );
|
|
|
|
} );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enables menu toggle for small screens.
|
|
|
|
*/
|
|
|
|
( function() {
|
|
|
|
var nav = $( '#site-navigation' ), button, menu;
|
|
|
|
if ( ! nav )
|
|
|
|
return;
|
|
|
|
|
|
|
|
button = nav.find( '.menu-toggle' );
|
|
|
|
menu = nav.find( '.nav-menu' );
|
|
|
|
if ( ! button )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Hide button if menu is missing or empty.
|
|
|
|
if ( ! menu || ! menu.children().length ) {
|
|
|
|
button.hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-16 23:51:07 +02:00
|
|
|
$( '.menu-toggle' ).on( 'click.twentythirteen', function() {
|
2013-02-19 00:08:56 +01:00
|
|
|
nav.toggleClass( 'toggled-on' );
|
|
|
|
} );
|
|
|
|
} )();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes "skip to content" link work correctly in IE9 and Chrome for better
|
|
|
|
* accessibility.
|
|
|
|
*
|
|
|
|
* @link http://www.nczonline.net/blog/2013/01/15/fixing-skip-to-content-links/
|
|
|
|
*/
|
2013-04-16 23:51:07 +02:00
|
|
|
_window.on( 'hashchange.twentythirteen', function() {
|
2013-04-23 18:30:03 +02:00
|
|
|
var element = document.getElementById( location.hash.substring( 1 ) );
|
2013-02-19 00:08:56 +01:00
|
|
|
|
|
|
|
if ( element ) {
|
2013-04-23 18:30:03 +02:00
|
|
|
if ( ! /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) )
|
|
|
|
element.tabIndex = -1;
|
2013-02-19 00:08:56 +01:00
|
|
|
|
|
|
|
element.focus();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Arranges footer widgets vertically.
|
|
|
|
*/
|
|
|
|
if ( $.isFunction( $.fn.masonry ) ) {
|
2013-03-07 18:57:16 +01:00
|
|
|
var columnWidth = body.is( '.sidebar' ) ? 228 : 245;
|
2013-02-19 00:08:56 +01:00
|
|
|
|
2013-02-28 22:35:26 +01:00
|
|
|
$( '#secondary .widget-area' ).masonry( {
|
2013-02-19 00:08:56 +01:00
|
|
|
itemSelector: '.widget',
|
2013-03-07 18:57:16 +01:00
|
|
|
columnWidth: columnWidth,
|
|
|
|
gutterWidth: 20,
|
2013-03-07 19:22:58 +01:00
|
|
|
isRTL: body.is( '.rtl' )
|
2013-02-19 00:08:56 +01:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
} )( jQuery );
|