Нет описания

infinity-customizer.js 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* globals wp */
  2. ( function ( $ ) {
  3. /**
  4. * Ready, set, go!
  5. */
  6. $( document ).ready( function () {
  7. // Integrate with Selective Refresh in the Customizer.
  8. if ( 'undefined' !== typeof wp && wp.customize && wp.customize.selectiveRefresh ) {
  9. /**
  10. * Handle rendering of selective refresh partials.
  11. *
  12. * Make sure that when a partial is rendered, the Jetpack post-load event
  13. * will be triggered so that any dynamic elements will be re-constructed,
  14. * such as ME.js elements, Photon replacements, social sharing, and more.
  15. * Note that this is applying here not strictly to posts being loaded.
  16. * If a widget contains a ME.js element and it is previewed via selective
  17. * refresh, the post-load would get triggered allowing any dynamic elements
  18. * therein to also be re-constructed.
  19. *
  20. * @param {wp.customize.selectiveRefresh.Placement} placement
  21. */
  22. wp.customize.selectiveRefresh.bind( 'partial-content-rendered', function ( placement ) {
  23. var content;
  24. if ( 'string' === typeof placement.addedContent ) {
  25. content = placement.addedContent;
  26. } else if ( placement.container ) {
  27. content = $( placement.container ).html();
  28. }
  29. if ( content ) {
  30. $( document.body ).trigger( 'post-load', { html: content } );
  31. }
  32. } );
  33. /*
  34. * Add partials for posts added via infinite scroll.
  35. *
  36. * This is unnecessary when MutationObserver is supported by the browser
  37. * since then this will be handled by Selective Refresh in core.
  38. */
  39. if ( 'undefined' === typeof MutationObserver ) {
  40. $( document.body ).on( 'post-load', function ( e, response ) {
  41. var rootElement = null;
  42. if ( response.html && -1 !== response.html.indexOf( 'data-customize-partial' ) ) {
  43. if ( window.infiniteScroll.settings.id ) {
  44. rootElement = $( '#' + window.infiniteScroll.settings.id );
  45. }
  46. wp.customize.selectiveRefresh.addPartials( rootElement );
  47. }
  48. } );
  49. }
  50. }
  51. } );
  52. } )( jQuery ); // Close closure