<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[28123] trunk/src/wp-admin: Theme installer: Improve route handling and make ?theme= work.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/28123">28123</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2014-04-14 22:05:20 +0000 (Mon, 14 Apr 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Theme installer: Improve route handling and make ?theme= work.

props matveb.
fixes <a href="http://core.trac.wordpress.org/ticket/27708">#27708</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadmincssthemescss">trunk/src/wp-admin/css/themes.css</a></li>
<li><a href="#trunksrcwpadminjsthemejs">trunk/src/wp-admin/js/theme.js</a></li>
<li><a href="#trunksrcwpadminthemeinstallphp">trunk/src/wp-admin/theme-install.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadmincssthemescss"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/css/themes.css (28122 => 28123)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/css/themes.css        2014-04-14 20:21:14 UTC (rev 28122)
+++ trunk/src/wp-admin/css/themes.css   2014-04-14 22:05:20 UTC (rev 28123)
</span><span class="lines">@@ -1713,6 +1713,9 @@
</span><span class="cx"> .wp-full-overlay .theme-navigation .next-theme {
</span><span class="cx">  float: right;
</span><span class="cx"> }
</span><ins>+.wp-full-overlay.no-navigation .theme-navigation {
+       display: none;
+}
</ins><span class="cx"> 
</span><span class="cx"> /* Animations */
</span><span class="cx"> .wp-full-overlay,
</span></span></pre></div>
<a id="trunksrcwpadminjsthemejs"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/js/theme.js (28122 => 28123)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/js/theme.js   2014-04-14 20:21:14 UTC (rev 28122)
+++ trunk/src/wp-admin/js/theme.js      2014-04-14 22:05:20 UTC (rev 28123)
</span><span class="lines">@@ -22,7 +22,7 @@
</span><span class="cx">  // Adds attributes to the default data coming through the .org themes api
</span><span class="cx">  // Map `id` to `slug` for shared code
</span><span class="cx">  initialize: function() {
</span><del>-               var install;
</del><ins>+                var install, description;
</ins><span class="cx"> 
</span><span class="cx">          // Install url for the theme
</span><span class="cx">          // using the install nonce
</span><span class="lines">@@ -46,6 +46,13 @@
</span><span class="cx">                  // slug is for installation, id is for existing.
</span><span class="cx">                  id: this.get( 'slug' ) || this.get( 'id' )
</span><span class="cx">          });
</span><ins>+
+               // Map `section.description` to `description`
+               // as the API sometimes returns it differently
+               if ( this.has( 'sections' ) ) {
+                       description = this.get( 'sections' ).description;
+                       this.set({ description: description });
+               }
</ins><span class="cx">   }
</span><span class="cx"> });
</span><span class="cx"> 
</span><span class="lines">@@ -218,7 +225,7 @@
</span><span class="cx">  //
</span><span class="cx">  // When we are missing a cache object we fire an apiCall()
</span><span class="cx">  // which triggers events of `query:success` or `query:fail`
</span><del>-       query: function( request ) {
</del><ins>+        query: function( request, action ) {
</ins><span class="cx">           /**
</span><span class="cx">           * @static
</span><span class="cx">           * @type Array
</span><span class="lines">@@ -247,29 +254,37 @@
</span><span class="cx"> 
</span><span class="cx">          // Otherwise, send a new API call and add it to the cache.
</span><span class="cx">          if ( ! query && ! isPaginated ) {
</span><del>-                       query = this.apiCall( request ).done( function( data ) {
</del><ins>+                        query = this.apiCall( request, action ).done( function( data ) {
+
</ins><span class="cx">                           // Update the collection with the queried data.
</span><del>-                               self.reset( data.themes );
-                               count = data.info.results;
</del><ins>+                                if ( data.themes ) {
+                                       self.reset( data.themes );
+                                       count = data.info.results;
+                                       // Store the results and the query request
+                                       queries.push( { themes: data.themes, request: request, total: count } );
</ins><span class="cx"> 
</span><ins>+                               } else if ( action ) {
+                                       self.reset( data );
+                                       count = 1;
+                                       self.trigger( 'query:theme' );
+                               }
+
</ins><span class="cx">                           // Trigger a collection refresh event
</span><span class="cx">                          // and a `query:success` event with a `count` argument.
</span><span class="cx">                          self.trigger( 'update' );
</span><span class="cx">                          self.trigger( 'query:success', count );
</span><span class="cx"> 
</span><del>-                               if ( data.themes.length === 0 ) {
</del><ins>+                                if ( data.themes && data.themes.length === 0 ) {
</ins><span class="cx">                                   self.trigger( 'query:empty' );
</span><span class="cx">                          }
</span><span class="cx"> 
</span><del>-                               // Store the results and the query request
-                               queries.push( { themes: data.themes, request: request, total: count } );
</del><span class="cx">                   }).fail( function() {
</span><span class="cx">                          self.trigger( 'query:fail' );
</span><span class="cx">                  });
</span><span class="cx">          } else {
</span><span class="cx">                  // If it's a paginated request we need to fetch more themes...
</span><span class="cx">                  if ( isPaginated ) {
</span><del>-                               return this.apiCall( request, isPaginated ).done( function( data ) {
</del><ins>+                                return this.apiCall( request, action, isPaginated ).done( function( data ) {
</ins><span class="cx">                                   // Add the new themes to the current collection
</span><span class="cx">                                  // @todo update counter
</span><span class="cx">                                  self.add( data.themes );
</span><span class="lines">@@ -314,13 +329,18 @@
</span><span class="cx">  },
</span><span class="cx"> 
</span><span class="cx">  // Send request to api.wordpress.org/themes
</span><del>-       apiCall: function( request, paginated ) {
</del><ins>+        apiCall: function( request, action, paginated ) {
</ins><span class="cx"> 
</span><span class="cx">          // Send tags (and fields) as comma-separated to keep the JSONP query string short.
</span><span class="cx">          if ( request.tag && _.isArray( request.tag ) ) {
</span><span class="cx">                  request.tag = request.tag.join( ',' );
</span><span class="cx">          }
</span><span class="cx"> 
</span><ins>+               // Set request action
+               if ( ! action ) {
+                       action = 'query_themes'
+               }
+
</ins><span class="cx">           // JSONP request to .org API
</span><span class="cx">          return $.ajax({
</span><span class="cx">                  url: 'https://api.wordpress.org/themes/info/1.1/?callback=?',
</span><span class="lines">@@ -329,7 +349,7 @@
</span><span class="cx"> 
</span><span class="cx">                  // Request data
</span><span class="cx">                  data: {
</span><del>-                               action: 'query_themes',
</del><ins>+                                action: action,
</ins><span class="cx">                           request: _.extend({
</span><span class="cx">                                  per_page: 72,
</span><span class="cx">                                  fields: 'description,tested,requires,rating,downloaded,downloadLink,last_updated,homepage,num_ratings'
</span><span class="lines">@@ -482,6 +502,15 @@
</span><span class="cx">          // Render the view and append it.
</span><span class="cx">          preview.render();
</span><span class="cx">          this.setNavButtonsState();
</span><ins>+
+               // Hide previous/next navigation if there is only one theme
+               if ( this.model.collection.length === 1 ) {
+                       preview.$el.addClass( 'no-navigation' );
+               } else {
+                       preview.$el.removeClass( 'no-navigation' );
+               }
+
+               // Apend preview
</ins><span class="cx">           $( 'div.wrap' ).append( preview.el );
</span><span class="cx"> 
</span><span class="cx">          // Listen to our preview object
</span><span class="lines">@@ -780,6 +809,7 @@
</span><span class="cx"> 
</span><span class="cx">          themes.router.navigate( themes.router.baseUrl( '' ) );
</span><span class="cx">          this.trigger( 'preview:close' );
</span><ins>+               this.unbind();
</ins><span class="cx">           return false;
</span><span class="cx">  },
</span><span class="cx"> 
</span><span class="lines">@@ -1305,10 +1335,13 @@
</span><span class="cx">          'click .filtering-by a': 'backToFilters'
</span><span class="cx">  },
</span><span class="cx"> 
</span><del>-       // Handles all the rendering of the public theme directory
-       browse: function( section ) {
</del><ins>+        // Initial render method
+       render: function() {
</ins><span class="cx">           var self = this;
</span><span class="cx"> 
</span><ins>+               this.search();
+               this.uploader();
+
</ins><span class="cx">           this.collection = new themes.Collection();
</span><span class="cx"> 
</span><span class="cx">          // Bump `collection.currentQuery.page` and request more themes if we hit the end of the page.
</span><span class="lines">@@ -1339,10 +1372,6 @@
</span><span class="cx">                  $( '.theme-browser' ).find( 'div.themes' ).before( '<div class="error"><p>' + l10n.error + '</p></div>' );
</span><span class="cx">          });
</span><span class="cx"> 
</span><del>-               // Create a new collection with the proper theme data
-               // for each section
-               this.collection.query( { browse: section } );
-
</del><span class="cx">           if ( this.view ) {
</span><span class="cx">                  this.view.remove();
</span><span class="cx">          }
</span><span class="lines">@@ -1350,7 +1379,6 @@
</span><span class="cx">          // Set ups the view and passes the section argument
</span><span class="cx">          this.view = new themes.view.Themes({
</span><span class="cx">                  collection: this.collection,
</span><del>-                       section: section,
</del><span class="cx">                   parent: this
</span><span class="cx">          });
</span><span class="cx"> 
</span><span class="lines">@@ -1363,11 +1391,11 @@
</span><span class="cx">          this.$el.find( '.theme-browser' ).append( this.view.el ).addClass( 'rendered' );
</span><span class="cx">  },
</span><span class="cx"> 
</span><del>-       // Initial render method
-       render: function() {
-               this.search();
-               this.uploader();
-               return this.browse( this.options.section );
</del><ins>+        // Handles all the rendering of the public theme directory
+       browse: function( section ) {
+               // Create a new collection with the proper theme data
+               // for each section
+               this.collection.query( { browse: section } );
</ins><span class="cx">   },
</span><span class="cx"> 
</span><span class="cx">  // Sorting navigation
</span><span class="lines">@@ -1554,7 +1582,7 @@
</span><span class="cx">          'theme-install.php?browse=:sort': 'sort',
</span><span class="cx">          'theme-install.php?upload': 'upload',
</span><span class="cx">          'theme-install.php?search=:query': 'search',
</span><del>-               '': 'sort'
</del><ins>+                'theme-install.php': 'sort'
</ins><span class="cx">   },
</span><span class="cx"> 
</span><span class="cx">  baseUrl: function( url ) {
</span><span class="lines">@@ -1596,16 +1624,23 @@
</span><span class="cx">  },
</span><span class="cx"> 
</span><span class="cx">  routes: function() {
</span><del>-               var self = this;
-               // Bind to our global thx object
-               // so that the object is available to sub-views
</del><ins>+                var self = this,
+                       request = {};
+
+               // Bind to our global `wp.themes` object
+               // so that the router is available to sub-views
</ins><span class="cx">           themes.router = new themes.InstallerRouter();
</span><span class="cx"> 
</span><del>-               // Handles theme details route event
-               themes.router.on( 'route:theme', function( slug ) {
-                       self.view.view.expand( slug );
</del><ins>+                // Handles `theme` route event
+               // Queries the API for the passed theme slug
+               themes.router.on( 'route:preview', function( slug ) {
+                       request.slug = slug;
+                       self.view.collection.query( request, 'theme_information' );
</ins><span class="cx">           });
</span><span class="cx"> 
</span><ins>+               // Handles sorting / browsing routes
+               // Also handles the root URL triggering a sort request
+               // for `featured`, the default view
</ins><span class="cx">           themes.router.on( 'route:sort', function( sort ) {
</span><span class="cx">                  if ( ! sort ) {
</span><span class="cx">                          sort = 'featured';
</span><span class="lines">@@ -1614,11 +1649,12 @@
</span><span class="cx">                  self.view.trigger( 'theme:close' );
</span><span class="cx">          });
</span><span class="cx"> 
</span><ins>+               // Support the `upload` route by going straight to upload section
</ins><span class="cx">           themes.router.on( 'route:upload', function() {
</span><span class="cx">                  $( 'a.upload' ).trigger( 'click' );
</span><span class="cx">          });
</span><span class="cx"> 
</span><del>-               // Handles search route event
</del><ins>+                // The `search` route event. The router populates the input field.
</ins><span class="cx">           themes.router.on( 'route:search', function() {
</span><span class="cx">                  $( '.theme-search' ).focus().trigger( 'keyup' );
</span><span class="cx">          });
</span></span></pre></div>
<a id="trunksrcwpadminthemeinstallphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/theme-install.php (28122 => 28123)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/theme-install.php     2014-04-14 20:21:14 UTC (rev 28122)
+++ trunk/src/wp-admin/theme-install.php        2014-04-14 22:05:20 UTC (rev 28123)
</span><span class="lines">@@ -122,7 +122,7 @@
</span><span class="cx"> 
</span><span class="cx">  <div class="theme-navigation">
</span><span class="cx">          <span class="theme-count"></span>
</span><del>-               <a class="theme-section current" href="#" data-sort="featured"><?php _ex( 'Featured', 'themes' ); ?></a>
</del><ins>+                <a class="theme-section" href="#" data-sort="featured"><?php _ex( 'Featured', 'themes' ); ?></a>
</ins><span class="cx">           <a class="theme-section" href="#" data-sort="popular"><?php _ex( 'Popular', 'themes' ); ?></a>
</span><span class="cx">          <a class="theme-section" href="#" data-sort="new"><?php _ex( 'Latest', 'themes' ); ?></a>
</span><span class="cx">          <div class="theme-top-filters">
</span></span></pre>
</div>
</div>

</body>
</html>