<!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>[28025] trunk/src/wp-admin: Theme Installer: Handle currently installed themes, add search route, let prev/next refresh collections.</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/28025">28025</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2014-04-07 23:03:05 +0000 (Mon, 07 Apr 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Theme Installer: Handle currently installed themes, add search route, let prev/next refresh collections.

props matveb.
see <a href="http://core.trac.wordpress.org/ticket/27055">#27055</a>. fixes <a href="http://core.trac.wordpress.org/ticket/27695">#27695</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 (28024 => 28025)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/css/themes.css        2014-04-07 22:54:13 UTC (rev 28024)
+++ trunk/src/wp-admin/css/themes.css   2014-04-07 23:03:05 UTC (rev 28025)
</span><span class="lines">@@ -216,7 +216,8 @@
</span><span class="cx">  * Displays a theme update notice
</span><span class="cx">  * when an update is available.
</span><span class="cx">  */
</span><del>-.theme-browser .theme .theme-update {
</del><ins>+.theme-browser .theme .theme-update,
+.theme-browser .theme .theme-installed {
</ins><span class="cx">   background: #d54e21;
</span><span class="cx">  background: rgba(213, 78, 33, 0.95);
</span><span class="cx">  color: #fff;
</span><span class="lines">@@ -234,7 +235,8 @@
</span><span class="cx">  overflow: hidden;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-.theme-browser .theme .theme-update:before {
</del><ins>+.theme-browser .theme .theme-update:before,
+.theme-browser .theme .theme-installed:before {
</ins><span class="cx">   content: '\f463';
</span><span class="cx">  display: inline-block;
</span><span class="cx">  font: normal 20px/1 'dashicons';
</span><span class="lines">@@ -1074,6 +1076,25 @@
</span><span class="cx">   16.2 - Install Themes
</span><span class="cx"> ------------------------------------------------------------------------------*/
</span><span class="cx"> 
</span><ins>+/* Already installed theme */
+.theme-browser .theme.is-installed {
+       cursor: default;
+}
+.theme-browser .theme .theme-installed {
+       background: #0074a2;
+}
+.theme-browser .theme .theme-installed:before {
+       content: '\f147';
+}
+.theme-browser .theme.is-installed .theme-actions,
+.theme-browser.rendered .theme.is-installed .more-details {
+       display: none !important;
+}
+.theme-browser.rendered .theme.is-installed:hover .theme-screenshot img,
+.theme-browser.rendered .theme.is-installed:focus .theme-screenshot img {
+       opacity: 1 !important;
+}
+
</ins><span class="cx"> .theme-navigation {
</span><span class="cx">  background: #fff;
</span><span class="cx">  -webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
</span></span></pre></div>
<a id="trunksrcwpadminjsthemejs"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/js/theme.js (28024 => 28025)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/js/theme.js   2014-04-07 22:54:13 UTC (rev 28024)
+++ trunk/src/wp-admin/js/theme.js      2014-04-07 23:03:05 UTC (rev 28025)
</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, preview;
</del><ins>+                var install, installed;
</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">@@ -35,18 +35,14 @@
</span><span class="cx">          // Build the url query
</span><span class="cx">          install = themes.data.settings.updateURI + '?' + $.param( install );
</span><span class="cx"> 
</span><del>-               // Preview url for the theme
-               preview = {
-                       tab: 'theme-information',
-                       theme: this.get( 'slug' )
-               };
</del><ins>+                // If theme is already installed, set an attribute.
+               if ( _.indexOf( themes.data.installedThemes, this.get( 'slug' ) ) !== -1 ) {
+                       this.set({ installed: true });
+               }
</ins><span class="cx"> 
</span><del>-               preview = themes.data.settings.installURI + '?' + $.param( preview );
-
</del><span class="cx">           // Set the attributes
</span><span class="cx">          this.set({
</span><del>-                       installURI: install,
-                       previewURI: preview,
</del><ins>+                        installURI: ( this.get( 'slug' ) ) ? install : false,
</ins><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><span class="lines">@@ -391,6 +387,11 @@
</span><span class="cx">          if ( this.model.get( 'displayAuthor' ) ) {
</span><span class="cx">                  this.$el.addClass( 'display-author' );
</span><span class="cx">          }
</span><ins>+
+               if ( this.model.get( 'installed' ) ) {
+                       this.$el.addClass( 'is-installed' );
+                       this.$el.unbind();
+               }
</ins><span class="cx">   },
</span><span class="cx"> 
</span><span class="cx">  // Adds a class to the currently active theme
</span><span class="lines">@@ -451,6 +452,11 @@
</span><span class="cx">                  return this.touchDrag = false;
</span><span class="cx">          }
</span><span class="cx"> 
</span><ins>+               // Allow direct link path to installing a theme.
+               if ( $( event.target ).hasClass( 'button-primary' ) ) {
+                       return;
+               }
+
</ins><span class="cx">           // 'enter' and 'space' keys expand the details view when a theme is :focused
</span><span class="cx">          if ( event.type === 'keydown' && ( event.which !== 13 && event.which !== 32 ) ) {
</span><span class="cx">                  return;
</span><span class="lines">@@ -494,6 +500,7 @@
</span><span class="cx"> 
</span><span class="cx">                  // If we have no more themes, bail.
</span><span class="cx">                  if ( _.isUndefined( self.current ) ) {
</span><ins>+                               self.options.parent.parent.trigger( 'theme:end' );
</ins><span class="cx">                           return self.current = current;
</span><span class="cx">                  }
</span><span class="cx"> 
</span><span class="lines">@@ -505,6 +512,7 @@
</span><span class="cx">                  // Render and append.
</span><span class="cx">                  preview.render();
</span><span class="cx">                  $( 'div.wrap' ).append( preview.el );
</span><ins>+                       $( '.next-theme' ).focus();
</ins><span class="cx">           })
</span><span class="cx">          .listenTo( preview, 'theme:previous', function() {
</span><span class="cx"> 
</span><span class="lines">@@ -532,6 +540,7 @@
</span><span class="cx">                  // Render and append.
</span><span class="cx">                  preview.render();
</span><span class="cx">                  $( 'div.wrap' ).append( preview.el );
</span><ins>+                       $( '.previous-theme' ).focus();
</ins><span class="cx">           });
</span><span class="cx">  }
</span><span class="cx"> });
</span><span class="lines">@@ -882,7 +891,8 @@
</span><span class="cx">          // Loop through the themes and setup each theme view
</span><span class="cx">          self.instance.each( function( theme ) {
</span><span class="cx">                  self.theme = new themes.view.Theme({
</span><del>-                               model: theme
</del><ins>+                                model: theme,
+                               parent: self
</ins><span class="cx">                   });
</span><span class="cx"> 
</span><span class="cx">                  // Render the views...
</span><span class="lines">@@ -1158,8 +1168,7 @@
</span><span class="cx"> 
</span><span class="cx">          // Handles search route event
</span><span class="cx">          themes.router.on( 'route:search', function( query ) {
</span><del>-                       self.view.trigger( 'theme:close' );
-                       self.themes.doSearch( query );
</del><ins>+                        $( '.theme-search' ).trigger( 'keyup' );
</ins><span class="cx">           });
</span><span class="cx"> 
</span><span class="cx">          this.extraRoutes();
</span><span class="lines">@@ -1224,6 +1233,9 @@
</span><span class="cx">          // Get the themes by sending Ajax POST request to api.wordpress.org/themes
</span><span class="cx">          // or searching the local cache
</span><span class="cx">          this.collection.query( request );
</span><ins>+
+               // Set route
+               themes.router.navigate( themes.router.baseUrl( '?search=' + value ), { replace: true } );
</ins><span class="cx">   }, 300 )
</span><span class="cx"> });
</span><span class="cx"> 
</span><span class="lines">@@ -1329,7 +1341,7 @@
</span><span class="cx">  },
</span><span class="cx"> 
</span><span class="cx">  sort: function( sort ) {
</span><del>-               $( '#theme-search-input' ).val( '' );
</del><ins>+                this.clearSearch();
</ins><span class="cx"> 
</span><span class="cx">          $( '.theme-section, .theme-filter' ).removeClass( this.activeClass );
</span><span class="cx">          $( '[data-sort="' + sort + '"]' ).addClass( this.activeClass );
</span><span class="lines">@@ -1450,6 +1462,9 @@
</span><span class="cx">                  return this.addFilter();
</span><span class="cx">          }
</span><span class="cx"> 
</span><ins>+               this.clearSearch();
+
+               themes.router.navigate( themes.router.baseUrl( '' ) );
</ins><span class="cx">           $( 'body' ).toggleClass( 'more-filters-opened' );
</span><span class="cx">  },
</span><span class="cx"> 
</span><span class="lines">@@ -1474,6 +1489,10 @@
</span><span class="cx"> 
</span><span class="cx">  backToFilters: function() {
</span><span class="cx">          $( 'body' ).removeClass( 'filters-applied' );
</span><ins>+       },
+
+       clearSearch: function() {
+               $( '#theme-search-input').val( '' );
</ins><span class="cx">   }
</span><span class="cx"> });
</span><span class="cx"> 
</span><span class="lines">@@ -1482,12 +1501,17 @@
</span><span class="cx">          'theme-install.php?theme=:slug': 'preview',
</span><span class="cx">          'theme-install.php?sort=:sort': 'sort',
</span><span class="cx">          'theme-install.php?upload': 'upload',
</span><ins>+               'theme-install.php?search=:query': 'search',
</ins><span class="cx">           '': 'sort'
</span><span class="cx">  },
</span><span class="cx"> 
</span><span class="cx">  baseUrl: function( url ) {
</span><span class="cx">          return 'theme-install.php' + url;
</span><del>-       }
</del><ins>+        },
+
+       search: function( query ) {
+               $( '.theme-search' ).val( query );
+       },
</ins><span class="cx"> });
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -1542,6 +1566,11 @@
</span><span class="cx">                  $( 'a.upload' ).trigger( 'click' );
</span><span class="cx">          });
</span><span class="cx"> 
</span><ins>+               // Handles search route event
+               themes.router.on( 'route:search', function( query ) {
+                       $( '.theme-search' ).focus().trigger( 'keyup' );
+               });
+
</ins><span class="cx">           this.extraRoutes();
</span><span class="cx">  },
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunksrcwpadminthemeinstallphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/theme-install.php (28024 => 28025)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/theme-install.php     2014-04-07 22:54:13 UTC (rev 28024)
+++ trunk/src/wp-admin/theme-install.php        2014-04-07 23:03:05 UTC (rev 28025)
</span><span class="lines">@@ -33,6 +33,13 @@
</span><span class="cx">  'new'      => __( 'Newest Themes' ),
</span><span class="cx"> );
</span><span class="cx"> 
</span><ins>+$installed_themes = search_theme_directories();
+foreach ( $installed_themes as $k => $v ) {
+       if ( false !== strpos( $k, '/' ) ) {
+               unset( $installed_themes[ $k ] );
+       }
+}
+
</ins><span class="cx"> wp_localize_script( 'theme', '_wpThemeSettings', array(
</span><span class="cx">  'themes'   => false,
</span><span class="cx">  'settings' => array(
</span><span class="lines">@@ -51,6 +58,7 @@
</span><span class="cx">          'back'   => __( 'Back' ),
</span><span class="cx">          'error'  => ( 'There was a problem trying to load the themes. Please, try again.' ), // @todo improve
</span><span class="cx">  ),
</span><ins>+       'installedThemes' => array_keys( $installed_themes ),
</ins><span class="cx">   'browse' => array(
</span><span class="cx">          'sections' => $sections,
</span><span class="cx">  ),
</span><span class="lines">@@ -190,13 +198,21 @@
</span><span class="cx">          <a class="button button-primary" href="{{ data.installURI }}"><?php esc_html_e( 'Install' ); ?></a>
</span><span class="cx">          <a class="button button-secondary preview install-theme-preview" href="#"><?php esc_html_e( 'Preview' ); ?></a>
</span><span class="cx">  </div>
</span><ins>+
+       <# if ( data.installed ) { #>
+               <div class="theme-installed"><?php _e( 'Already Installed' ); ?></div>
+       <# } #>
</ins><span class="cx"> </script>
</span><span class="cx"> 
</span><span class="cx"> <script id="tmpl-theme-preview" type="text/template">
</span><span class="cx">  <div class="wp-full-overlay-sidebar">
</span><span class="cx">          <div class="wp-full-overlay-header">
</span><span class="cx">                  <a href="#" class="close-full-overlay button-secondary"><?php _e( 'Close' ); ?></a>
</span><ins>+               <# if ( data.installed ) { #>
+                       <a href="#" class="button button-primary theme-install disabled"><?php _e( 'Installed' ); ?></a>
+               <# } else { #>
</ins><span class="cx">                   <a href="{{ data.installURI }}" class="button button-primary theme-install"><?php _e( 'Install' ); ?></a>
</span><ins>+               <# } #>
</ins><span class="cx">           </div>
</span><span class="cx">          <div class="wp-full-overlay-sidebar-content">
</span><span class="cx">                  <div class="install-theme-info">
</span></span></pre>
</div>
</div>

</body>
</html>