2013-11-15 09:16:08 -05:00
|
|
|
/* global ajaxurl, list_args, theme_list_args */
|
|
|
|
|
|
|
|
var theme_viewer;
|
|
|
|
|
2013-11-13 15:58:05 -05:00
|
|
|
/**
|
|
|
|
* Theme Browsing
|
|
|
|
*
|
|
|
|
* Controls visibility of theme details on manage and install themes pages.
|
|
|
|
*/
|
|
|
|
jQuery( function($) {
|
|
|
|
$('#availablethemes').on( 'click', '.theme-detail', function (event) {
|
|
|
|
var theme = $(this).closest('.available-theme'),
|
|
|
|
details = theme.find('.themedetaildiv');
|
|
|
|
|
|
|
|
if ( ! details.length ) {
|
|
|
|
details = theme.find('.install-theme-info .theme-details');
|
|
|
|
details = details.clone().addClass('themedetaildiv').appendTo( theme ).hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
details.toggle();
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Theme Browser Thickbox
|
|
|
|
*
|
|
|
|
* Aligns theme browser thickbox.
|
|
|
|
*/
|
|
|
|
var tb_position;
|
|
|
|
jQuery(document).ready( function($) {
|
|
|
|
tb_position = function() {
|
|
|
|
var tbWindow = $('#TB_window'), width = $(window).width(), H = $(window).height(), W = ( 1040 < width ) ? 1040 : width, adminbar_height = 0;
|
|
|
|
|
2013-11-15 09:16:08 -05:00
|
|
|
if ( $('body.admin-bar').length ) {
|
2013-11-13 15:58:05 -05:00
|
|
|
adminbar_height = 28;
|
2013-11-15 09:16:08 -05:00
|
|
|
}
|
2013-11-13 15:58:05 -05:00
|
|
|
|
|
|
|
if ( tbWindow.size() ) {
|
|
|
|
tbWindow.width( W - 50 ).height( H - 45 - adminbar_height );
|
|
|
|
$('#TB_iframeContent').width( W - 50 ).height( H - 75 - adminbar_height );
|
|
|
|
tbWindow.css({'margin-left': '-' + parseInt( ( ( W - 50 ) / 2 ), 10 ) + 'px'});
|
2013-11-15 09:16:08 -05:00
|
|
|
if ( typeof document.body.style.maxWidth !== 'undefined' ) {
|
2013-11-13 15:58:05 -05:00
|
|
|
tbWindow.css({'top': 20 + adminbar_height + 'px','margin-top':'0'});
|
2013-11-15 09:16:08 -05:00
|
|
|
}
|
|
|
|
}
|
2013-11-13 15:58:05 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
$(window).resize(function(){ tb_position(); });
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Theme Install
|
|
|
|
*
|
|
|
|
* Displays theme previews on theme install pages.
|
|
|
|
*/
|
|
|
|
jQuery( function($) {
|
2013-11-15 09:16:08 -05:00
|
|
|
if ( ! window.postMessage ) {
|
2013-11-13 15:58:05 -05:00
|
|
|
return;
|
2013-11-15 09:16:08 -05:00
|
|
|
}
|
2013-11-13 15:58:05 -05:00
|
|
|
|
|
|
|
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' ).toggleClass( 'expanded' );
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#availablethemes').on( 'click', '.install-theme-preview', function( event ) {
|
|
|
|
var src;
|
|
|
|
|
|
|
|
info.html( $(this).closest('.installable-theme').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();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
var ThemeViewer;
|
|
|
|
|
|
|
|
(function($){
|
2013-11-15 09:16:08 -05:00
|
|
|
ThemeViewer = function() {
|
2013-11-13 15:58:05 -05:00
|
|
|
|
|
|
|
function init() {
|
|
|
|
$( '#filter-click, #mini-filter-click' ).unbind( 'click' ).click( function() {
|
|
|
|
$( '#filter-click' ).toggleClass( 'current' );
|
|
|
|
$( '#filter-box' ).slideToggle();
|
|
|
|
$( '#current-theme' ).slideToggle( 300 );
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
$( '#filter-box :checkbox' ).unbind( 'click' ).click( function() {
|
|
|
|
var count = $( '#filter-box :checked' ).length,
|
|
|
|
text = $( '#filter-click' ).text();
|
|
|
|
|
2013-11-15 09:16:08 -05:00
|
|
|
if ( text.indexOf( '(' ) !== -1 ) {
|
2013-11-13 15:58:05 -05:00
|
|
|
text = text.substr( 0, text.indexOf( '(' ) );
|
2013-11-15 09:16:08 -05:00
|
|
|
}
|
2013-11-13 15:58:05 -05:00
|
|
|
|
2013-11-15 09:16:08 -05:00
|
|
|
if ( count === 0 ) {
|
2013-11-13 15:58:05 -05:00
|
|
|
$( '#filter-click' ).text( text );
|
2013-11-15 09:16:08 -05:00
|
|
|
} else {
|
2013-11-13 15:58:05 -05:00
|
|
|
$( '#filter-click' ).text( text + ' (' + count + ')' );
|
2013-11-15 09:16:08 -05:00
|
|
|
}
|
2013-11-13 15:58:05 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
/* $('#filter-box :submit').unbind( 'click' ).click(function() {
|
|
|
|
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 );
|
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}); */
|
|
|
|
}
|
|
|
|
|
|
|
|
// These are the functions we expose
|
|
|
|
var api = {
|
|
|
|
init: init
|
|
|
|
};
|
|
|
|
|
2013-11-15 09:16:08 -05:00
|
|
|
return api;
|
|
|
|
};
|
2013-11-13 15:58:05 -05:00
|
|
|
})(jQuery);
|
|
|
|
|
2013-11-15 09:16:08 -05:00
|
|
|
jQuery( document ).ready( function() {
|
2013-11-13 15:58:05 -05:00
|
|
|
theme_viewer = new ThemeViewer();
|
|
|
|
theme_viewer.init();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
(function($){
|
|
|
|
ThemeScroller = {
|
|
|
|
querying: false,
|
|
|
|
scrollPollingDelay: 500,
|
|
|
|
failedRetryDelay: 4000,
|
|
|
|
outListBottomThreshold: 300,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializer
|
|
|
|
*
|
|
|
|
* @since 3.4
|
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
init: function() {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
// Get out early if we don't have the required arguments.
|
|
|
|
if ( typeof ajaxurl === 'undefined' ||
|
2013-11-15 09:16:08 -05:00
|
|
|
typeof list_args === 'undefined' ||
|
|
|
|
typeof theme_list_args === 'undefined' ) {
|
|
|
|
|
|
|
|
$('.pagination-links').show();
|
2013-11-13 15:58:05 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle inputs
|
|
|
|
this.nonce = $('#_ajax_fetch_list_nonce').val();
|
|
|
|
this.nextPage = ( theme_list_args.paged + 1 );
|
|
|
|
|
|
|
|
// Cache jQuery selectors
|
|
|
|
this.$outList = $('#availablethemes');
|
|
|
|
this.$spinner = $('div.tablenav.bottom').children( '.spinner' );
|
|
|
|
this.$window = $(window);
|
|
|
|
this.$document = $(document);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If there are more pages to query, then start polling to track
|
|
|
|
* when user hits the bottom of the current page
|
|
|
|
*/
|
2013-11-15 09:16:08 -05:00
|
|
|
if ( theme_list_args.total_pages >= this.nextPage ) {
|
|
|
|
this.pollInterval = setInterval( function() {
|
|
|
|
return self.poll();
|
|
|
|
}, this.scrollPollingDelay );
|
|
|
|
}
|
2013-11-13 15:58:05 -05: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
|
|
|
|
*/
|
|
|
|
poll: function() {
|
|
|
|
var bottom = this.$document.scrollTop() + this.$window.innerHeight();
|
|
|
|
|
|
|
|
if ( this.querying ||
|
2013-11-15 09:16:08 -05:00
|
|
|
( bottom < this.$outList.height() - this.outListBottomThreshold ) ) {
|
2013-11-13 15:58:05 -05:00
|
|
|
return;
|
2013-11-15 09:16:08 -05:00
|
|
|
}
|
2013-11-13 15:58:05 -05:00
|
|
|
|
|
|
|
this.ajax();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Applies results passed from this.ajax() to $outList
|
|
|
|
*
|
|
|
|
* @since 3.4
|
|
|
|
* @access private
|
|
|
|
*
|
|
|
|
* @param results Array with results from this.ajax() query.
|
|
|
|
*/
|
|
|
|
process: function( results ) {
|
|
|
|
if ( results === undefined ) {
|
|
|
|
clearInterval( this.pollInterval );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-15 09:16:08 -05:00
|
|
|
if ( this.nextPage > theme_list_args.total_pages ) {
|
2013-11-13 15:58:05 -05:00
|
|
|
clearInterval( this.pollInterval );
|
2013-11-15 09:16:08 -05:00
|
|
|
}
|
2013-11-13 15:58:05 -05:00
|
|
|
|
2013-11-15 09:16:08 -05:00
|
|
|
if ( this.nextPage <= ( theme_list_args.total_pages + 1 ) ) {
|
2013-11-13 15:58:05 -05:00
|
|
|
this.$outList.append( results.rows );
|
2013-11-15 09:16:08 -05:00
|
|
|
}
|
2013-11-13 15:58:05 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Queries next page of themes
|
|
|
|
*
|
|
|
|
* @since 3.4
|
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
ajax: function() {
|
2013-11-15 09:16:08 -05:00
|
|
|
var self = this,
|
|
|
|
query = {
|
2013-11-13 15:58:05 -05:00
|
|
|
action: 'fetch-list',
|
|
|
|
paged: this.nextPage,
|
|
|
|
s: theme_list_args.search,
|
|
|
|
tab: theme_list_args.tab,
|
|
|
|
type: theme_list_args.type,
|
|
|
|
_ajax_fetch_list_nonce: this.nonce,
|
|
|
|
'features[]': theme_list_args.features,
|
|
|
|
'list_args': list_args
|
|
|
|
};
|
|
|
|
|
2013-11-15 09:16:08 -05:00
|
|
|
this.querying = true;
|
|
|
|
|
2013-11-13 15:58:05 -05:00
|
|
|
this.$spinner.show();
|
|
|
|
$.getJSON( ajaxurl, query )
|
|
|
|
.done( function( response ) {
|
|
|
|
self.nextPage++;
|
|
|
|
self.process( response );
|
|
|
|
self.$spinner.hide();
|
|
|
|
self.querying = false;
|
|
|
|
})
|
|
|
|
.fail( function() {
|
|
|
|
self.$spinner.hide();
|
|
|
|
self.querying = false;
|
|
|
|
setTimeout( function() { self.ajax(); }, self.failedRetryDelay );
|
|
|
|
});
|
|
|
|
}
|
2013-11-15 09:16:08 -05:00
|
|
|
};
|
2013-11-13 15:58:05 -05:00
|
|
|
|
2013-11-15 09:16:08 -05:00
|
|
|
$(document).ready( function() {
|
2013-11-13 15:58:05 -05:00
|
|
|
ThemeScroller.init();
|
|
|
|
});
|
|
|
|
|
|
|
|
})(jQuery);
|