<!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>[23095] trunk: Add the ability to click "Edit" and kick out to the advanced image editor from within the Media modal.</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/23095">23095</a></dd>
<dt>Author</dt> <dd>markjaquith</dd>
<dt>Date</dt> <dd>2012-12-06 05:52:19 +0000 (Thu, 06 Dec 2012)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add the ability to click "Edit" and kick out to the advanced image editor from within the Media modal. New window, with "Refresh" offered on your return. fixes <a href="http://core.trac.wordpress.org/ticket/22743">#22743</a>. props koopersmith, nacin, helenyhou.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadmincsswpadmincss">trunk/wp-admin/css/wp-admin.css</a></li>
<li><a href="#trunkwpadminincludesimageeditphp">trunk/wp-admin/includes/image-edit.php</a></li>
<li><a href="#trunkwpadminincludesmediaphp">trunk/wp-admin/includes/media.php</a></li>
<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="trunkwpadmincsswpadmincss"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/css/wp-admin.css (23094 => 23095)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/css/wp-admin.css        2012-12-06 05:34:17 UTC (rev 23094)
+++ trunk/wp-admin/css/wp-admin.css        2012-12-06 05:52:19 UTC (rev 23095)
</span><span class="lines">@@ -4150,23 +4150,26 @@
</span><span class="cx">         margin: 8px 0;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+.post-php .imgedit-wrap table {
+        width: 100%;
+}
+
</ins><span class="cx"> .describe .imgedit-wrap table td,
</span><span class="cx"> .wp_attachment_holder .imgedit-wrap table td {
</span><span class="cx">         vertical-align: top;
</span><span class="cx">         padding-top: 0;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-.imgedit-wrap p,
-.describe .imgedit-wrap table td {
-        font-size: 11px;
-        line-height: 18px;
-}
-
</del><span class="cx"> .describe .imgedit-wrap table td.imgedit-settings {
</span><span class="cx">         padding: 0 5px;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+.wp_attachment_holder .imgedit-wrap table td.imgedit-settings {
+        width: 250px;
+}
+
</ins><span class="cx"> td.imgedit-settings input {
</span><ins>+        margin-top: 0;
</ins><span class="cx">         vertical-align: middle;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -4349,19 +4352,10 @@
</span><span class="cx">         margin-bottom: 8px;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-.imgedit-help ul li {
-        font-size: 11px;
-}
-
</del><span class="cx"> a.imgedit-help-toggle {
</span><span class="cx">         text-decoration: none;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-#wpbody-content .imgedit-response div {
-        width: 600px;
-        margin: 8px;
-}
-
</del><span class="cx"> .form-table td.imgedit-response {
</span><span class="cx">         padding: 0;
</span><span class="cx"> }
</span><span class="lines">@@ -4389,8 +4383,8 @@
</span><span class="cx"> .imgedit-group {
</span><span class="cx">         border-width: 1px;
</span><span class="cx">         border-style: solid;
</span><del>-        -webkit-border-radius: 8px;
-        border-radius: 8px;
</del><ins>+        -webkit-border-radius: 3px;
+        border-radius: 3px;
</ins><span class="cx">         margin-bottom: 8px;
</span><span class="cx">         padding: 2px 10px;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkwpadminincludesimageeditphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/image-edit.php (23094 => 23095)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/image-edit.php        2012-12-06 05:34:17 UTC (rev 23094)
+++ trunk/wp-admin/includes/image-edit.php        2012-12-06 05:52:19 UTC (rev 23095)
</span><span class="lines">@@ -191,7 +191,7 @@
</span><span class="cx">         </td></tr>
</span><span class="cx">         </tbody></table>
</span><span class="cx">         <div class="imgedit-wait" id="imgedit-wait-<?php echo $post_id; ?>"></div>
</span><del>-        <script type="text/javascript">imageEdit.init(<?php echo $post_id; ?>);</script>
</del><ins>+        <script type="text/javascript">jQuery( function() { imageEdit.init(<?php echo $post_id; ?>); });</script>
</ins><span class="cx">         <div class="hidden" id="imgedit-leaving-<?php echo $post_id; ?>"><?php _e("There are unsaved changes that will be lost. 'OK' to continue, 'Cancel' to return to the Image Editor."); ?></div>
</span><span class="cx">         </div>
</span><span class="cx"> <?php
</span></span></pre></div>
<a id="trunkwpadminincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/media.php (23094 => 23095)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/media.php        2012-12-06 05:34:17 UTC (rev 23094)
+++ trunk/wp-admin/includes/media.php        2012-12-06 05:52:19 UTC (rev 23095)
</span><span class="lines">@@ -2270,20 +2270,18 @@
</span><span class="cx"> function edit_form_image_editor() {
</span><span class="cx">         $post = get_post();
</span><span class="cx">
</span><ins>+        $open = isset( $_GET['image-editor'] );
+        if ( $open )
+                require_once ABSPATH . 'wp-admin/includes/image-edit.php';
+
</ins><span class="cx">         $thumb_url = false;
</span><span class="cx">         if ( $attachment_id = intval( $post->ID ) )
</span><del>-                $thumb_url = wp_get_attachment_image_src( $attachment_id, array( 900, 600 ), true );
</del><ins>+                $thumb_url = wp_get_attachment_image_src( $attachment_id, array( 900, 450 ), true );
</ins><span class="cx">
</span><span class="cx">         $filename = esc_html( basename( $post->guid ) );
</span><span class="cx">         $title = esc_attr( $post->post_title );
</span><span class="cx">         $alt_text = get_post_meta( $post->ID, '_wp_attachment_image_alt', true );
</span><span class="cx">
</span><del>-        $media_dims = '';
-        $meta = wp_get_attachment_metadata( $post->ID );
-        if ( is_array( $meta ) && array_key_exists( 'width', $meta ) && array_key_exists( 'height', $meta ) )
-                $media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']}&nbsp;&times;&nbsp;{$meta['height']}</span> ";
-        $media_dims = apply_filters( 'media_meta', $media_dims, $post );
-
</del><span class="cx">         $att_url = wp_get_attachment_url( $post->ID );
</span><span class="cx">
</span><span class="cx">         if ( wp_attachment_is_image( $post->ID ) ) :
</span><span class="lines">@@ -2296,11 +2294,13 @@
</span><span class="cx">         <div class="wp_attachment_holder">
</span><span class="cx">                 <div class="imgedit-response" id="imgedit-response-<?php echo $attachment_id; ?>"></div>
</span><span class="cx">
</span><del>-                <div class="wp_attachment_image" id="media-head-<?php echo $attachment_id; ?>">
</del><ins>+                <div<?php if ( $open ) echo ' style="display:none"'; ?> class="wp_attachment_image" id="media-head-<?php echo $attachment_id; ?>">
</ins><span class="cx">                         <p id="thumbnail-head-<?php echo $attachment_id; ?>"><img class="thumbnail" src="<?php echo set_url_scheme( $thumb_url[0] ); ?>" style="max-width:100%" alt="" /></p>
</span><span class="cx">                         <p><?php echo $image_edit_button; ?></p>
</span><span class="cx">                 </div>
</span><del>-                <div style="display:none" class="image-editor" id="image-editor-<?php echo $attachment_id; ?>"></div>
</del><ins>+                <div<?php if ( ! $open ) echo ' style="display:none"'; ?> class="image-editor" id="image-editor-<?php echo $attachment_id; ?>">
+                        <?php if ( $open ) wp_image_editor( $attachment_id ); ?>
+                </div>
</ins><span class="cx">         </div>
</span><span class="cx">         <?php endif; ?>
</span><span class="cx">
</span></span></pre></div>
<a id="trunkwpincludescssmediaviewscss"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/css/media-views.css (23094 => 23095)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/css/media-views.css        2012-12-06 05:34:17 UTC (rev 23094)
+++ trunk/wp-includes/css/media-views.css        2012-12-06 05:52:19 UTC (rev 23095)
</span><span class="lines">@@ -1308,6 +1308,7 @@
</span><span class="cx">         float: left;
</span><span class="cx">         max-width: 120px;
</span><span class="cx">         max-height: 120px;
</span><ins>+        margin-top: 5px;
</ins><span class="cx">         margin-right: 10px;
</span><span class="cx">         margin-bottom: 5px;
</span><span class="cx"> }
</span><span class="lines">@@ -1347,19 +1348,32 @@
</span><span class="cx">         max-width: 100%;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-.attachment-info .delete-attachment a {
-        color: red;
-        padding: 2px 4px;
-        margin: -2px -4px;
</del><ins>+.attachment-info .edit-attachment,
+.attachment-info .refresh-attachment,
+.attachment-info .delete-attachment {
+        display: block;
</ins><span class="cx">         text-decoration: none;
</span><span class="cx">         white-space: nowrap;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-.attachment-info .delete-attachment a:hover {
-        color: #fff;
-        background: red;
</del><ins>+.attachment-info .refresh-attachment,
+.attachment-details.needs-refresh .attachment-info .edit-attachment {
+        display: none;
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+.attachment-details.needs-refresh .attachment-info .refresh-attachment,
+.attachment-info .edit-attachment {
+        display: block;
+}
+
+.attachment-info .delete-attachment {
+        color: #bc0b0b;
+}
+
+.attachment-info .delete-attachment:hover {
+        color: red;
+}
+
</ins><span class="cx"> /**
</span><span class="cx"> * Attachment Display Settings
</span><span class="cx"> */
</span></span></pre></div>
<a id="trunkwpincludesjsmediaviewsjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/media-views.js (23094 => 23095)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/media-views.js        2012-12-06 05:34:17 UTC (rev 23094)
+++ trunk/wp-includes/js/media-views.js        2012-12-06 05:52:19 UTC (rev 23095)
</span><span class="lines">@@ -4021,7 +4021,9 @@
</span><span class="cx">                         'change [data-setting] input': 'updateSetting',
</span><span class="cx">                         'change [data-setting] select': 'updateSetting',
</span><span class="cx">                         'change [data-setting] textarea': 'updateSetting',
</span><del>-                        'click .delete-attachment': 'deleteAttachment'
</del><ins>+                        'click .delete-attachment': 'deleteAttachment',
+                        'click .edit-attachment': 'editAttachment',
+                        'click .refresh-attachment': 'refreshAttachment'
</ins><span class="cx">                 },
</span><span class="cx">
</span><span class="cx">                 initialize: function() {
</span><span class="lines">@@ -4038,11 +4040,21 @@
</span><span class="cx">                         return this;
</span><span class="cx">                 },
</span><span class="cx">
</span><del>-                deleteAttachment: function(event) {
</del><ins>+                deleteAttachment: function( event ) {
</ins><span class="cx">                         event.preventDefault();
</span><span class="cx">
</span><span class="cx">                         if ( confirm( l10n.warnDelete ) )
</span><span class="cx">                                 this.model.destroy();
</span><ins>+                },
+
+                editAttachment: function( event ) {
+                        this.$el.addClass('needs-refresh');
+                },
+
+                refreshAttachment: function( event ) {
+                        this.$el.removeClass('needs-refresh');
+                        event.preventDefault();
+                        this.model.fetch();
</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 (23094 => 23095)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/media.php        2012-12-06 05:34:17 UTC (rev 23094)
+++ trunk/wp-includes/media.php        2012-12-06 05:52:19 UTC (rev 23095)
</span><span class="lines">@@ -1337,10 +1337,13 @@
</span><span class="cx">                         'update' => false,
</span><span class="cx">                         'delete' => false,
</span><span class="cx">                 ),
</span><ins>+                'editLink' => false,
</ins><span class="cx">         );
</span><span class="cx">
</span><del>-        if ( current_user_can( 'edit_post', $attachment->ID ) )
</del><ins>+        if ( current_user_can( 'edit_post', $attachment->ID ) ) {
</ins><span class="cx">                 $response['nonces']['update'] = wp_create_nonce( 'update-post_' . $attachment->ID );
</span><ins>+                $response['editLink'] = get_edit_post_link( $attachment->ID, 'raw' );
+        }
</ins><span class="cx">
</span><span class="cx">         if ( current_user_can( 'delete_post', $attachment->ID ) )
</span><span class="cx">                 $response['nonces']['delete'] = wp_create_nonce( 'delete-post_' . $attachment->ID );
</span><span class="lines">@@ -1703,14 +1706,22 @@
</span><span class="cx">                         <div class="details">
</span><span class="cx">                                 <div class="filename">{{ data.filename }}</div>
</span><span class="cx">                                 <div class="uploaded">{{ data.dateFormatted }}</div>
</span><del>-                                <# if ( 'image' === data.type && ! data.uploading && data.width && data.height ) { #>
-                                        <div class="dimensions">{{ data.width }} &times; {{ data.height }}</div>
</del><ins>+
+                                <# if ( 'image' === data.type && ! data.uploading ) { #>
+                                        <# if ( data.width && data.height ) { #>
+                                                <div class="dimensions">{{ data.width }} &times; {{ data.height }}</div>
+                                        <# } #>
+
+                                        <# if ( data.can.save ) { #>
+                                                <a class="edit-attachment" href="{{ data.editLink }}&amp;image-editor" target="_blank"><?php _e( 'Edit Image' ); ?></a>
+                                                <a class="refresh-attachment" href="#"><?php _e( 'Refresh' ); ?></a>
+                                        <# } #>
</ins><span class="cx">                                 <# } #>
</span><ins>+
</ins><span class="cx">                                 <# if ( ! data.uploading && data.can.remove ) { #>
</span><del>-                                        <div class="delete-attachment">
-                                                <a href="#"><?php _e( 'Delete Permanently' ); ?></a>
-                                        </div>
</del><ins>+                                        <a class="delete-attachment" href="#"><?php _e( 'Delete Permanently' ); ?></a>
</ins><span class="cx">                                 <# } #>
</span><ins>+
</ins><span class="cx">                                 <div class="compat-meta">
</span><span class="cx">                                         <# if ( data.compat && data.compat.meta ) { #>
</span><span class="cx">                                                 {{{ data.compat.meta }}}
</span></span></pre>
</div>
</div>
</body>
</html>