2012-04-10 02:34:39 +02:00
|
|
|
/**
|
|
|
|
* Theme Browsing
|
|
|
|
*
|
|
|
|
* Controls visibility of theme details on manage and install themes pages.
|
|
|
|
*/
|
|
|
|
jQuery( function($) {
|
|
|
|
$('#availablethemes').on( 'click', '.theme-detail', function (event) {
|
|
|
|
$(this).parent().siblings('.themedetaildiv').toggle();
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
2012-03-07 18:35:17 +01:00
|
|
|
* Theme Install
|
|
|
|
*
|
|
|
|
* Displays theme previews on theme install pages.
|
|
|
|
*/
|
|
|
|
jQuery( function($) {
|
|
|
|
var preview = $('#theme-installer'),
|
|
|
|
info = preview.find('.install-theme-info'),
|
|
|
|
panel = preview.find('.wp-full-overlay-main'),
|
|
|
|
body = $( document.body );
|
|
|
|
|
|
|
|
preview.on( 'click', '.close-full-overlay', function( event ) {
|
|
|
|
preview.fadeOut( 200, function() {
|
|
|
|
panel.empty();
|
|
|
|
body.removeClass('theme-installer-active full-overlay-active');
|
|
|
|
});
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
|
|
|
|
preview.on( 'click', '.collapse-sidebar', function( event ) {
|
|
|
|
preview.toggleClass('collapsed');
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
|
2012-03-07 19:24:34 +01:00
|
|
|
$('#availablethemes').on( 'click', '.installable-theme', function( event ) {
|
2012-03-07 18:35:17 +01:00
|
|
|
var src;
|
|
|
|
|
|
|
|
info.html( $(this).find('.install-theme-info').html() );
|
|
|
|
src = info.find( '.theme-preview-url' ).val();
|
|
|
|
panel.html( '<iframe src="' + src + '" />');
|
|
|
|
preview.fadeIn( 200, function() {
|
|
|
|
body.addClass('theme-installer-active full-overlay-active');
|
|
|
|
});
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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-03-02 23:09:26 +01:00
|
|
|
/**
|
|
|
|
* Class that provides infinite scroll for Themes admin screens
|
|
|
|
*
|
|
|
|
* @since 3.4
|
|
|
|
*
|
|
|
|
* @uses ajaxurl
|
|
|
|
* @uses list_args
|
|
|
|
* @uses theme_list_args
|
|
|
|
* @uses $('#_ajax_fetch_list_nonce').val()
|
|
|
|
* */
|
|
|
|
var ThemeScroller;
|
2012-02-09 18:20:26 +01:00
|
|
|
(function($){
|
2012-02-21 20:44:10 +01:00
|
|
|
ThemeScroller = {
|
2012-03-02 23:09:26 +01:00
|
|
|
querying: false,
|
2012-02-21 20:44:10 +01:00
|
|
|
scrollPollingDelay: 500,
|
|
|
|
failedRetryDelay: 4000,
|
|
|
|
outListBottomThreshold: 300,
|
|
|
|
|
2012-03-02 23:09:26 +01:00
|
|
|
/**
|
|
|
|
* Initializer
|
|
|
|
*
|
|
|
|
* @since 3.4
|
|
|
|
* @access private
|
|
|
|
*/
|
2012-02-21 20:44:10 +01:00
|
|
|
init: function() {
|
2012-03-21 21:17:47 +01:00
|
|
|
var self = this;
|
2012-03-02 23:09:26 +01:00
|
|
|
|
|
|
|
// Get out early if we don't have the required arguments.
|
|
|
|
if ( typeof ajaxurl === 'undefined' ||
|
|
|
|
typeof list_args === 'undefined' ||
|
|
|
|
typeof theme_list_args === 'undefined' ) {
|
|
|
|
$('.pagination-links').show();
|
|
|
|
return;
|
|
|
|
}
|
2012-02-21 20:44:10 +01:00
|
|
|
|
|
|
|
// Handle inputs
|
|
|
|
this.nonce = $('#_ajax_fetch_list_nonce').val();
|
2012-03-21 21:17:47 +01:00
|
|
|
this.nextPage = ( theme_list_args.paged + 1 );
|
2012-02-21 20:44:10 +01:00
|
|
|
|
|
|
|
// Cache jQuery selectors
|
|
|
|
this.$outList = $('#availablethemes');
|
|
|
|
this.$spinner = $('div.tablenav.bottom').children( 'img.ajax-loading' );
|
|
|
|
this.$window = $(window);
|
|
|
|
this.$document = $(document);
|
|
|
|
|
2012-03-02 23:09:26 +01:00
|
|
|
/**
|
|
|
|
* If there are more pages to query, then start polling to track
|
|
|
|
* when user hits the bottom of the current page
|
|
|
|
*/
|
2012-03-21 21:17:47 +01:00
|
|
|
if ( theme_list_args.total_pages >= this.nextPage )
|
2012-02-21 20:44:10 +01:00
|
|
|
this.pollInterval =
|
2012-02-27 20:46:52 +01:00
|
|
|
setInterval( function() {
|
2012-02-21 20:44:10 +01:00
|
|
|
return self.poll();
|
|
|
|
}, this.scrollPollingDelay );
|
2012-02-09 18:20:26 +01:00
|
|
|
},
|
2012-03-02 23:09:26 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks to see if user has scrolled to bottom of page.
|
|
|
|
* If so, requests another page of content from self.ajax().
|
|
|
|
*
|
|
|
|
* @since 3.4
|
|
|
|
* @access private
|
|
|
|
*/
|
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-03-02 23:09:26 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Applies results passed from this.ajax() to $outList
|
|
|
|
*
|
|
|
|
* @since 3.4
|
|
|
|
* @access private
|
|
|
|
*
|
|
|
|
* @param results Array with results from this.ajax() query.
|
|
|
|
*/
|
2012-02-21 20:44:10 +01:00
|
|
|
process: function( results ) {
|
2012-03-21 21:17:47 +01:00
|
|
|
if ( results === undefined ) {
|
2012-02-21 20:44:10 +01:00
|
|
|
clearInterval( this.pollInterval );
|
2012-02-09 18:20:26 +01:00
|
|
|
return;
|
2012-02-21 20:44:10 +01:00
|
|
|
}
|
|
|
|
|
2012-03-02 23:09:26 +01:00
|
|
|
if ( this.nextPage > theme_list_args.total_pages )
|
2012-02-21 20:44:10 +01:00
|
|
|
clearInterval( this.pollInterval );
|
2012-02-09 18:20:26 +01:00
|
|
|
|
2012-03-02 23:09:26 +01:00
|
|
|
if ( this.nextPage <= ( theme_list_args.total_pages + 1 ) )
|
2012-02-21 20:44:10 +01:00
|
|
|
this.$outList.append( results.rows );
|
|
|
|
},
|
2012-03-02 23:09:26 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Queries next page of themes
|
|
|
|
*
|
|
|
|
* @since 3.4
|
|
|
|
* @access private
|
|
|
|
*/
|
2012-02-21 20:44:10 +01:00
|
|
|
ajax: function() {
|
|
|
|
var self = this;
|
2012-03-02 23:09:26 +01:00
|
|
|
|
2012-02-21 20:44:10 +01:00
|
|
|
this.querying = true;
|
2012-02-09 18:20:26 +01:00
|
|
|
|
2012-02-21 20:44:10 +01:00
|
|
|
var query = {
|
|
|
|
action: 'fetch-list',
|
|
|
|
paged: this.nextPage,
|
2012-03-02 23:09:26 +01:00
|
|
|
s: theme_list_args.search,
|
|
|
|
tab: theme_list_args.tab,
|
|
|
|
type: theme_list_args.type,
|
2012-02-21 20:44:10 +01:00
|
|
|
_ajax_fetch_list_nonce: this.nonce,
|
2012-03-02 23:09:26 +01:00
|
|
|
'features[]': theme_list_args.features,
|
2012-02-21 20:44:10 +01:00
|
|
|
'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;
|
2012-03-02 23:09:26 +01:00
|
|
|
setTimeout( function() { self.ajax(); }, self.failedRetryDelay );
|
2012-02-21 20:44:10 +01:00
|
|
|
});
|
2012-02-09 18:20:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-02 23:09:26 +01:00
|
|
|
$(document).ready( function($) {
|
|
|
|
ThemeScroller.init();
|
|
|
|
});
|
2012-02-09 18:20:26 +01:00
|
|
|
|
|
|
|
})(jQuery);
|