|
1 /** |
|
2 * Functionality specific to Twenty Thirteen. |
|
3 * |
|
4 * Provides helper functions to enhance the theme experience. |
|
5 */ |
|
6 |
|
7 ( function( $ ) { |
|
8 var body = $( 'body' ), |
|
9 _window = $( window ); |
|
10 |
|
11 /** |
|
12 * Adds a top margin to the footer if the sidebar widget area is higher |
|
13 * than the rest of the page, to help the footer always visually clear |
|
14 * the sidebar. |
|
15 */ |
|
16 $( function() { |
|
17 if ( body.is( '.sidebar' ) ) { |
|
18 var sidebar = $( '#secondary .widget-area' ), |
|
19 secondary = ( 0 == sidebar.length ) ? -40 : sidebar.height(), |
|
20 margin = $( '#tertiary .widget-area' ).height() - $( '#content' ).height() - secondary; |
|
21 |
|
22 if ( margin > 0 && _window.innerWidth() > 999 ) |
|
23 $( '#colophon' ).css( 'margin-top', margin + 'px' ); |
|
24 } |
|
25 } ); |
|
26 |
|
27 /** |
|
28 * Enables menu toggle for small screens. |
|
29 */ |
|
30 ( function() { |
|
31 var nav = $( '#site-navigation' ), button, menu; |
|
32 if ( ! nav ) |
|
33 return; |
|
34 |
|
35 button = nav.find( '.menu-toggle' ); |
|
36 if ( ! button ) |
|
37 return; |
|
38 |
|
39 // Hide button if menu is missing or empty. |
|
40 menu = nav.find( '.nav-menu' ); |
|
41 if ( ! menu || ! menu.children().length ) { |
|
42 button.hide(); |
|
43 return; |
|
44 } |
|
45 |
|
46 $( '.menu-toggle' ).on( 'click.twentythirteen', function() { |
|
47 nav.toggleClass( 'toggled-on' ); |
|
48 } ); |
|
49 } )(); |
|
50 |
|
51 /** |
|
52 * Makes "skip to content" link work correctly in IE9 and Chrome for better |
|
53 * accessibility. |
|
54 * |
|
55 * @link http://www.nczonline.net/blog/2013/01/15/fixing-skip-to-content-links/ |
|
56 */ |
|
57 _window.on( 'hashchange.twentythirteen', function() { |
|
58 var element = document.getElementById( location.hash.substring( 1 ) ); |
|
59 |
|
60 if ( element ) { |
|
61 if ( ! /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) |
|
62 element.tabIndex = -1; |
|
63 |
|
64 element.focus(); |
|
65 } |
|
66 } ); |
|
67 |
|
68 /** |
|
69 * Arranges footer widgets vertically. |
|
70 */ |
|
71 if ( $.isFunction( $.fn.masonry ) ) { |
|
72 var columnWidth = body.is( '.sidebar' ) ? 228 : 245; |
|
73 |
|
74 $( '#secondary .widget-area' ).masonry( { |
|
75 itemSelector: '.widget', |
|
76 columnWidth: columnWidth, |
|
77 gutterWidth: 20, |
|
78 isRTL: body.is( '.rtl' ) |
|
79 } ); |
|
80 } |
|
81 } )( jQuery ); |