Infinite scroll for themes.php and theme-install.php. Bump per page limit for themes.php to 999. Props helenyhou, DH-Shredder. see #19815

git-svn-id: https://develop.svn.wordpress.org/trunk@19893 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2012-02-09 21:40:46 +00:00
parent a95f44f53f
commit d9d408fd44
1 changed files with 17 additions and 28 deletions

View File

@ -66,7 +66,7 @@ var wpThemes;
noMoreResults: false, noMoreResults: false,
init : function() { init : function() {
$( '.pagination-links' ).hide(); $('.pagination-links').hide();
inputs.nonce = $('#_ajax_fetch_list_nonce').val(); inputs.nonce = $('#_ajax_fetch_list_nonce').val();
@ -77,7 +77,7 @@ var wpThemes;
// Handle Inputs from Query // Handle Inputs from Query
inputs.search = inputs.queryArray['s']; inputs.search = inputs.queryArray['s'];
inputs.features = inputs.queryArray['features']; inputs.features = inputs.queryArray['features'];
inputs.startPage = parseInt( inputs.queryArray['paged'] ); inputs.startPage = parseInt( inputs.queryArray['paged'] );
inputs.tab = inputs.queryArray['tab']; inputs.tab = inputs.queryArray['tab'];
inputs.type = inputs.queryArray['type']; inputs.type = inputs.queryArray['type'];
@ -86,17 +86,16 @@ var wpThemes;
else else
inputs.startPage++; inputs.startPage++;
// FIXME: Debug Features Array // Cache jQuery objects
// console.log("Features:" + inputs.features);
// Link to output and start polling
inputs.outList = $('#availablethemes'); inputs.outList = $('#availablethemes');
inputs.waiting = $('div.tablenav.bottom').children( 'img.ajax-loading' );
inputs.window = $(window);
// Generate Query // Generate Query
wpThemes.query = new Query(); wpThemes.query = new Query();
// Start Polling // Start Polling
$(window).scroll( function(){ wpThemes.maybeLoad(); }); inputs.window.scroll( function(){ wpThemes.maybeLoad(); } );
}, },
delayedCallback : function( func, delay ) { delayedCallback : function( func, delay ) {
var timeoutTriggered, funcTriggered, funcArgs, funcContext; var timeoutTriggered, funcTriggered, funcArgs, funcContext;
@ -137,21 +136,14 @@ var wpThemes;
( results.rows.indexOf( "no-items" ) != -1 ) ) { ( results.rows.indexOf( "no-items" ) != -1 ) ) {
this.noMoreResults = true; this.noMoreResults = true;
} else { } else {
inputs.outList.append(results.rows); inputs.outList.append( results.rows );
} }
}, },
maybeLoad: function() { maybeLoad: function() {
var self = this, var self = this,
el = $(document), el = $(document),
bottom = el.scrollTop() + $(window).innerHeight(); bottom = el.scrollTop() + inputs.window.innerHeight();
/* // FIXME: Debug scroll trigger.
console.log('scrollTop:'+ el.scrollTop() +
'; scrollBottom:' + bottom +
'; height:' + el.height() +
'; checkVal:' + (el.height() - wpThemes.outListBottomThreshold));
*/
if ( this.noMoreResults || if ( this.noMoreResults ||
!this.query.ready() || !this.query.ready() ||
( bottom < inputs.outList.height() - wpThemes.outListBottomThreshold ) ) ( bottom < inputs.outList.height() - wpThemes.outListBottomThreshold ) )
@ -159,18 +151,15 @@ var wpThemes;
setTimeout( function() { setTimeout( function() {
var newTop = el.scrollTop(), var newTop = el.scrollTop(),
newBottom = newTop + $(window).innerHeight(); newBottom = newTop + inputs.window.innerHeight();
if ( !self.query.ready() || if ( !self.query.ready() ||
( newBottom < inputs.outList.height() - wpThemes.outListBottomThreshold ) ) ( newBottom < inputs.outList.height() - wpThemes.outListBottomThreshold ) )
return; return;
/* FIXME: Create/Add Spinner. inputs.waiting.css( 'visibility', 'visible' ); // Show Spinner
self.waiting.show(); // Show Spinner self.ajax( function() { inputs.waiting.css( 'visibility', 'hidden' ) } ); // Hide Spinner
el.scrollTop( newTop + self.waiting.outerHeight() ); // Scroll down?
self.ajax( function() { self.waiting.hide(); }); // Hide Spinner
*/
self.ajax();
}, wpThemes.timeToTriggerQuery ); }, wpThemes.timeToTriggerQuery );
}, },
parseQuery: function( query ) { parseQuery: function( query ) {
@ -213,13 +202,13 @@ var wpThemes;
var self = this, var self = this,
query = { query = {
action: 'fetch-list', action: 'fetch-list',
tab: inputs.tab,
paged: this.page, paged: this.page,
s: inputs.search, s: inputs.search,
type: inputs.type,
_ajax_fetch_list_nonce: inputs.nonce,
'features[]': inputs.features, 'features[]': inputs.features,
'list_args': list_args, 'list_args': list_args
'tab': inputs.tab,
'type': inputs.type,
'_ajax_fetch_list_nonce': inputs.nonce
}; };
this.querying = true; this.querying = true;