Skip to content

Instantly share code, notes, and snippets.

@bradyvercher
Last active December 20, 2015 08:39
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradyvercher/6102036 to your computer and use it in GitHub Desktop.
Save bradyvercher/6102036 to your computer and use it in GitHub Desktop.
WordPress Plugin: Infinite scroll support for WP List Tables in the WordPress admin panel.
<?php
/**
* Plugin Name: Infinite WP List Tables
* Description: Infinite scroll support for WP List Tables in the WordPress admin panel.
* Version: 0.1.0
* Author: Brady Vercher
* Author URI: http://www.blazersix.com/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
/**
* Enqueue and print scripts and styles in the admin footer.
*/
function iwplt_admin_footer() {
// Enqueue the Infinite Scroll script.
wp_enqueue_script(
'jquery-infinite-scroll',
'//cdn.jsdelivr.net/jquery.infinitescroll/2.0b2/jquery.infinitescroll.js',
array( 'jquery' ),
'2.0b2',
true
);
wp_localize_script( 'jquery-infinite-scroll', 'iwpltL10n', array(
'loadingMessage' => __( 'Loading&hellip;', 'iwplt' ),
) );
?>
<script type="text/javascript">
jQuery(function( $ ) {
var $msgEl = $( '<tr id="iwplt-loading"><td class="colspanchange"></td></tr>' );
// Ensure the loading message cell spans the appropriate number of columns.
$msgEl.find( '.colspanchange' )
.attr( 'colspan', $( '.wp-list-table thead tr' ).children( ':visible' ).length )
.append( '<span class="spinner"></span> ' )
.append( iwpltL10n.loadingMessage );
$( '#the-list' ).infinitescroll({
loading: {
finished: function() {
$( '#iwplt-loading' ).hide();
},
msg: $msgEl
},
navSelector: '.pagination-links',
nextSelector: '.next-page',
itemSelector: '#the-list tr',
contentSelector: '#the-list',
maxPage: $( '.total-pages' ).first().text()
});
});
</script>
<style type="text/css">
tr#iwplt-loading td {
padding: 10px;
vertical-align: middle;
}
tr#iwplt-loading .spinner {
display: inline-block;
float: none;
margin-top: 0;
vertical-align: middle;
}
</style>
<?php
}
add_action( 'admin_footer', 'iwplt_admin_footer' );
@lobo
Copy link

lobo commented Jan 7, 2014

Hi! I'm having a difficulty in scrolling in the main Wordpress admin panel (when editing the pages - I have several pages, but just can access to the first one in the list). If this is the fix, where am I supposed to paste this file? wp-includes folder? wp-content folder? or where? Thanks in advance, from Buenos Aires :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment