4 * Controls visibility of theme details on manage and install themes pages.
7 $('#availablethemes').on( 'click', '.theme-detail', function (event) {
8 var theme = $(this).closest('.available-theme'),
9 details = theme.find('.themedetaildiv');
11 if ( ! details.length ) {
12 details = theme.find('.install-theme-info .theme-details');
13 details = details.clone().addClass('themedetaildiv').appendTo( theme ).hide();
17 event.preventDefault();
24 * Displays theme previews on theme install pages.
27 if( ! window.postMessage )
30 var preview = $('#theme-installer'),
31 info = preview.find('.install-theme-info'),
32 panel = preview.find('.wp-full-overlay-main'),
33 body = $( document.body );
35 preview.on( 'click', '.close-full-overlay', function( event ) {
36 preview.fadeOut( 200, function() {
38 body.removeClass('theme-installer-active full-overlay-active');
40 event.preventDefault();
43 preview.on( 'click', '.collapse-sidebar', function( event ) {
44 preview.toggleClass( 'collapsed' ).toggleClass( 'expanded' );
45 event.preventDefault();
48 $('#availablethemes').on( 'click', '.install-theme-preview', function( event ) {
51 info.html( $(this).closest('.installable-theme').find('.install-theme-info').html() );
52 src = info.find( '.theme-preview-url' ).val();
53 panel.html( '<iframe src="' + src + '" />');
54 preview.fadeIn( 200, function() {
55 body.addClass('theme-installer-active full-overlay-active');
57 event.preventDefault();
64 ThemeViewer = function( args ) {
67 $( '#filter-click, #mini-filter-click' ).unbind( 'click' ).click( function() {
68 $( '#filter-click' ).toggleClass( 'current' );
69 $( '#filter-box' ).slideToggle();
70 $( '#current-theme' ).slideToggle( 300 );
74 $( '#filter-box :checkbox' ).unbind( 'click' ).click( function() {
75 var count = $( '#filter-box :checked' ).length,
76 text = $( '#filter-click' ).text();
78 if ( text.indexOf( '(' ) != -1 )
79 text = text.substr( 0, text.indexOf( '(' ) );
82 $( '#filter-click' ).text( text );
84 $( '#filter-click' ).text( text + ' (' + count + ')' );
87 /* $('#filter-box :submit').unbind( 'click' ).click(function() {
89 $('#filter-box :checked').each(function() {
90 features.push($(this).val());
93 listTable.update_rows({'features': features}, true, function() {
94 $( '#filter-click' ).toggleClass( 'current' );
95 $( '#filter-box' ).slideToggle();
96 $( '#current-theme' ).slideToggle( 300 );
103 // These are the functions we expose
112 jQuery( document ).ready( function($) {
113 theme_viewer = new ThemeViewer();
119 * Class that provides infinite scroll for Themes admin screens
125 * @uses theme_list_args
126 * @uses $('#_ajax_fetch_list_nonce').val()
132 scrollPollingDelay: 500,
133 failedRetryDelay: 4000,
134 outListBottomThreshold: 300,
145 // Get out early if we don't have the required arguments.
146 if ( typeof ajaxurl === 'undefined' ||
147 typeof list_args === 'undefined' ||
148 typeof theme_list_args === 'undefined' ) {
149 $('.pagination-links').show();
154 this.nonce = $('#_ajax_fetch_list_nonce').val();
155 this.nextPage = ( theme_list_args.paged + 1 );
157 // Cache jQuery selectors
158 this.$outList = $('#availablethemes');
159 this.$spinner = $('div.tablenav.bottom').children( '.spinner' );
160 this.$window = $(window);
161 this.$document = $(document);
164 * If there are more pages to query, then start polling to track
165 * when user hits the bottom of the current page
167 if ( theme_list_args.total_pages >= this.nextPage )
169 setInterval( function() {
171 }, this.scrollPollingDelay );
175 * Checks to see if user has scrolled to bottom of page.
176 * If so, requests another page of content from self.ajax().
182 var bottom = this.$document.scrollTop() + this.$window.innerHeight();
184 if ( this.querying ||
185 ( bottom < this.$outList.height() - this.outListBottomThreshold ) )
192 * Applies results passed from this.ajax() to $outList
197 * @param results Array with results from this.ajax() query.
199 process: function( results ) {
200 if ( results === undefined ) {
201 clearInterval( this.pollInterval );
205 if ( this.nextPage > theme_list_args.total_pages )
206 clearInterval( this.pollInterval );
208 if ( this.nextPage <= ( theme_list_args.total_pages + 1 ) )
209 this.$outList.append( results.rows );
213 * Queries next page of themes
221 this.querying = true;
224 action: 'fetch-list',
225 paged: this.nextPage,
226 s: theme_list_args.search,
227 tab: theme_list_args.tab,
228 type: theme_list_args.type,
229 _ajax_fetch_list_nonce: this.nonce,
230 'features[]': theme_list_args.features,
231 'list_args': list_args
234 this.$spinner.show();
235 $.getJSON( ajaxurl, query )
236 .done( function( response ) {
238 self.process( response );
239 self.$spinner.hide();
240 self.querying = false;
243 self.$spinner.hide();
244 self.querying = false;
245 setTimeout( function() { self.ajax(); }, self.failedRetryDelay );
250 $(document).ready( function($) {
251 ThemeScroller.init();