]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-content/themes/twentyfourteen/js/functions.js
WordPress 4.6.3
[autoinstalls/wordpress.git] / wp-content / themes / twentyfourteen / js / functions.js
index ea656d8077e8c93808d9e12e496f3bab4eb2d78a..a21849ec350d4ff6e2ed4edf30381a1a38f72c76 100644 (file)
@@ -7,29 +7,34 @@
  */
 ( function( $ ) {
        var body    = $( 'body' ),
-               _window = $( window );
+               _window = $( window ),
+               nav, button, menu;
+
+       nav = $( '#primary-navigation' );
+       button = nav.find( '.menu-toggle' );
+       menu = nav.find( '.nav-menu' );
 
        // Enable menu toggle for small screens.
        ( function() {
-               var nav = $( '#primary-navigation' ), button, menu;
-               if ( ! nav ) {
-                       return;
-               }
-
-               button = nav.find( '.menu-toggle' );
-               if ( ! button ) {
+               if ( ! nav.length || ! button.length ) {
                        return;
                }
 
                // Hide button if menu is missing or empty.
-               menu = nav.find( '.nav-menu' );
-               if ( ! menu || ! menu.children().length ) {
+               if ( ! menu.length || ! menu.children().length ) {
                        button.hide();
                        return;
                }
 
-               $( '.menu-toggle' ).on( 'click.twentyfourteen', function() {
+               button.on( 'click.twentyfourteen', function() {
                        nav.toggleClass( 'toggled-on' );
+                       if ( nav.hasClass( 'toggled-on' ) ) {
+                               $( this ).attr( 'aria-expanded', 'true' );
+                               menu.attr( 'aria-expanded', 'true' );
+                       } else {
+                               $( this ).attr( 'aria-expanded', 'false' );
+                               menu.attr( 'aria-expanded', 'false' );
+                       }
                } );
        } )();
 
         * @link http://www.nczonline.net/blog/2013/01/15/fixing-skip-to-content-links/
         */
        _window.on( 'hashchange.twentyfourteen', function() {
-               var element = document.getElementById( location.hash.substring( 1 ) );
+               var hash = location.hash.substring( 1 ), element;
+
+               if ( ! hash ) {
+                       return;
+               }
+
+               element = document.getElementById( hash );
 
                if ( element ) {
                        if ( ! /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) {
                // Search toggle.
                $( '.search-toggle' ).on( 'click.twentyfourteen', function( event ) {
                        var that    = $( this ),
-                               wrapper = $( '.search-box-wrapper' );
+                               wrapper = $( '#search-container' ),
+                               container = that.find( 'a' );
 
                        that.toggleClass( 'active' );
                        wrapper.toggleClass( 'hide' );
 
+                       if ( that.hasClass( 'active' ) ) {
+                               container.attr( 'aria-expanded', 'true' );
+                       } else {
+                               container.attr( 'aria-expanded', 'false' );
+                       }
+
                        if ( that.is( '.active' ) || $( '.search-toggle .screen-reader-text' )[0] === event.target ) {
                                wrapper.find( '.search-field' ).focus();
                        }
                                mastheadOffset = $( '#masthead' ).offset().top - toolbarOffset;
 
                                _window.on( 'scroll.twentyfourteen', function() {
-                                       if ( ( window.scrollY > mastheadOffset ) && ( mastheadHeight < 49 ) ) {
+                                       if ( _window.scrollTop() > mastheadOffset && mastheadHeight < 49 ) {
                                                body.addClass( 'masthead-fixed' );
                                        } else {
                                                body.removeClass( 'masthead-fixed' );
                } );
        } );
 
+       /**
+        * @summary Add or remove ARIA attributes.
+        * Uses jQuery's width() function to determine the size of the window and add
+        * the default ARIA attributes for the menu toggle if it's visible.
+        * @since Twenty Fourteen 1.4
+        */
+       function onResizeARIA() {
+               if ( 781 > _window.width() ) {
+                       button.attr( 'aria-expanded', 'false' );
+                       menu.attr( 'aria-expanded', 'false' );
+                       button.attr( 'aria-controls', 'primary-menu' );
+               } else {
+                       button.removeAttr( 'aria-expanded' );
+                       menu.removeAttr( 'aria-expanded' );
+                       button.removeAttr( 'aria-controls' );
+               }
+       }
+
+       _window
+               .on( 'load.twentyfourteen', onResizeARIA )
+               .on( 'resize.twentyfourteen', function() {
+                       onResizeARIA();
+       } );
+
        _window.load( function() {
+               var footerSidebar,
+                       isCustomizeSelectiveRefresh = ( 'undefined' !== typeof wp && wp.customize && wp.customize.selectiveRefresh );
+
                // Arrange footer widgets vertically.
                if ( $.isFunction( $.fn.masonry ) ) {
-                       $( '#footer-sidebar' ).masonry( {
+                       footerSidebar = $( '#footer-sidebar' );
+                       footerSidebar.masonry( {
                                itemSelector: '.widget',
                                columnWidth: function( containerWidth ) {
                                        return containerWidth / 4;
                                isResizable: true,
                                isRTL: $( 'body' ).is( '.rtl' )
                        } );
+
+                       if ( isCustomizeSelectiveRefresh ) {
+
+                               // Retain previous masonry-brick initial position.
+                               wp.customize.selectiveRefresh.bind( 'partial-content-rendered', function( placement ) {
+                                       var copyPosition = (
+                                               placement.partial.extended( wp.customize.widgetsPreview.WidgetPartial ) &&
+                                               placement.removedNodes instanceof jQuery &&
+                                               placement.removedNodes.is( '.masonry-brick' ) &&
+                                               placement.container instanceof jQuery
+                                       );
+                                       if ( copyPosition ) {
+                                               placement.container.css( {
+                                                       position: placement.removedNodes.css( 'position' ),
+                                                       top: placement.removedNodes.css( 'top' ),
+                                                       left: placement.removedNodes.css( 'left' )
+                                               } );
+                                       }
+                               } );
+
+                               // Re-arrange footer widgets after selective refresh event.
+                               wp.customize.selectiveRefresh.bind( 'sidebar-updated', function( sidebarPartial ) {
+                                       if ( 'sidebar-3' === sidebarPartial.sidebarId ) {
+                                               footerSidebar.masonry( 'reloadItems' );
+                                               footerSidebar.masonry( 'layout' );
+                                       }
+                               } );
+                       }
+               }
+
+               // Initialize audio and video players in Twenty_Fourteen_Ephemera_Widget widget when selectively refreshed in Customizer.
+               if ( isCustomizeSelectiveRefresh && wp.mediaelement ) {
+                       wp.customize.selectiveRefresh.bind( 'partial-content-rendered', function() {
+                               wp.mediaelement.initialize();
+                       } );
                }
 
                // Initialize Featured Content slider.