<!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>[22137] trunk/wp-includes: Better thumbnail previews in the image editor.</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, #logmsg > ol { margin-left: 0; 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/22137">22137</a></dd>
<dt>Author</dt> <dd>koopersmith</dd>
<dt>Date</dt> <dd>2012-10-08 23:20:04 +0000 (Mon, 08 Oct 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>Better thumbnail previews in the image editor.

* Images are auto-cropped, then fit to the preview on hover (with a slight delay). This is an experiment; we'll see how it turns out.
* Various style changes.

see <a href="http://core.trac.wordpress.org/ticket/21390">#21390</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludescssmediaviewscss">trunk/wp-includes/css/media-views.css</a></li>
<li><a href="#trunkwpincludesjsmediamodelsjs">trunk/wp-includes/js/media-models.js</a></li>
<li><a href="#trunkwpincludesjsmediaviewsjs">trunk/wp-includes/js/media-views.js</a></li>
<li><a href="#trunkwpincludesmediaphp">trunk/wp-includes/media.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludescssmediaviewscss"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/css/media-views.css (22136 => 22137)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/css/media-views.css        2012-10-08 21:25:13 UTC (rev 22136)
+++ trunk/wp-includes/css/media-views.css        2012-10-08 23:20:04 UTC (rev 22137)
</span><span class="lines">@@ -230,12 +230,15 @@
</span><span class="cx"> .attachment {
</span><span class="cx">         position: relative;
</span><span class="cx">         float: left;
</span><del>-        width: 200px;
-        height: 200px;
</del><ins>+        width: 199px;
+        height: 199px;
</ins><span class="cx"> 
</span><span class="cx">         padding: 0;
</span><span class="cx">         margin: 0 10px 20px;
</span><del>-        border: 1px solid #dfdfdf;
</del><ins>+        box-shadow:
+                inset 0 0 15px rgba( 0, 0, 0, 0.1 ),
+                inset 0 0 0 1px rgba( 0, 0, 0, 0.05 );
+        background: #eee;
</ins><span class="cx"> 
</span><span class="cx">         -webkit-user-select: none;
</span><span class="cx">         -moz-user-select:    none;
</span><span class="lines">@@ -244,14 +247,6 @@
</span><span class="cx">         user-select:         none;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-.attachment:hover {
-        border-color: #d54e21;
-}
-
-.attachment.library.selected {
-        border-color: #21759b;
-}
-
</del><span class="cx"> .attachment.library.selected:after {
</span><span class="cx">         content: '\2713';
</span><span class="cx">         display: block;
</span><span class="lines">@@ -276,13 +271,17 @@
</span><span class="cx">         overflow: hidden;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-.attachment img {
</del><ins>+.attachment .icon,
+.attachment .thumbnail {
</ins><span class="cx">         display: block;
</span><del>-        max-height: 200px;
-        max-width: 200px;
</del><ins>+        position: absolute;
+        top: 0;
+        left: 0;
+        margin: 0 auto;
+}
</ins><span class="cx"> 
</span><del>-        /* Vertically center the thumbnails. */
-        position: absolute;
</del><ins>+/* Vertically center the icons. */
+.attachment .icon {
</ins><span class="cx">         top: 50%;
</span><span class="cx">         left: 50%;
</span><span class="cx">         -webkit-transform: translate( -50%, -50% );
</span><span class="lines">@@ -290,11 +289,52 @@
</span><span class="cx">         -ms-transform:     translate( -50%, -50% );
</span><span class="cx">         -o-transform:      translate( -50%, -50% );
</span><span class="cx">         transform:         translate( -50%, -50% );
</span><ins>+}
</ins><span class="cx"> 
</span><del>-        margin: 0 auto;
-        box-shadow: inset 0 0 0 1px rgba( 0, 0, 0, 0.4 );
</del><ins>+.attachment .thumbnail,
+.attachment .thumbnail img {
+        -webkit-transition-property: width, height, top, left, right, bottom;
+        -moz-transition-property:    width, height, top, left, right, bottom;
+        -ms-transition-property:     width, height, top, left, right, bottom;
+        -o-transition-property:      width, height, top, left, right, bottom;
+        transition-property:         width, height, top, left, right, bottom;
+        -webkit-transition-duration: 80ms;
+        -moz-transition-duration:    80ms;
+        -ms-transition-duration:     80ms;
+        -o-transition-duration:      80ms;
+        transition-duration:         80ms;
+        -webkit-transition-delay:    125ms;
+        -moz-transition-delay:       125ms;
+        -ms-transition-delay:        125ms;
+        -o-transition-delay:         125ms;
+        transition-delay:            125ms;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+.attachment .thumbnail {
+        width: 199px;
+        height: 199px;
+}
+
+.attachment .thumbnail:after {
+        content: '';
+        display: block;
+        position: absolute;
+        top: 0;
+        left: 0;
+        right: 0;
+        bottom: 0;
+        box-shadow: inset 0 0 0 1px rgba( 0, 0, 0, 0.1 );
+        overflow: hidden;
+}
+
+.attachment.fit .thumbnail:after {
+        box-shadow: inset 0 0 0 1px rgba( 0, 0, 0, 0.15 );
+}
+
+.attachment .thumbnail img {
+        position: absolute;
+}
+
</ins><span class="cx"> .attachment .insert {
</span><span class="cx">         display: none;
</span><span class="cx">         position: absolute;
</span></span></pre></div>
<a id="trunkwpincludesjsmediamodelsjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/media-models.js (22136 => 22137)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/media-models.js        2012-10-08 21:25:13 UTC (rev 22136)
+++ trunk/wp-includes/js/media-models.js        2012-10-08 23:20:04 UTC (rev 22137)
</span><span class="lines">@@ -146,11 +146,11 @@
</span><span class="cx">                         if ( 'width' === constraint &amp;&amp; width &gt; maxWidth ) {
</span><span class="cx">                                 return {
</span><span class="cx">                                         width : maxWidth,
</span><del>-                                        height: maxWidth * height / width
</del><ins>+                                        height: Math.round( maxWidth * height / width )
</ins><span class="cx">                                 };
</span><span class="cx">                         } else if ( 'height' === constraint &amp;&amp; height &gt; maxHeight ) {
</span><span class="cx">                                 return {
</span><del>-                                        width : maxHeight * width / height,
</del><ins>+                                        width : Math.round( maxHeight * width / height ),
</ins><span class="cx">                                         height: maxHeight
</span><span class="cx">                                 };
</span><span class="cx">                         } else {
</span></span></pre></div>
<a id="trunkwpincludesjsmediaviewsjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/media-views.js (22136 => 22137)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/media-views.js        2012-10-08 21:25:13 UTC (rev 22136)
+++ trunk/wp-includes/js/media-views.js        2012-10-08 23:20:04 UTC (rev 22137)
</span><span class="lines">@@ -376,7 +376,9 @@
</span><span class="cx">                 template:  media.template('attachment'),
</span><span class="cx"> 
</span><span class="cx">                 events: {
</span><del>-                        'click': 'toggleSelection'
</del><ins>+                        'click': 'toggleSelection',
+                        'mouseenter': 'shrink',
+                        'mouseleave': 'expand'
</ins><span class="cx">                 },
</span><span class="cx"> 
</span><span class="cx">                 buttons: {},
</span><span class="lines">@@ -396,7 +398,7 @@
</span><span class="cx">                 render: function() {
</span><span class="cx">                         var attachment = this.model.toJSON(),
</span><span class="cx">                                 options = {
</span><del>-                                        thumbnail:   'image' === attachment.type ? attachment.url : attachment.icon,
</del><ins>+                                        icon:        attachment.icon,
</ins><span class="cx">                                         uploading:   attachment.uploading,
</span><span class="cx">                                         orientation: attachment.orientation || 'landscape',
</span><span class="cx">                                         type:        attachment.type,
</span><span class="lines">@@ -404,14 +406,10 @@
</span><span class="cx">                                         buttons:     this.buttons
</span><span class="cx">                                 };
</span><span class="cx"> 
</span><del>-                        // Use the medium image size if possible. If the medium size
-                        // doesn't exist, then the attachment is too small.
-                        // In that case, use the attachment itself.
-                        if ( attachment.sizes &amp;&amp; attachment.sizes.medium ) {
-                                options.orientation = attachment.sizes.medium.orientation;
-                                options.thumbnail   = attachment.sizes.medium.url;
-                        }
</del><span class="cx"> 
</span><ins>+                        if ( 'image' === attachment.type )
+                                _.extend( options, this.crop() );
+
</ins><span class="cx">                         this.$el.html( this.template( options ) );
</span><span class="cx"> 
</span><span class="cx">                         if ( attachment.uploading )
</span><span class="lines">@@ -456,6 +454,68 @@
</span><span class="cx"> 
</span><span class="cx">                 preventDefault: function( event ) {
</span><span class="cx">                         event.preventDefault();
</span><ins>+                },
+
+                imageSize: function( size ) {
+                        var sizes = this.model.get('sizes');
+
+                        size = size || 'medium';
+
+                        // Use the provided image size if possible.
+                        if ( sizes &amp;&amp; sizes[ size ] ) {
+                                return sizes[ size ];
+                        } else {
+                                return {
+                                        url:         this.model.get('url'),
+                                        width:       this.model.get('width'),
+                                        height:      this.model.get('height'),
+                                        orientation: this.model.get('orientation')
+                                };
+                        }
+                },
+
+                crop: function( sizeId ) {
+                        var edge = 199,
+                                size = this.imageSize( sizeId ),
+                                wide, tall;
+
+                        wide = wp.media.fit( _.extend( { maxWidth:  edge }, size ) );
+                        tall = wp.media.fit( _.extend( { maxHeight: edge }, size ) );
+
+                        _.extend( size, wide.width &gt; tall.width ? wide : tall );
+
+                        size.top  = ( edge - size.height ) / 2;
+                        size.left = ( edge - size.width ) / 2;
+                        return size;
+                },
+
+                fit: function( sizeId ) {
+                        var margin = 10,
+                                full = 199,
+                                edge = full - ( margin * 2 ),
+                                size = _.extend( wp.media.fit( _.extend({
+                                        maxWidth:  edge,
+                                        maxHeight: edge
+                                }, this.imageSize( sizeId ) ) ) );
+
+                        size.top  = Math.round( margin + ( edge - size.height ) / 2 );
+                        size.left = Math.round( margin + ( edge - size.width ) / 2 );
+                        return size;
+                },
+
+                shrink: function() {
+                        var size = _.pick( this.fit(), 'top', 'left', 'width', 'height' );
+                        this.$el.addClass('fit');
+                        this.$('.thumbnail').css( size );
+                        this.$('.thumbnail img').css( _.extend( size, { top: 0, left: 0 } ) );
+                },
+
+                expand: function() {
+                        var size = _.pick( this.crop(), 'top', 'left', 'width', 'height' );
+                        this.$el.removeClass('fit');
+                        this.$('.thumbnail img').css( size );
+                        this.$('.thumbnail').css({ top: 0, left: 0, width: 199, height: 199 });
+
</ins><span class="cx">                 }
</span><span class="cx">         });
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/media.php (22136 => 22137)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/media.php        2012-10-08 21:25:13 UTC (rev 22136)
+++ trunk/wp-includes/media.php        2012-10-08 23:20:04 UTC (rev 22137)
</span><span class="lines">@@ -1330,8 +1330,13 @@
</span><span class="cx"> 
</span><span class="cx">         &lt;script type=&quot;text/html&quot; id=&quot;tmpl-attachment&quot;&gt;
</span><span class="cx">                 &lt;div class=&quot;attachment-preview type-&lt;%- type %&gt; subtype-&lt;%- subtype %&gt; &lt;%- orientation %&gt;&quot;&gt;
</span><del>-                        &lt;% if ( thumbnail ) { %&gt;
-                                &lt;img src=&quot;&lt;%- thumbnail %&gt;&quot; draggable=&quot;false&quot; /&gt;
</del><ins>+                        &lt;% if ( 'image' === type ) { %&gt;
+                                &lt;div class=&quot;thumbnail&quot;&gt;
+                                        &lt;img src=&quot;&lt;%- url %&gt;&quot; width=&quot;&lt;%- width %&gt;&quot; height=&quot;&lt;%- height %&gt;&quot; draggable=&quot;false&quot;
+                                        style=&quot;top:&lt;%- top %&gt;px; left:&lt;%- left %&gt;px;&quot; /&gt;
+                                &lt;/div&gt;
+                        &lt;% } else { %&gt;
+                                &lt;img src=&quot;&lt;%- icon %&gt;&quot; class=&quot;icon&quot; draggable=&quot;false&quot; /&gt;
</ins><span class="cx">                         &lt;% } %&gt;
</span><span class="cx"> 
</span><span class="cx">                         &lt;% if ( uploading ) { %&gt;
</span><span class="lines">@@ -1343,7 +1348,7 @@
</span><span class="cx">                         &lt;% } %&gt;
</span><span class="cx"> 
</span><span class="cx">                         &lt;% if ( buttons.insert ) { %&gt;
</span><del>-                                &lt;a class=&quot;insert button button-primary button-small&quot; href=&quot;#&quot;&gt;&lt;?php _e( 'Insert' ); ?&gt;&lt;/a&gt;
</del><ins>+                                &lt;a class=&quot;insert button button-small&quot; href=&quot;#&quot;&gt;&lt;?php _e( 'Insert' ); ?&gt;&lt;/a&gt;
</ins><span class="cx">                         &lt;% } %&gt;
</span><span class="cx">                 &lt;/div&gt;
</span><span class="cx">                 &lt;div class=&quot;describe&quot;&gt;&lt;/div&gt;
</span></span></pre>
</div>
</div>

</body>
</html>