2010-09-24 20:50:31 +02:00
|
|
|
var ThemeViewer;
|
|
|
|
|
|
|
|
(function($){
|
|
|
|
ThemeViewer = function( args ) {
|
|
|
|
|
|
|
|
function init() {
|
|
|
|
$( '#filter-click, #mini-filter-click' ).unbind( 'click' ).click( function() {
|
|
|
|
$( '#filter-click' ).toggleClass( 'current' );
|
2010-11-23 21:17:22 +01:00
|
|
|
$( '#filter-box' ).slideToggle();
|
2010-09-24 20:50:31 +02:00
|
|
|
$( '#current-theme' ).slideToggle( 300 );
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2010-11-23 21:17:22 +01:00
|
|
|
$( '#filter-box :checkbox' ).unbind( 'click' ).click( function() {
|
2010-11-23 21:20:44 +01:00
|
|
|
var count = $( '#filter-box :checked' ).length,
|
|
|
|
text = $( '#filter-click' ).text();
|
|
|
|
|
|
|
|
if ( text.indexOf( '(' ) != -1 )
|
|
|
|
text = text.substr( 0, text.indexOf( '(' ) );
|
|
|
|
|
|
|
|
if ( count == 0 )
|
|
|
|
$( '#filter-click' ).text( text );
|
|
|
|
else
|
|
|
|
$( '#filter-click' ).text( text + ' (' + count + ')' );
|
2010-09-24 20:50:31 +02:00
|
|
|
});
|
2010-11-23 21:17:22 +01:00
|
|
|
|
2011-01-18 18:32:35 +01:00
|
|
|
/* $('#filter-box :submit').unbind( 'click' ).click(function() {
|
2010-11-23 21:17:22 +01:00
|
|
|
var features = [];
|
|
|
|
$('#filter-box :checked').each(function() {
|
|
|
|
features.push($(this).val());
|
|
|
|
});
|
|
|
|
|
|
|
|
listTable.update_rows({'features': features}, true, function() {
|
|
|
|
$( '#filter-click' ).toggleClass( 'current' );
|
|
|
|
$( '#filter-box' ).slideToggle();
|
|
|
|
$( '#current-theme' ).slideToggle( 300 );
|
|
|
|
});
|
2010-12-13 22:21:50 +01:00
|
|
|
|
2010-11-23 21:17:22 +01:00
|
|
|
return false;
|
2011-01-18 18:32:35 +01:00
|
|
|
}); */
|
2010-09-24 20:50:31 +02:00
|
|
|
}
|
2010-10-21 21:55:28 +02:00
|
|
|
|
2010-09-24 20:50:31 +02:00
|
|
|
// These are the functions we expose
|
|
|
|
var api = {
|
|
|
|
init: init
|
|
|
|
};
|
|
|
|
|
2012-02-21 20:44:10 +01:00
|
|
|
return api;
|
2010-09-24 20:50:31 +02:00
|
|
|
}
|
|
|
|
})(jQuery);
|
|
|
|
|
|
|
|
jQuery( document ).ready( function($) {
|
|
|
|
theme_viewer = new ThemeViewer();
|
|
|
|
theme_viewer.init();
|
2010-11-23 01:06:15 +01:00
|
|
|
});
|
2012-02-09 18:20:26 +01:00
|
|
|
|
2012-02-21 20:44:10 +01:00
|
|
|
var ThemeScroller;
|
2012-02-09 18:20:26 +01:00
|
|
|
|
|
|
|
(function($){
|
2012-02-21 20:44:10 +01:00
|
|
|
ThemeScroller = {
|
|
|
|
// Inputs
|
|
|
|
nonce: '',
|
|
|
|
search: '',
|
|
|
|
tab: '',
|
|
|
|
type: '',
|
|
|
|
nextPage: 2,
|
|
|
|
features: {},
|
|
|
|
|
|
|
|
// Preferences
|
|
|
|
scrollPollingDelay: 500,
|
|
|
|
failedRetryDelay: 4000,
|
|
|
|
outListBottomThreshold: 300,
|
|
|
|
|
|
|
|
// Flags
|
|
|
|
scrolling: false,
|
|
|
|
querying: false,
|
|
|
|
|
|
|
|
init: function() {
|
|
|
|
var self = this,
|
|
|
|
startPage,
|
|
|
|
queryArray = {},
|
|
|
|
queryString = window.location.search;
|
|
|
|
|
|
|
|
// We're using infinite scrolling, so hide all pagination.
|
2012-02-09 22:40:46 +01:00
|
|
|
$('.pagination-links').hide();
|
2012-02-09 18:20:26 +01:00
|
|
|
|
2012-02-21 20:44:10 +01:00
|
|
|
// Parse GET query string
|
|
|
|
queryArray = this.parseQuery( queryString.substring( 1 ) );
|
|
|
|
|
|
|
|
// Handle inputs
|
|
|
|
this.nonce = $('#_ajax_fetch_list_nonce').val();
|
|
|
|
this.search = queryArray['s'];
|
|
|
|
this.features = queryArray['features'];
|
|
|
|
this.tab = queryArray['tab'];
|
|
|
|
this.type = queryArray['type'];
|
|
|
|
|
|
|
|
startPage = parseInt( queryArray['paged'], 10 );
|
|
|
|
if ( ! isNaN( startPage ) )
|
|
|
|
this.nextPage = ( startPage + 1 );
|
|
|
|
|
|
|
|
// Cache jQuery selectors
|
|
|
|
this.$outList = $('#availablethemes');
|
|
|
|
this.$spinner = $('div.tablenav.bottom').children( 'img.ajax-loading' );
|
|
|
|
this.$window = $(window);
|
|
|
|
this.$document = $(document);
|
|
|
|
|
|
|
|
if ( $('.tablenav-pages').length )
|
|
|
|
this.pollInterval =
|
|
|
|
setInterval( function() {
|
|
|
|
return self.poll();
|
|
|
|
}, this.scrollPollingDelay );
|
2012-02-09 18:20:26 +01:00
|
|
|
},
|
2012-02-21 20:44:10 +01:00
|
|
|
poll: function() {
|
|
|
|
var bottom = this.$document.scrollTop() + this.$window.innerHeight();
|
|
|
|
|
|
|
|
if ( this.querying ||
|
|
|
|
( bottom < this.$outList.height() - this.outListBottomThreshold ) )
|
|
|
|
return;
|
2012-02-09 18:20:26 +01:00
|
|
|
|
2012-02-21 20:44:10 +01:00
|
|
|
this.ajax();
|
2012-02-09 18:20:26 +01:00
|
|
|
},
|
2012-02-21 20:44:10 +01:00
|
|
|
process: function( results ) {
|
2012-02-09 18:20:26 +01:00
|
|
|
if ( ( results === undefined ) ||
|
2012-02-21 20:44:10 +01:00
|
|
|
( results.rows.indexOf( 'no-items' ) != -1 ) ) {
|
|
|
|
clearInterval( this.pollInterval );
|
2012-02-09 18:20:26 +01:00
|
|
|
return;
|
2012-02-21 20:44:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var totalPages = parseInt( results.total_pages, 10 );
|
|
|
|
if ( this.nextPage > totalPages )
|
|
|
|
clearInterval( this.pollInterval );
|
2012-02-09 18:20:26 +01:00
|
|
|
|
2012-02-21 20:44:10 +01:00
|
|
|
if ( this.nextPage <= ( totalPages + 1 ) )
|
|
|
|
this.$outList.append( results.rows );
|
|
|
|
},
|
|
|
|
ajax: function() {
|
|
|
|
var self = this;
|
|
|
|
this.querying = true;
|
2012-02-09 18:20:26 +01:00
|
|
|
|
2012-02-21 20:44:10 +01:00
|
|
|
var query = {
|
|
|
|
action: 'fetch-list',
|
|
|
|
tab: this.tab,
|
|
|
|
paged: this.nextPage,
|
|
|
|
s: this.search,
|
|
|
|
type: this.type,
|
|
|
|
_ajax_fetch_list_nonce: this.nonce,
|
|
|
|
'features[]': this.features,
|
|
|
|
'list_args': list_args
|
|
|
|
};
|
2012-02-09 18:20:26 +01:00
|
|
|
|
2012-02-21 20:44:10 +01:00
|
|
|
this.$spinner.css( 'visibility', 'visible' );
|
|
|
|
$.getJSON( ajaxurl, query )
|
|
|
|
.done( function( response ) {
|
|
|
|
self.nextPage++;
|
|
|
|
self.process( response );
|
|
|
|
self.$spinner.css( 'visibility', 'hidden' );
|
|
|
|
self.querying = false;
|
|
|
|
})
|
|
|
|
.fail( function() {
|
|
|
|
self.$spinner.css( 'visibility', 'hidden' );
|
|
|
|
self.querying = false;
|
|
|
|
setTimeout( function() { self.ajax(); }, self.failedRetryDelay )
|
|
|
|
});
|
2012-02-09 18:20:26 +01:00
|
|
|
},
|
|
|
|
parseQuery: function( query ) {
|
2012-02-21 20:44:10 +01:00
|
|
|
var params = {};
|
|
|
|
if ( ! query )
|
|
|
|
return params;
|
|
|
|
|
|
|
|
var pairs = query.split( /[;&]/ );
|
|
|
|
for ( var i = 0; i < pairs.length; i++ ) {
|
|
|
|
var keyVal = pairs[i].split( '=' );
|
|
|
|
|
|
|
|
if ( ! keyVal || keyVal.length != 2 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
var key = unescape( keyVal[0] );
|
|
|
|
var val = unescape( keyVal[1] );
|
|
|
|
val = val.replace( /\+/g, ' ' );
|
|
|
|
key = key.replace( /\[.*\]$/g, '' );
|
|
|
|
|
|
|
|
if ( params[key] === undefined ) {
|
|
|
|
params[key] = val;
|
2012-02-09 18:20:26 +01:00
|
|
|
} else {
|
2012-02-21 20:44:10 +01:00
|
|
|
var oldVal = params[key];
|
|
|
|
if ( ! $.isArray( params[key] ) )
|
|
|
|
params[key] = new Array( oldVal, val );
|
2012-02-09 18:20:26 +01:00
|
|
|
else
|
2012-02-21 20:44:10 +01:00
|
|
|
params[key].push( val );
|
2012-02-09 18:20:26 +01:00
|
|
|
}
|
|
|
|
}
|
2012-02-21 20:44:10 +01:00
|
|
|
return params;
|
2012-02-09 18:20:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-21 20:44:10 +01:00
|
|
|
$(document).ready( function( $ ) { ThemeScroller.init(); });
|
2012-02-09 18:20:26 +01:00
|
|
|
|
|
|
|
})(jQuery);
|