wp/wp-content/themes/twentythirteen/js/functions.js
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
--- a/wp/wp-content/themes/twentythirteen/js/functions.js	Tue Jun 09 11:14:17 2015 +0000
+++ b/wp/wp-content/themes/twentythirteen/js/functions.js	Mon Oct 14 17:39:30 2019 +0200
@@ -34,12 +34,12 @@
 	 * Enables 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;
 		}
@@ -75,9 +75,11 @@
 	} )();
 
 	/**
-	 * @summary Add or remove ARIA attributes.
+	 * 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 Thirteen 1.5
 	 */
 	function onResizeARIA() {
@@ -119,14 +121,47 @@
 	/**
 	 * Arranges footer widgets vertically.
 	 */
-	if ( $.isFunction( $.fn.masonry ) ) {
-		var columnWidth = body.is( '.sidebar' ) ? 228 : 245;
+	$( function() {
+		var columnWidth, widgetArea;
+		if ( ! $.isFunction( $.fn.masonry ) ) {
+			return;
+		}
+		columnWidth = body.is( '.sidebar' ) ? 228 : 245;
+		widgetArea = $( '#secondary .widget-area' );
 
-		$( '#secondary .widget-area' ).masonry( {
+		widgetArea.masonry( {
 			itemSelector: '.widget',
 			columnWidth: columnWidth,
 			gutterWidth: 20,
 			isRTL: body.is( '.rtl' )
 		} );
-	}
+
+		if ( 'undefined' !== typeof wp && wp.customize && wp.customize.selectiveRefresh ) {
+
+			// 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 when sidebar is updated via selective refresh in the Customizer.
+			wp.customize.selectiveRefresh.bind( 'sidebar-updated', function( sidebarPartial ) {
+				if ( 'sidebar-1' === sidebarPartial.sidebarId ) {
+					widgetArea.masonry( 'reloadItems' );
+					widgetArea.masonry( 'layout' );
+				}
+			} );
+		}
+	} );
 } )( jQuery );
\ No newline at end of file