<!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>[22324] trunk/wp-includes: Add dynamic attachment view sizing.</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/22324">22324</a></dd>
<dt>Author</dt> <dd>koopersmith</dd>
<dt>Date</dt> <dd>2012-10-29 18:05:03 +0000 (Mon, 29 Oct 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add dynamic attachment view sizing. Removes the attachment view zooming in the process. 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="#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 (22323 => 22324)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/css/media-views.css        2012-10-29 15:13:02 UTC (rev 22323)
+++ trunk/wp-includes/css/media-views.css        2012-10-29 18:05:03 UTC (rev 22324)
</span><span class="lines">@@ -174,6 +174,7 @@
</span><span class="cx">         bottom: 0;
</span><span class="cx">         height: auto;
</span><span class="cx">         width: auto;
</span><ins>+        margin: 0;
</ins><span class="cx">         overflow: auto;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -198,44 +199,6 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * Attachments
- */
-/*.attachments {
-        position: relative;
-        width: 100%;
-        height: 100%;
-}
-
-.attachments-header {
-        position: absolute;
-        top: 0;
-        left: 0;
-        right: 0;
-        height: 50px;
-        padding: 0 10px;
-        background: #fff;
-}
-
-.attachments-header h3 {
-        float: left;
-        margin: 0;
-        padding: 0;
-        line-height: 50px;
-        font-size: 18px;
-        font-weight: 200;
-}
-
-.attachments ul {
-        position: absolute;
-        top: 50px;
-        left: 0;
-        right: 0;
-        bottom: 0;
-        overflow: auto;
-        margin: 0 0 20px;
-}*/
-
-/**
</del><span class="cx">  * Attachment
</span><span class="cx">  */
</span><span class="cx"> .attachment {
</span><span class="lines">@@ -289,10 +252,39 @@
</span><span class="cx">         margin: 0 auto;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+.attachment .thumbnail {
+        -webkit-transform: translate( 50%, 50% );
+        -moz-transform:    translate( 50%, 50% );
+        -ms-transform:     translate( 50%, 50% );
+        -o-transform:      translate( 50%, 50% );
+        transform:         translate( 50%, 50% );
+}
+
</ins><span class="cx"> /* Vertically center the icons. */
</span><span class="cx"> .attachment .icon {
</span><span class="cx">         top: 50%;
</span><span class="cx">         left: 50%;
</span><ins>+}
+
+.attachment-preview: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 .thumbnail img {
+        top: 0;
+        left: 0;
+}
+
+.attachment .icon,
+.attachment .thumbnail img {
</ins><span class="cx">         -webkit-transform: translate( -50%, -50% );
</span><span class="cx">         -moz-transform:    translate( -50%, -50% );
</span><span class="cx">         -ms-transform:     translate( -50%, -50% );
</span><span class="lines">@@ -301,52 +293,22 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> .attachment .filename {
</span><del>-        margin-top: 140px;
-        padding: 0 10px;
</del><ins>+        position: absolute;
+        left: 0;
+        right: 0;
+        bottom: 0;
+        padding: 5px 10px;
</ins><span class="cx">         text-align: center;
</span><span class="cx">         font-weight: bold;
</span><ins>+        background: rgba( 255, 255, 255, 0.8 );
+        box-shadow: 0 0 2px rgba( 0, 0, 0, 0.2 );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-.attachment-preview .thumbnail,
-.attachment-preview .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:    200ms;
-        -moz-transition-delay:       200ms;
-        -ms-transition-delay:        200ms;
-        -o-transition-delay:         200ms;
-        transition-delay:            200ms;
-}
-
</del><span class="cx"> .attachment-preview .thumbnail {
</span><span class="cx">         width: 199px;
</span><span class="cx">         height: 199px;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-.attachment-preview .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 );
-}
-
</del><span class="cx"> .attachment .thumbnail img {
</span><span class="cx">         position: absolute;
</span><span class="cx"> }
</span><span class="lines">@@ -622,6 +584,7 @@
</span><span class="cx"> .attachment-details .describe {
</span><span class="cx">         float: left;
</span><span class="cx">         margin: 10px 0 0;
</span><ins>+        border-radius: 3px;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span></span></pre></div>
<a id="trunkwpincludesjsmediaviewsjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/media-views.js (22323 => 22324)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/media-views.js        2012-10-29 15:13:02 UTC (rev 22323)
+++ trunk/wp-includes/js/media-views.js        2012-10-29 18:05:03 UTC (rev 22324)
</span><span class="lines">@@ -127,6 +127,12 @@
</span><span class="cx">                         if ( ! this.get('library') )
</span><span class="cx">                                 this.set( 'library', media.query() );
</span><span class="cx"> 
</span><ins>+                        if ( ! this.get('edge') )
+                                this.set( 'edge', 120 );
+
+                        if ( ! this.get('gutter') )
+                                this.set( 'gutter', 6 );
+
</ins><span class="cx">                         this.on( 'activate', this.activate, this );
</span><span class="cx">                         this.on( 'deactivate', this.deactivate, this );
</span><span class="cx">                         this.on( 'change:details', this.details, this );
</span><span class="lines">@@ -248,7 +254,8 @@
</span><span class="cx">                         id:         'gallery',
</span><span class="cx">                         multiple:   false,
</span><span class="cx">                         describe:   true,
</span><del>-                        title:      l10n.createGallery
</del><ins>+                        title:      l10n.createGallery,
+                        edge:       199
</ins><span class="cx">                 },
</span><span class="cx"> 
</span><span class="cx">                 toolbar: function() {
</span><span class="lines">@@ -1016,8 +1023,8 @@
</span><span class="cx"> 
</span><span class="cx">                 events: {
</span><span class="cx">                         'click .attachment-preview':      'toggleSelection',
</span><del>-                        'mouseenter .attachment-preview': 'shrink',
-                        'mouseleave .attachment-preview': 'expand',
</del><ins>+                        // 'mouseenter .attachment-preview': 'shrink',
+                        // 'mouseleave .attachment-preview': 'expand',
</ins><span class="cx">                         'change .describe':               'describe'
</span><span class="cx">                 },
</span><span class="cx"> 
</span><span class="lines">@@ -1052,7 +1059,7 @@
</span><span class="cx">                         options.describe = this.controller.state().get('describe');
</span><span class="cx"> 
</span><span class="cx">                         if ( 'image' === options.type )
</span><del>-                                _.extend( options, this.crop() );
</del><ins>+                                _.extend( options, this.imageSize() );
</ins><span class="cx"> 
</span><span class="cx">                         this.$el.html( this.template( options ) );
</span><span class="cx"> 
</span><span class="lines">@@ -1123,7 +1130,7 @@
</span><span class="cx"> 
</span><span class="cx">                         // Use the provided image size if possible.
</span><span class="cx">                         if ( sizes &amp;&amp; sizes[ size ] ) {
</span><del>-                                return sizes[ size ];
</del><ins>+                                return _.clone( sizes[ size ] );
</ins><span class="cx">                         } else {
</span><span class="cx">                                 return {
</span><span class="cx">                                         url:         this.model.get('url'),
</span><span class="lines">@@ -1134,57 +1141,6 @@
</span><span class="cx">                         }
</span><span class="cx">                 },
</span><span class="cx"> 
</span><del>-                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
-                        });
-                },
-
</del><span class="cx">                 describe: function( event ) {
</span><span class="cx">                         if ( 'image' === this.model.get('type') )
</span><span class="cx">                                 this.model.save( 'caption', event.target.value );
</span><span class="lines">@@ -1225,6 +1181,7 @@
</span><span class="cx">         media.view.Attachments = Backbone.View.extend({
</span><span class="cx">                 tagName:   'ul',
</span><span class="cx">                 className: 'attachments',
</span><ins>+                template:  media.template('attachments-css'),
</ins><span class="cx"> 
</span><span class="cx">                 events: {
</span><span class="cx">                         'scroll': 'scroll'
</span><span class="lines">@@ -1232,6 +1189,7 @@
</span><span class="cx"> 
</span><span class="cx">                 initialize: function() {
</span><span class="cx">                         this.controller = this.options.controller;
</span><ins>+                        this.el.id = _.uniqueId('__attachments-view-');
</ins><span class="cx"> 
</span><span class="cx">                         _.defaults( this.options, {
</span><span class="cx">                                 refreshSensitivity: 200,
</span><span class="lines">@@ -1252,8 +1210,30 @@
</span><span class="cx">                         this.scroll = _.chain( this.scroll ).bind( this ).throttle( this.options.refreshSensitivity ).value();
</span><span class="cx"> 
</span><span class="cx">                         this.initSortable();
</span><ins>+
+                        this.controller.state().on( 'change:edge change:gutter', this.css, this );
+                        this.css();
</ins><span class="cx">                 },
</span><span class="cx"> 
</span><ins>+                destroy: function() {
+                        this.collection.off( 'add remove reset', null, this );
+                        this.controller.state().off( 'change:edge change:gutter', this.css, this );
+                },
+
+                css: function() {
+                        var $css = $( '#' + this.el.id + '-css' ),
+                                state = this.controller.state();
+
+                        if ( $css.length )
+                                $css.remove();
+
+                        media.view.Attachments.$head().append( this.template({
+                                id:     this.el.id,
+                                edge:   state.get('edge'),
+                                gutter: state.get('gutter')
+                        }) );
+                },
+
</ins><span class="cx">                 initSortable: function() {
</span><span class="cx">                         var collection = this.collection,
</span><span class="cx">                                 from;
</span><span class="lines">@@ -1353,6 +1333,13 @@
</span><span class="cx">                                 this.collection.more();
</span><span class="cx">                         }
</span><span class="cx">                 }
</span><ins>+        }, {
+                $head: (function() {
+                        var $head;
+                        return function() {
+                                return $head = $head || $('head');
+                        };
+                }())
</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 (22323 => 22324)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/media.php        2012-10-29 15:13:02 UTC (rev 22323)
+++ trunk/wp-includes/media.php        2012-10-29 18:05:03 UTC (rev 22324)
</span><span class="lines">@@ -1327,8 +1327,7 @@
</span><span class="cx">                                 &lt;div class=&quot;media-progress-bar&quot;&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;
</span><span class="cx">                         &lt;% } else if ( 'image' === type ) { %&gt;
</span><span class="cx">                                 &lt;div class=&quot;thumbnail&quot;&gt;
</span><del>-                                        &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;
</del><ins>+                                        &lt;img src=&quot;&lt;%- url %&gt;&quot; draggable=&quot;false&quot; /&gt;
</ins><span class="cx">                                 &lt;/div&gt;
</span><span class="cx">                         &lt;% } else { %&gt;
</span><span class="cx">                                 &lt;img src=&quot;&lt;%- icon %&gt;&quot; class=&quot;icon&quot; draggable=&quot;false&quot; /&gt;
</span><span class="lines">@@ -1461,5 +1460,34 @@
</span><span class="cx">                         &lt;div class=&quot;button edit&quot;&gt;&lt;?php _e('Edit'); ?&gt;&lt;/div&gt;
</span><span class="cx">                 &lt;/div&gt;
</span><span class="cx">         &lt;/script&gt;
</span><ins>+
+        &lt;script type=&quot;text/html&quot; id=&quot;tmpl-attachments-css&quot;&gt;
+                &lt;style type=&quot;text/css&quot; id=&quot;&lt;%- id %&gt;-css&quot;&gt;
+                        #&lt;%- id %&gt; {
+                                padding: &lt;%- gutter %&gt;px;
+                        }
+
+                        #&lt;%- id %&gt; .attachment {
+                                margin: &lt;%- gutter %&gt;px;
+                                width: &lt;%- edge %&gt;px;
+                        }
+
+                        #&lt;%- id %&gt; .attachment-preview,
+                        #&lt;%- id %&gt; .attachment-preview .thumbnail {
+                                width: &lt;%- edge %&gt;px;
+                                height: &lt;%- edge %&gt;px;
+                        }
+
+                        #&lt;%- id %&gt; .portrait .thumbnail img {
+                                width: &lt;%- edge %&gt;px;
+                                height: auto;
+                        }
+
+                        #&lt;%- id %&gt; .landscape .thumbnail img {
+                                width: auto;
+                                height: &lt;%- edge %&gt;px;
+                        }
+                &lt;/style&gt;
+        &lt;/script&gt;
</ins><span class="cx">         &lt;?php
</span><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>