diff options
author | Yury German <blueknight@gentoo.org> | 2017-03-07 20:49:57 -0500 |
---|---|---|
committer | Yury German <blueknight@gentoo.org> | 2017-03-07 20:49:57 -0500 |
commit | 4aef42856734c8d67b06814ff6c97b101869836b (patch) | |
tree | dd94b6858923fa285673285940bcd74be3bb5eb9 /plugins/jetpack/modules/infinite-scroll | |
parent | Update plugin wordpress-mobile-pack 2.2.8 (diff) | |
download | blogs-gentoo-4aef42856734c8d67b06814ff6c97b101869836b.tar.gz blogs-gentoo-4aef42856734c8d67b06814ff6c97b101869836b.tar.bz2 blogs-gentoo-4aef42856734c8d67b06814ff6c97b101869836b.zip |
Jetpack upgrade 4.7
Diffstat (limited to 'plugins/jetpack/modules/infinite-scroll')
5 files changed, 435 insertions, 14 deletions
diff --git a/plugins/jetpack/modules/infinite-scroll/infinity.js b/plugins/jetpack/modules/infinite-scroll/infinity.js index 11001246..687762a0 100644 --- a/plugins/jetpack/modules/infinite-scroll/infinity.js +++ b/plugins/jetpack/modules/infinite-scroll/infinity.js @@ -339,6 +339,8 @@ Scroller.prototype.refresh = function() { if ( response.lastbatch ) { if ( self.click_handle ) { $( '#infinite-handle' ).remove(); + // Update body classes + self.body.addClass( 'infinity-end' ).removeClass( 'infinity-success' ); } else { self.body.trigger( 'infinite-scroll-posts-end' ); } @@ -646,6 +648,8 @@ $( document ).ready( function() { if ( 'object' != typeof infiniteScroll ) return; + $( document.body ).addClass( infiniteScroll.settings.body_class ); + // Set ajaxurl (for brevity) ajaxurl = infiniteScroll.settings.ajaxurl; diff --git a/plugins/jetpack/modules/infinite-scroll/infinity.php b/plugins/jetpack/modules/infinite-scroll/infinity.php index f99ca93f..e9cb166d 100644 --- a/plugins/jetpack/modules/infinite-scroll/infinity.php +++ b/plugins/jetpack/modules/infinite-scroll/infinity.php @@ -300,12 +300,27 @@ class The_Neverending_Home_Page { * Is this guaranteed to be the last batch of posts? */ static function is_last_batch() { - $post_type = get_post_type(); - $entries = wp_count_posts( empty( $post_type ) ? 'post' : $post_type )->publish; - if ( self::wp_query()->get( 'paged' ) && self::wp_query()->get( 'paged' ) > 1 ) { - $entries -= self::get_settings()->posts_per_page * self::wp_query()->get( 'paged' ); + $entries = (int) self::wp_query()->found_posts; + $posts_per_page = self::get_settings()->posts_per_page; + + // This is to cope with an issue in certain themes or setups where posts are returned but found_posts is 0. + if ( 0 == $entries ) { + return (bool) ( count( self::wp_query()->posts ) < $posts_per_page ); + } + $paged = self::wp_query()->get( 'paged' ); + + // Are there enough posts for more than the first page? + if ( $entries <= $posts_per_page ) { + return true; } - return $entries <= self::get_settings()->posts_per_page; + + // Calculate entries left after a certain number of pages + if ( $paged && $paged > 1 ) { + $entries -= $posts_per_page * $paged; + } + + // Are there some entries left to display? + return $entries <= 0; } /** @@ -352,7 +367,7 @@ class The_Neverending_Home_Page { echo '<label>' . $notice . '</label>'; } else { echo '<label><input name="infinite_scroll" type="checkbox" value="1" ' . checked( 1, '' !== get_option( self::$option_name_enabled ), false ) . ' /> ' . esc_html__( 'Check to load posts as you scroll. Uncheck to show clickable button to load posts', 'jetpack' ) . '</label>'; - echo '<p class="description">' . sprintf( esc_html__( 'Shows %s posts on each load.', 'jetpack' ), number_format_i18n( self::get_settings()->posts_per_page ) ) . '</p>'; + echo '<p class="description">' . esc_html( sprintf( _n( 'Shows %s post on each load.', 'Shows %s posts on each load.', self::get_settings()->posts_per_page, 'jetpack' ), number_format_i18n( self::get_settings()->posts_per_page ) ) ) . '</p>'; } } @@ -385,9 +400,6 @@ class The_Neverending_Home_Page { return; } - // Add a class to the body. - add_filter( 'body_class', array( $this, 'body_class' ) ); - // Add our scripts. wp_enqueue_script( 'the-neverending-homepage' ); @@ -411,16 +423,21 @@ class The_Neverending_Home_Page { } /** - * Adds an 'infinite-scroll' class to the body. + * Returns classes to be added to <body>. If it's enabled, 'infinite-scroll'. If set to continuous scroll, adds 'neverending' too. + * + * @since 4.7.0 No longer added as a 'body_class' filter but passed to JS environment and added using JS. + * + * @return string */ - function body_class( $classes ) { + function body_class() { + $classes = ''; // Do not add infinity-scroll class if disabled through the Reading page $disabled = '' === get_option( self::$option_name_enabled ) ? true : false; if ( ! $disabled || 'click' == self::get_settings()->type ) { - $classes[] = 'infinite-scroll'; + $classes = 'infinite-scroll'; if ( 'scroll' == self::get_settings()->type ) - $classes[] = 'neverending'; + $classes .= ' neverending'; } return $classes; @@ -742,6 +759,7 @@ class The_Neverending_Home_Page { } if ( isset( $cpt_text ) ) { + /* translators: %s is the name of a custom post type */ $click_handle_text = sprintf( __( 'Older %s', 'jetpack' ), $cpt_text ); unset( $cpt_text ); } @@ -775,6 +793,7 @@ class The_Neverending_Home_Page { ), 'query_args' => self::get_query_vars(), 'last_post_date' => self::get_last_post_date(), + 'body_class' => self::body_class(), ); // Optional order param @@ -1429,6 +1448,10 @@ class The_Neverending_Home_Page { if ( 'scroll' != self::get_settings()->type || ! self::archive_supports_infinity() ) return; + if ( self::is_last_batch() ) { + return; + } + // Display a footer, either user-specified or a default if ( false !== self::get_settings()->footer_callback && is_callable( self::get_settings()->footer_callback ) ) call_user_func( self::get_settings()->footer_callback, self::get_settings() ); @@ -1448,6 +1471,7 @@ class The_Neverending_Home_Page { __( 'Proudly powered by WordPress', 'jetpack' ) ); $credits .= sprintf( + /* translators: %1$s is the name of a theme */ __( 'Theme: %1$s.', 'jetpack' ), function_exists( 'wp_get_theme' ) ? wp_get_theme()->Name : get_current_theme() ); @@ -1466,7 +1490,7 @@ class The_Neverending_Home_Page { <div id="infinite-footer"> <div class="container"> <div class="blog-info"> - <a id="infinity-blog-title" href="<?php echo home_url( '/' ); ?>" target="_blank" rel="home"> + <a id="infinity-blog-title" href="<?php echo home_url( '/' ); ?>" rel="home"> <?php bloginfo( 'name' ); ?> </a> </div> diff --git a/plugins/jetpack/modules/infinite-scroll/themes/twentyseventeen-rtl.css b/plugins/jetpack/modules/infinite-scroll/themes/twentyseventeen-rtl.css new file mode 100644 index 00000000..396dfc0d --- /dev/null +++ b/plugins/jetpack/modules/infinite-scroll/themes/twentyseventeen-rtl.css @@ -0,0 +1,168 @@ +.infinite-scroll .pagination { + display: none; +} + +.infinite-wrap > article:before, +.infinite-wrap > article:after { + content: ""; + display: table; +} + +.infinite-wrap > article:after { + clear: both; +} + +.infinite-wrap > article { + padding-bottom: 2em; +} + +/* Spinner */ +.site-main .infinite-loader { + clear: both; + color: currentColor; + height: 42px; + margin-bottom: 3.5em; +} + +.blog:not(.has-sidebar) .infinite-loader { + width: 100%; +} + +.site-main .infinite-loader .spinner { + right: 50%!important; +} + +/* Click-to-load */ +#infinite-handle { + clear: both; + margin: 0 7.6923% 2em; + text-align: center; +} + +/* Style "Load More" button */ +.site-main #infinite-handle span { + background: #1a1a1a; + border-radius: 2px; + color: #fff; + font-family: "Libre Franklin", "Helvetica Neue", helvetica, arial, sans-serif; + font-size: inherit; + font-weight: 700; + letter-spacing: 0.046875em; + line-height: 1; + padding: 0.84375em 0.875em 0.78125em; + text-transform: uppercase; +} + +#infinite-handle span:hover, +#infinite-handle span:focus { + background: #767676; +} + +/* Style "Load More" button when dark color scheme is used */ +.colors-dark .site-main #infinite-handle span { + background: #f8f8f8; + border-radius: 2px; + color: #222; + font-family: "Libre Franklin", "Helvetica Neue", helvetica, arial, sans-serif; + font-size: inherit; + font-weight: 700; + letter-spacing: 0.046875em; + line-height: 1; + padding: 0.84375em 0.875em 0.78125em; + text-transform: uppercase; +} + +.colors-dark #infinite-handle span:hover, +.colors-dark #infinite-handle span:focus { + background: #bbb; + columns: #222; +} + +/* Style Infinite Footer */ +#infinite-footer { + position: fixed !important; +} + +#infinite-footer .container { + background-color: #fff; + border-color: #d1d1d1; + padding: 0 7.6923%; +} + +#infinite-footer .blog-info, +#infinite-footer .blog-credits { + font-family: "Libre Franklin", "Helvetica Neue", helvetica, arial, sans-serif; + text-align: center; + width: auto; +} + +#infinite-footer .blog-info a, +#infinite-footer .blog-credits, +#infinite-footer .blog-credits a { + color: #222222; +} + +#infinite-footer .blog-info a:hover, +#infinite-footer .blog-info a:focus, +#infinite-footer .blog-credits a:hover, +#infinite-footer .blog-credits a:focus { + color: #767676; + text-decoration: none; +} + +.infinite-scroll #navigation, +.infinite-scroll.neverending .jetpack-mobile-link, +.infinite-scroll.neverending .site-footer { + display: none; +} + +/* Shows the footer & mobile link again in case all posts have been loaded */ +.infinity-end.neverending .jetpack-mobile-link, +.infinity-end.neverending .site-footer { + display: block; +} + +@media screen and (min-width: 44.375em) { + #infinite-handle { + margin: 0 0 1em 0; + text-align: center; + } + + .has-sidebar #infinite-handle { + text-align: right; + } + + .site-main #infinite-handle span { + display: inline-block; + } +} + +@media screen and (min-width: 48em) { + .infinite-wrap > article { + padding-bottom: 4em; + } +} + +@media screen and (min-width: 48em) { + #infinite-footer .blog-info, + #infinite-footer .blog-credits { + line-height: 35px; + } + + #infinite-footer .blog-info { + font-size: 1.1rem; + } + + #infinite-footer .blog-credits { + font-size: 0.9rem; + } + + .blog:not(.has-sidebar) .infinite-loader { + float: left; + width: 58%; + } + + .site-main .infinite-loader .spinner { + margin-right: -17px; + } +} diff --git a/plugins/jetpack/modules/infinite-scroll/themes/twentyseventeen.css b/plugins/jetpack/modules/infinite-scroll/themes/twentyseventeen.css new file mode 100644 index 00000000..243cfb70 --- /dev/null +++ b/plugins/jetpack/modules/infinite-scroll/themes/twentyseventeen.css @@ -0,0 +1,168 @@ +.infinite-scroll .pagination { + display: none; +} + +.infinite-wrap > article:before, +.infinite-wrap > article:after { + content: ""; + display: table; +} + +.infinite-wrap > article:after { + clear: both; +} + +.infinite-wrap > article { + padding-bottom: 2em; +} + +/* Spinner */ +.site-main .infinite-loader { + clear: both; + color: currentColor; + height: 42px; + margin-bottom: 3.5em; +} + +.blog:not(.has-sidebar) .infinite-loader { + width: 100%; +} + +.site-main .infinite-loader .spinner { + left: 50%!important; +} + +/* Click-to-load */ +#infinite-handle { + clear: both; + margin: 0 7.6923% 2em; + text-align: center; +} + +/* Style "Load More" button */ +.site-main #infinite-handle span { + background: #1a1a1a; + border-radius: 2px; + color: #fff; + font-family: "Libre Franklin", "Helvetica Neue", helvetica, arial, sans-serif; + font-size: inherit; + font-weight: 700; + letter-spacing: 0.046875em; + line-height: 1; + padding: 0.84375em 0.875em 0.78125em; + text-transform: uppercase; +} + +#infinite-handle span:hover, +#infinite-handle span:focus { + background: #767676; +} + +/* Style "Load More" button when dark color scheme is used */ +.colors-dark .site-main #infinite-handle span { + background: #f8f8f8; + border-radius: 2px; + color: #222; + font-family: "Libre Franklin", "Helvetica Neue", helvetica, arial, sans-serif; + font-size: inherit; + font-weight: 700; + letter-spacing: 0.046875em; + line-height: 1; + padding: 0.84375em 0.875em 0.78125em; + text-transform: uppercase; +} + +.colors-dark #infinite-handle span:hover, +.colors-dark #infinite-handle span:focus { + background: #bbb; + columns: #222; +} + +/* Style Infinite Footer */ +#infinite-footer { + position: fixed !important; +} + +#infinite-footer .container { + background-color: #fff; + border-color: #d1d1d1; + padding: 0 7.6923%; +} + +#infinite-footer .blog-info, +#infinite-footer .blog-credits { + font-family: "Libre Franklin", "Helvetica Neue", helvetica, arial, sans-serif; + text-align: center; + width: auto; +} + +#infinite-footer .blog-info a, +#infinite-footer .blog-credits, +#infinite-footer .blog-credits a { + color: #222222; +} + +#infinite-footer .blog-info a:hover, +#infinite-footer .blog-info a:focus, +#infinite-footer .blog-credits a:hover, +#infinite-footer .blog-credits a:focus { + color: #767676; + text-decoration: none; +} + +.infinite-scroll #navigation, +.infinite-scroll.neverending .jetpack-mobile-link, +.infinite-scroll.neverending .site-footer { + display: none; +} + +/* Shows the footer & mobile link again in case all posts have been loaded */ +.infinity-end.neverending .jetpack-mobile-link, +.infinity-end.neverending .site-footer { + display: block; +} + +@media screen and (min-width: 44.375em) { + #infinite-handle { + margin: 0 0 1em 0; + text-align: center; + } + + .has-sidebar #infinite-handle { + text-align: left; + } + + .site-main #infinite-handle span { + display: inline-block; + } +} + +@media screen and (min-width: 48em) { + .infinite-wrap > article { + padding-bottom: 4em; + } +} + +@media screen and (min-width: 48em) { + #infinite-footer .blog-info, + #infinite-footer .blog-credits { + line-height: 35px; + } + + #infinite-footer .blog-info { + font-size: 1.1rem; + } + + #infinite-footer .blog-credits { + font-size: 0.9rem; + } + + .blog:not(.has-sidebar) .infinite-loader { + float: right; + width: 58%; + } + + .site-main .infinite-loader .spinner { + margin-left: -17px; + } +} diff --git a/plugins/jetpack/modules/infinite-scroll/themes/twentyseventeen.php b/plugins/jetpack/modules/infinite-scroll/themes/twentyseventeen.php new file mode 100644 index 00000000..766b240e --- /dev/null +++ b/plugins/jetpack/modules/infinite-scroll/themes/twentyseventeen.php @@ -0,0 +1,57 @@ +<?php +/** + * Infinite Scroll Theme Assets + * + * Register support for Twenty Seventeen. + */ + +/** + * Add theme support for infinite scroll + */ +function jetpack_twentyseventeen_infinite_scroll_init() { + add_theme_support( 'infinite-scroll', array( + 'container' => 'main', + 'render' => 'jetpack_twentyseventeen_infinite_scroll_render', + 'footer' => 'content', + 'footer_widgets' => jetpack_twentyseventeen_has_footer_widgets(), + ) ); +} +add_action( 'init', 'jetpack_twentyseventeen_infinite_scroll_init' ); + +/** + * Custom render function for Infinite Scroll. + */ +function jetpack_twentyseventeen_infinite_scroll_render() { + while ( have_posts() ) { + the_post(); + if ( is_search() ) { + get_template_part( 'template-parts/post/content', 'search' ); + } else { + get_template_part( 'template-parts/post/content', get_post_format() ); + } + } +} + +/** + * Custom function to check for the presence of footer widgets or the social links menu + */ +function jetpack_twentyseventeen_has_footer_widgets() { + if ( is_active_sidebar( 'sidebar-2' ) || + is_active_sidebar( 'sidebar-3' ) || + has_nav_menu( 'social' ) ) { + return true; + } else { + return false; + } +} + +/** + * Enqueue CSS stylesheet with theme styles for Infinite Scroll. + */ +function jetpack_twentyseventeen_infinite_scroll_enqueue_styles() { + if ( wp_script_is( 'the-neverending-homepage' ) ) { + wp_enqueue_style( 'infinity-twentyseventeen', plugins_url( 'twentyseventeen.css', __FILE__ ), array( 'the-neverending-homepage' ), '20161219' ); + wp_style_add_data( 'infinity-twentyseventeen', 'rtl', 'replace' ); + } +} +add_action( 'wp_enqueue_scripts', 'jetpack_twentyseventeen_infinite_scroll_enqueue_styles', 25 ); |