diff options
author | Anthony G. Basile <blueness@gentoo.org> | 2016-04-18 11:52:28 -0400 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2016-04-18 11:52:28 -0400 |
commit | 097e7d91b32dd6d27ea47e5d7cd8d6bdcf1e50a2 (patch) | |
tree | edf0e0c9fcd6ce7c922593a4df301d624e9faeb1 /plugins/jetpack/modules/infinite-scroll | |
parent | Update pluging wordpress-mobile-pack to 2.2.2 (diff) | |
download | blogs-gentoo-097e7d91b32dd6d27ea47e5d7cd8d6bdcf1e50a2.tar.gz blogs-gentoo-097e7d91b32dd6d27ea47e5d7cd8d6bdcf1e50a2.tar.bz2 blogs-gentoo-097e7d91b32dd6d27ea47e5d7cd8d6bdcf1e50a2.zip |
Update plugin jetpack to 3.9.6
Diffstat (limited to 'plugins/jetpack/modules/infinite-scroll')
-rw-r--r-- | plugins/jetpack/modules/infinite-scroll/infinity.js | 72 | ||||
-rw-r--r-- | plugins/jetpack/modules/infinite-scroll/infinity.php | 167 |
2 files changed, 82 insertions, 157 deletions
diff --git a/plugins/jetpack/modules/infinite-scroll/infinity.js b/plugins/jetpack/modules/infinite-scroll/infinity.js index e4095fa2..b19817db 100644 --- a/plugins/jetpack/modules/infinite-scroll/infinity.js +++ b/plugins/jetpack/modules/infinite-scroll/infinity.js @@ -186,7 +186,7 @@ Scroller.prototype.thefooter = function() { */ Scroller.prototype.refresh = function() { var self = this, - query, jqxhr, load, loader, color; + query, jqxhr, load, loader, color, customized; // If we're disabled, ready, or don't pass the check, bail. if ( this.disabled || ! this.ready || ! this.check() ) @@ -214,6 +214,20 @@ Scroller.prototype.refresh = function() { action: 'infinite_scroll' }, this.query() ); + // Inject Customizer state. + if ( 'undefined' !== typeof wp && wp.customize && wp.customize.settings.theme ) { + customized = {}; + query.wp_customize = 'on'; + query.theme = wp.customize.settings.theme.stylesheet; + wp.customize.each( function( setting ) { + if ( setting._dirty ) { + customized[ setting.id ] = setting(); + } + } ); + query.customized = JSON.stringify( customized ); + query.nonce = wp.customize.settings.nonce.preview; + } + // Fire the ajax request. jqxhr = $.post( infiniteScroll.settings.ajaxurl, query ); @@ -234,13 +248,9 @@ Scroller.prototype.refresh = function() { } // Check for and parse our response. - if ( ! response ) - return; - - response = $.parseJSON( response ); - - if ( ! response || ! response.type ) + if ( ! response || ! response.type ) { return; + } // If there are no remaining posts... if ( response.type == 'empty' ) { @@ -654,6 +664,54 @@ $( document ).ready( function() { } , 250 ); }); } + + // Integrate with Selective Refresh in the Customizer. + if ( 'undefined' !== typeof wp && wp.customize && wp.customize.selectiveRefresh ) { + + /** + * Handle rendering of selective refresh partials. + * + * Make sure that when a partial is rendered, the Jetpack post-load event + * will be triggered so that any dynamic elements will be re-constructed, + * such as ME.js elements, Photon replacements, social sharing, and more. + * Note that this is applying here not strictly to posts being loaded. + * If a widget contains a ME.js element and it is previewed via selective + * refresh, the post-load would get triggered allowing any dynamic elements + * therein to also be re-constructed. + * + * @param {wp.customize.selectiveRefresh.Placement} placement + */ + wp.customize.selectiveRefresh.bind( 'partial-content-rendered', function( placement ) { + var content; + if ( 'string' === typeof placement.addedContent ) { + content = placement.addedContent; + } else if ( placement.container ) { + content = $( placement.container ).html(); + } + + if ( content ) { + $( document.body ).trigger( 'post-load', { html: content } ); + } + } ); + + /* + * Add partials for posts added via infinite scroll. + * + * This is unnecessary when MutationObserver is supported by the browser + * since then this will be handled by Selective Refresh in core. + */ + if ( 'undefined' === typeof MutationObserver ) { + $( document.body ).on( 'post-load', function( e, response ) { + var rootElement = null; + if ( response.html && -1 !== response.html.indexOf( 'data-customize-partial' ) ) { + if ( infiniteScroll.settings.id ) { + rootElement = $( '#' + infiniteScroll.settings.id ); + } + wp.customize.selectiveRefresh.addPartials( rootElement ); + } + } ); + } + } }); diff --git a/plugins/jetpack/modules/infinite-scroll/infinity.php b/plugins/jetpack/modules/infinite-scroll/infinity.php index 2c00f448..f98d8a75 100644 --- a/plugins/jetpack/modules/infinite-scroll/infinity.php +++ b/plugins/jetpack/modules/infinite-scroll/infinity.php @@ -229,6 +229,14 @@ class The_Neverending_Home_Page { } } + // If IS is set to click, and if the site owner changed posts_per_page, let's use that + if ( + 'click' == $settings['type'] + && ( '10' !== get_option( 'posts_per_page' ) ) + ) { + $settings['posts_per_page'] = (int) get_option( 'posts_per_page' ); + } + // Force display of the click handler and attendant bits when the type isn't `click` if ( 'click' !== $settings['type'] ) { $settings['click_handle'] = true; @@ -247,7 +255,8 @@ class The_Neverending_Home_Page { self::$settings = apply_filters( 'infinite_scroll_settings', $settings ); } - return (object) self::$settings; + /** This filter is documented in modules/infinite-scroll/infinity.php */ + return (object) apply_filters( 'infinite_scroll_settings', self::$settings ); } /** @@ -367,7 +376,7 @@ class The_Neverending_Home_Page { add_filter( 'body_class', array( $this, 'body_class' ) ); // Add our scripts. - wp_enqueue_script( 'the-neverending-homepage', plugins_url( 'infinity.js', __FILE__ ), array( 'jquery' ), 20141016, true ); + wp_enqueue_script( 'the-neverending-homepage', plugins_url( 'infinity.js', __FILE__ ), array( 'jquery' ), '3.10', true ); // Add our default styles. wp_enqueue_style( 'the-neverending-homepage', plugins_url( 'infinity.css', __FILE__ ), array(), '20140422' ); @@ -1098,6 +1107,7 @@ class The_Neverending_Home_Page { * @return string or null */ function query() { + global $wp_customize; if ( ! isset( $_REQUEST['page'] ) || ! current_theme_supports( 'infinite-scroll' ) ) die; @@ -1248,7 +1258,11 @@ class The_Neverending_Home_Page { $results['type'] = 'empty'; } - echo wp_json_encode( + if ( is_customize_preview() ) { + $wp_customize->remove_preview_signature(); + } + + wp_send_json( /** * Filter the Infinite Scroll results. * @@ -1262,7 +1276,6 @@ class The_Neverending_Home_Page { */ apply_filters( 'infinite_scroll_results', $results, $query_args, self::wp_query() ) ); - die; } /** @@ -1528,149 +1541,3 @@ if ( The_Neverending_Home_Page::got_infinity() ) { // Don't load the admin bar when doing the AJAX response. show_admin_bar( false ); } - -/** - * Include the wp_json_encode functions for pre-wordpress-4.1 - */ - -if ( ! function_exists( 'wp_json_encode' ) ) : - /** - * Encode a variable into JSON, with some sanity checks. - * - * @since 4.1.0 - * - * @param mixed $data Variable (usually an array or object) to encode as JSON. - * @param int $options Optional. Options to be passed to json_encode(). Default 0. - * @param int $depth Optional. Maximum depth to walk through $data. Must be - * greater than 0. Default 512. - * @return bool|string The JSON encoded string, or false if it cannot be encoded. - */ - function wp_json_encode( $data, $options = 0, $depth = 512 ) { - /* - * json_encode() has had extra params added over the years. - * $options was added in 5.3, and $depth in 5.5. - * We need to make sure we call it with the correct arguments. - */ - if ( version_compare( PHP_VERSION, '5.5', '>=' ) ) { - $args = array( $data, $options, $depth ); - } elseif ( version_compare( PHP_VERSION, '5.3', '>=' ) ) { - $args = array( $data, $options ); - } else { - $args = array( $data ); - } - - $json = call_user_func_array( 'json_encode', $args ); - - // If json_encode() was successful, no need to do more sanity checking. - // ... unless we're in an old version of PHP, and json_encode() returned - // a string containing 'null'. Then we need to do more sanity checking. - if ( false !== $json && ( version_compare( PHP_VERSION, '5.5', '>=' ) || false === strpos( $json, 'null' ) ) ) { - return $json; - } - - try { - $args[0] = _wp_json_sanity_check( $data, $depth ); - } catch ( Exception $e ) { - return false; - } - - return call_user_func_array( 'json_encode', $args ); - } -endif; - -if ( ! function_exists( '_wp_json_sanity_check' ) ) : - /** - * Perform sanity checks on data that shall be encoded to JSON. - * - * @see wp_json_encode() - * - * @since 4.1.0 - * @access private - * @internal - * - * @param mixed $data Variable (usually an array or object) to encode as JSON. - * @param int $depth Maximum depth to walk through $data. Must be greater than 0. - * @return mixed The sanitized data that shall be encoded to JSON. - */ - function _wp_json_sanity_check( $data, $depth ) { - if ( $depth < 0 ) { - throw new Exception( 'Reached depth limit' ); - } - - if ( is_array( $data ) ) { - $output = array(); - foreach ( $data as $id => $el ) { - // Don't forget to sanitize the ID! - if ( is_string( $id ) ) { - $clean_id = _wp_json_convert_string( $id ); - } else { - $clean_id = $id; - } - - // Check the element type, so that we're only recursing if we really have to. - if ( is_array( $el ) || is_object( $el ) ) { - $output[ $clean_id ] = _wp_json_sanity_check( $el, $depth - 1 ); - } elseif ( is_string( $el ) ) { - $output[ $clean_id ] = _wp_json_convert_string( $el ); - } else { - $output[ $clean_id ] = $el; - } - } - } elseif ( is_object( $data ) ) { - $output = new stdClass; - foreach ( $data as $id => $el ) { - if ( is_string( $id ) ) { - $clean_id = _wp_json_convert_string( $id ); - } else { - $clean_id = $id; - } - - if ( is_array( $el ) || is_object( $el ) ) { - $output->$clean_id = _wp_json_sanity_check( $el, $depth - 1 ); - } elseif ( is_string( $el ) ) { - $output->$clean_id = _wp_json_convert_string( $el ); - } else { - $output->$clean_id = $el; - } - } - } elseif ( is_string( $data ) ) { - return _wp_json_convert_string( $data ); - } else { - return $data; - } - - return $output; - } -endif; - -if ( ! function_exists( '_wp_json_convert_string' ) ) : - /** - * Convert a string to UTF-8, so that it can be safely encoded to JSON. - * - * @see _wp_json_sanity_check() - * - * @since 4.1.0 - * @access private - * @internal - * - * @param string $string The string which is to be converted. - * @return string The checked string. - */ - function _wp_json_convert_string( $string ) { - static $use_mb = null; - if ( is_null( $use_mb ) ) { - $use_mb = function_exists( 'mb_convert_encoding' ); - } - - if ( $use_mb ) { - $encoding = mb_detect_encoding( $string, mb_detect_order(), true ); - if ( $encoding ) { - return mb_convert_encoding( $string, 'UTF-8', $encoding ); - } else { - return mb_convert_encoding( $string, 'UTF-8', 'UTF-8' ); - } - } else { - return wp_check_invalid_utf8( $string, true ); - } - } -endif; |