summaryrefslogtreecommitdiff
path: root/js/functions.js
diff options
context:
space:
mode:
authorNathan Kinkade <nath@nkinka.de>2014-06-16 16:03:41 +0000
committerNathan Kinkade <nath@nkinka.de>2014-06-16 16:03:41 +0000
commit07b2ba9ff5fe1cf4bba34de578c29aee85c48b83 (patch)
tree3aacb1db21dfd0975813ea0b8a7defff3603e8f2 /js/functions.js
Initial commit of Vortant theme based on WordPress twentythirteen stock theme.
Diffstat (limited to 'js/functions.js')
-rw-r--r--js/functions.js90
1 files changed, 90 insertions, 0 deletions
diff --git a/js/functions.js b/js/functions.js
new file mode 100644
index 0000000..78c8c84
--- /dev/null
+++ b/js/functions.js
@@ -0,0 +1,90 @@
+/**
+ * Functionality specific to Twenty Thirteen.
+ *
+ * Provides helper functions to enhance the theme experience.
+ */
+
+( function( $ ) {
+ var body = $( 'body' ),
+ _window = $( window );
+
+ /**
+ * 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.
+ */
+ $( function() {
+ if ( body.is( '.sidebar' ) ) {
+ 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' );
+ }
+ }
+ } );
+
+ /**
+ * Enables menu toggle for small screens.
+ */
+ ( function() {
+ var nav = $( '#site-navigation' ), button, menu;
+ if ( ! nav ) {
+ return;
+ }
+
+ button = nav.find( '.menu-toggle' );
+ if ( ! button ) {
+ return;
+ }
+
+ // Hide button if menu is missing or empty.
+ menu = nav.find( '.nav-menu' );
+ if ( ! menu || ! menu.children().length ) {
+ button.hide();
+ return;
+ }
+
+ button.on( 'click.twentythirteen', function() {
+ nav.toggleClass( 'toggled-on' );
+ } );
+
+ // Better focus for hidden submenu items for accessibility.
+ menu.find( 'a' ).on( 'focus.twentythirteen blur.twentythirteen', function() {
+ $( this ).parents( '.menu-item, .page_item' ).toggleClass( 'focus' );
+ } );
+ } )();
+
+ /**
+ * 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/
+ */
+ _window.on( 'hashchange.twentythirteen', function() {
+ var element = document.getElementById( location.hash.substring( 1 ) );
+
+ if ( element ) {
+ if ( ! /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) {
+ element.tabIndex = -1;
+ }
+
+ element.focus();
+ }
+ } );
+
+ /**
+ * Arranges footer widgets vertically.
+ */
+ if ( $.isFunction( $.fn.masonry ) ) {
+ var columnWidth = body.is( '.sidebar' ) ? 228 : 245;
+
+ $( '#secondary .widget-area' ).masonry( {
+ itemSelector: '.widget',
+ columnWidth: columnWidth,
+ gutterWidth: 20,
+ isRTL: body.is( '.rtl' )
+ } );
+ }
+} )( jQuery ); \ No newline at end of file