[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-admin/js/ -> theme.dev.js (source)

   1  /**
   2   * Theme Browsing
   3   *
   4   * Controls visibility of theme details on manage and install themes pages.
   5   */
   6  jQuery( function($) {
   7      $('#availablethemes').on( 'click', '.theme-detail', function (event) {
   8          var theme   = $(this).closest('.available-theme'),
   9              details = theme.find('.themedetaildiv');
  10  
  11          if ( ! details.length ) {
  12              details = theme.find('.install-theme-info .theme-details');
  13              details = details.clone().addClass('themedetaildiv').appendTo( theme ).hide();
  14          }
  15  
  16          details.toggle();
  17          event.preventDefault();
  18      });
  19  });
  20  
  21  /**
  22   * Theme Customizer
  23   *
  24   * Ensures the themes page is refreshed if the customizer switches the theme.
  25   */
  26  jQuery( function($) {
  27      var Loader, activated;
  28  
  29      if ( typeof wp === 'undefined' || ! wp.customize || ! ( Loader = wp.customize.Loader ) )
  30          return;
  31  
  32      // Strip the current URL of its query string and hash, add activated query string.
  33      activated = window.location.href.replace(/[#?].*$/, '') + '?activated=true';
  34  
  35      // When an instance of the customizer is loaded...
  36      Loader.bind( 'open', function() {
  37  
  38          // If the customizer triggers a theme switched event,
  39          // load the activated page when the customizer is closed.
  40          Loader.messenger.bind( 'switched', function() {
  41  
  42              Loader.unbind( 'close', Loader.overlay.hide );
  43              Loader.bind( 'close', function() {
  44                  window.location = activated;
  45              });
  46          });
  47      });
  48  });
  49  
  50  /**
  51   * Theme Install
  52   *
  53   * Displays theme previews on theme install pages.
  54   */
  55  jQuery( function($) {
  56      if( ! window.postMessage )
  57          return;
  58  
  59      var preview = $('#theme-installer'),
  60          info    = preview.find('.install-theme-info'),
  61          panel   = preview.find('.wp-full-overlay-main'),
  62          body    = $( document.body );
  63  
  64      preview.on( 'click', '.close-full-overlay', function( event ) {
  65          preview.fadeOut( 200, function() {
  66              panel.empty();
  67              body.removeClass('theme-installer-active full-overlay-active');
  68          });
  69          event.preventDefault();
  70      });
  71  
  72      preview.on( 'click', '.collapse-sidebar', function( event ) {
  73          preview.toggleClass('collapsed');
  74          event.preventDefault();
  75      });
  76  
  77      $('#availablethemes').on( 'click', '.install-theme-preview', function( event ) {
  78          var src;
  79  
  80          info.html( $(this).closest('.installable-theme').find('.install-theme-info').html() );
  81          src = info.find( '.theme-preview-url' ).val();
  82          panel.html( '<iframe src="' + src + '" />');
  83          preview.fadeIn( 200, function() {
  84              body.addClass('theme-installer-active full-overlay-active');
  85          });
  86          event.preventDefault();
  87      });
  88  });
  89  
  90  var ThemeViewer;
  91  
  92  (function($){
  93      ThemeViewer = function( args ) {
  94  
  95  		function init() {
  96              $( '#filter-click, #mini-filter-click' ).unbind( 'click' ).click( function() {
  97                  $( '#filter-click' ).toggleClass( 'current' );
  98                  $( '#filter-box' ).slideToggle();
  99                  $( '#current-theme' ).slideToggle( 300 );
 100                  return false;
 101              });
 102  
 103              $( '#filter-box :checkbox' ).unbind( 'click' ).click( function() {
 104                  var count = $( '#filter-box :checked' ).length,
 105                      text  = $( '#filter-click' ).text();
 106  
 107                  if ( text.indexOf( '(' ) != -1 )
 108                      text = text.substr( 0, text.indexOf( '(' ) );
 109  
 110                  if ( count == 0 )
 111                      $( '#filter-click' ).text( text );
 112                  else
 113                      $( '#filter-click' ).text( text + ' (' + count + ')' );
 114              });
 115  
 116              /* $('#filter-box :submit').unbind( 'click' ).click(function() {
 117                  var features = [];
 118                  $('#filter-box :checked').each(function() {
 119                      features.push($(this).val());
 120                  });
 121  
 122                  listTable.update_rows({'features': features}, true, function() {
 123                      $( '#filter-click' ).toggleClass( 'current' );
 124                      $( '#filter-box' ).slideToggle();
 125                      $( '#current-theme' ).slideToggle( 300 );
 126                  });
 127  
 128                  return false;
 129              }); */
 130          }
 131  
 132          // These are the functions we expose
 133          var api = {
 134              init: init
 135          };
 136  
 137      return api;
 138      }
 139  })(jQuery);
 140  
 141  jQuery( document ).ready( function($) {
 142      theme_viewer = new ThemeViewer();
 143      theme_viewer.init();
 144  });
 145  
 146  
 147  /**
 148   * Class that provides infinite scroll for Themes admin screens
 149   *
 150   * @since 3.4
 151   *
 152   * @uses ajaxurl
 153   * @uses list_args
 154   * @uses theme_list_args
 155   * @uses $('#_ajax_fetch_list_nonce').val()
 156  * */
 157  var ThemeScroller;
 158  (function($){
 159      ThemeScroller = {
 160          querying: false,
 161          scrollPollingDelay: 500,
 162          failedRetryDelay: 4000,
 163          outListBottomThreshold: 300,
 164  
 165          /**
 166           * Initializer
 167           *
 168           * @since 3.4
 169           * @access private
 170           */
 171          init: function() {
 172              var self = this;
 173  
 174              // Get out early if we don't have the required arguments.
 175              if ( typeof ajaxurl === 'undefined' ||
 176                   typeof list_args === 'undefined' ||
 177                   typeof theme_list_args === 'undefined' ) {
 178                      $('.pagination-links').show();
 179                      return;
 180              }
 181  
 182              // Handle inputs
 183              this.nonce = $('#_ajax_fetch_list_nonce').val();
 184              this.nextPage = ( theme_list_args.paged + 1 );
 185  
 186              // Cache jQuery selectors
 187              this.$outList = $('#availablethemes');
 188              this.$spinner = $('div.tablenav.bottom').children( 'img.ajax-loading' );
 189              this.$window = $(window);
 190              this.$document = $(document);
 191  
 192              /**
 193               * If there are more pages to query, then start polling to track
 194               * when user hits the bottom of the current page
 195               */
 196              if ( theme_list_args.total_pages >= this.nextPage )
 197                  this.pollInterval =
 198                      setInterval( function() {
 199                          return self.poll();
 200                      }, this.scrollPollingDelay );
 201          },
 202  
 203          /**
 204           * Checks to see if user has scrolled to bottom of page.
 205           * If so, requests another page of content from self.ajax().
 206           *
 207           * @since 3.4
 208           * @access private
 209           */
 210          poll: function() {
 211              var bottom = this.$document.scrollTop() + this.$window.innerHeight();
 212  
 213              if ( this.querying ||
 214                  ( bottom < this.$outList.height() - this.outListBottomThreshold ) )
 215                  return;
 216  
 217              this.ajax();
 218          },
 219  
 220          /**
 221           * Applies results passed from this.ajax() to $outList
 222           *
 223           * @since 3.4
 224           * @access private
 225           *
 226           * @param results Array with results from this.ajax() query.
 227           */
 228          process: function( results ) {
 229              if ( results === undefined ) {
 230                  clearInterval( this.pollInterval );
 231                  return;
 232              }
 233  
 234              if ( this.nextPage > theme_list_args.total_pages )
 235                  clearInterval( this.pollInterval );
 236  
 237              if ( this.nextPage <= ( theme_list_args.total_pages + 1 ) )
 238                  this.$outList.append( results.rows );
 239          },
 240  
 241          /**
 242           * Queries next page of themes
 243           *
 244           * @since 3.4
 245           * @access private
 246           */
 247          ajax: function() {
 248              var self = this;
 249  
 250              this.querying = true;
 251  
 252              var query = {
 253                  action: 'fetch-list',
 254                  paged: this.nextPage,
 255                  s: theme_list_args.search,
 256                  tab: theme_list_args.tab,
 257                  type: theme_list_args.type,
 258                  _ajax_fetch_list_nonce: this.nonce,
 259                  'features[]': theme_list_args.features,
 260                  'list_args': list_args
 261              };
 262  
 263              this.$spinner.css( 'visibility', 'visible' );
 264              $.getJSON( ajaxurl, query )
 265                  .done( function( response ) {
 266                      self.nextPage++;
 267                      self.process( response );
 268                      self.$spinner.css( 'visibility', 'hidden' );
 269                      self.querying = false;
 270                  })
 271                  .fail( function() {
 272                      self.$spinner.css( 'visibility', 'hidden' );
 273                      self.querying = false;
 274                      setTimeout( function() { self.ajax(); }, self.failedRetryDelay );
 275                  });
 276          }
 277      }
 278  
 279      $(document).ready( function($) {
 280          ThemeScroller.init();
 281      });
 282  
 283  })(jQuery);


Generated: Fri May 25 03:56:23 2012 Hosted by follow the white rabbit.