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