1 /* global ajaxurl, list_args, theme_list_args */
8 * Controls visibility of theme details on manage and install themes pages.
11 $('#availablethemes').on( 'click', '.theme-detail', function (event) {
12 var theme = $(this).closest('.available-theme'),
13 details = theme.find('.themedetaildiv');
15 if ( ! details.length ) {
16 details = theme.find('.install-theme-info .theme-details');
17 details = details.clone().addClass('themedetaildiv').appendTo( theme ).hide();
21 event.preventDefault();
28 * Displays theme previews on theme install pages.
31 if ( ! window.postMessage ) {
35 var preview = $('#theme-installer'),
36 header = preview.find('.wp-full-overlay-header'),
37 info = preview.find('.install-theme-info'),
38 panel = preview.find('.wp-full-overlay-main'),
39 body = $( document.body );
41 preview.on( 'click', '.close-full-overlay', function( event ) {
42 preview.fadeOut( 200, function() {
44 body.removeClass('theme-installer-active full-overlay-active');
46 event.preventDefault();
49 preview.on( 'click', '.collapse-sidebar', function( event ) {
50 preview.toggleClass( 'collapsed' ).toggleClass( 'expanded' );
51 event.preventDefault();
54 $('#availablethemes').on( 'click', '.install-theme-preview', function( event ) {
57 info.html( $(this).closest('.installable-theme').find('.install-theme-info').html() );
59 header.find( '.theme-install' ).replaceWith( info.find( '.theme-install' ) );
61 src = info.find( '.theme-preview-url' ).val();
62 panel.html( '<iframe src="' + src + '" />');
63 preview.fadeIn( 200, function() {
64 body.addClass('theme-installer-active full-overlay-active');
66 event.preventDefault();
73 ThemeViewer = function() {
76 $( '#filter-click, #mini-filter-click' ).unbind( 'click' ).click( function() {
77 $( '#filter-click' ).toggleClass( 'current' );
78 $( '#filter-box' ).slideToggle();
79 $( '#current-theme' ).slideToggle( 300 );
83 $( '#filter-box :checkbox' ).unbind( 'click' ).click( function() {
84 var count = $( '#filter-box :checked' ).length,
85 text = $( '#filter-click' ).text();
87 if ( text.indexOf( '(' ) !== -1 ) {
88 text = text.substr( 0, text.indexOf( '(' ) );
92 $( '#filter-click' ).text( text );
94 $( '#filter-click' ).text( text + ' (' + count + ')' );
98 /* $('#filter-box :submit').unbind( 'click' ).click(function() {
100 $('#filter-box :checked').each(function() {
101 features.push($(this).val());
104 listTable.update_rows({'features': features}, true, function() {
105 $( '#filter-click' ).toggleClass( 'current' );
106 $( '#filter-box' ).slideToggle();
107 $( '#current-theme' ).slideToggle( 300 );
114 // These are the functions we expose
123 jQuery( document ).ready( function() {
124 theme_viewer = new ThemeViewer();
130 * Class that provides infinite scroll for Themes admin screens
136 * @uses theme_list_args
137 * @uses $('#_ajax_fetch_list_nonce').val()
143 scrollPollingDelay: 500,
144 failedRetryDelay: 4000,
145 outListBottomThreshold: 300,
156 // Get out early if we don't have the required arguments.
157 if ( typeof ajaxurl === 'undefined' ||
158 typeof list_args === 'undefined' ||
159 typeof theme_list_args === 'undefined' ) {
161 $('.pagination-links').show();
166 this.nonce = $('#_ajax_fetch_list_nonce').val();
167 this.nextPage = ( theme_list_args.paged + 1 );
169 // Cache jQuery selectors
170 this.$outList = $('#availablethemes');
171 this.$spinner = $('div.tablenav.bottom').children( '.spinner' );
172 this.$window = $(window);
173 this.$document = $(document);
176 * If there are more pages to query, then start polling to track
177 * when user hits the bottom of the current page
179 if ( theme_list_args.total_pages >= this.nextPage ) {
180 this.pollInterval = setInterval( function() {
182 }, this.scrollPollingDelay );
187 * Checks to see if user has scrolled to bottom of page.
188 * If so, requests another page of content from self.ajax().
194 var bottom = this.$document.scrollTop() + this.$window.innerHeight();
196 if ( this.querying ||
197 ( bottom < this.$outList.height() - this.outListBottomThreshold ) ) {
205 * Applies results passed from this.ajax() to $outList
210 * @param results Array with results from this.ajax() query.
212 process: function( results ) {
213 if ( results === undefined ) {
214 clearInterval( this.pollInterval );
218 if ( this.nextPage > theme_list_args.total_pages ) {
219 clearInterval( this.pollInterval );
222 if ( this.nextPage <= ( theme_list_args.total_pages + 1 ) ) {
223 this.$outList.append( results.rows );
228 * Queries next page of themes
236 action: 'fetch-list',
237 paged: this.nextPage,
238 s: theme_list_args.search,
239 tab: theme_list_args.tab,
240 type: theme_list_args.type,
241 _ajax_fetch_list_nonce: this.nonce,
242 'features[]': theme_list_args.features,
243 'list_args': list_args
246 this.querying = true;
248 this.$spinner.show();
249 $.getJSON( ajaxurl, query )
250 .done( function( response ) {
252 self.process( response );
253 self.$spinner.hide();
254 self.querying = false;
257 self.$spinner.hide();
258 self.querying = false;
259 setTimeout( function() { self.ajax(); }, self.failedRetryDelay );
264 $(document).ready( function() {
265 ThemeScroller.init();