Skip to content

Commit

Permalink
Creating selective refresh script. Partial completion of issue #1, re…
Browse files Browse the repository at this point in the history
…renders the plugin however it is hidden
  • Loading branch information
cameronjonesweb committed Apr 2, 2016
1 parent add24f7 commit 1071daf
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions js/selective-refresh.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
jQuery( function() {
// Short-circuit selective refresh events if not in customizer preview or pre-4.5.
if ( 'undefined' === typeof wp || ! wp.customize || ! wp.customize.selectiveRefresh ) {
return;
}

// Re-load Facebook Page Plugin when a partial is rendered.
wp.customize.selectiveRefresh.bind( 'partial-content-rendered', function( placement ) {
if ( placement.container ) {
if( placement.container.find('.cameronjonesweb_facebook_page_plugin') ) {
var wrapper = placement.container.find('.cameronjonesweb_facebook_page_plugin');
var containerId = wrapper.attr('id');
var container = wrapper.children('.fb-page');
var url = container.data('href');
container.load( url, function() {
FB.XFBML.parse(document.getElementById( containerId ),
function() {
container.fadeIn( "slow" );
}
);
});
}
}
} );

// Refresh a moved partial containing a Facebook Page Plugin, since it has to be re-built.
wp.customize.selectiveRefresh.bind( 'partial-content-moved', function( placement ) {
if ( placement.container && placement.container.find( '.cameronjonesweb_facebook_page_plugin' ).length ) {
placement.partial.refresh();
}
} );
} );

0 comments on commit 1071daf

Please sign in to comment.