]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-content/themes/twentyfourteen/js/functions.js
WordPress 4.5
[autoinstalls/wordpress.git] / wp-content / themes / twentyfourteen / js / functions.js
index 603e1379a02cd3c1eccacbc0c4be0c3608fce22b..a21849ec350d4ff6e2ed4edf30381a1a38f72c76 100644 (file)
 
        // Enable menu toggle for small screens.
        ( function() {
-               if ( ! nav || ! button ) {
+               if ( ! nav.length || ! button.length ) {
                        return;
                }
 
                // Hide button if menu is missing or empty.
-               if ( ! menu || ! menu.children().length ) {
+               if ( ! menu.length || ! menu.children().length ) {
                        button.hide();
                        return;
                }
        } );
 
        _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.