<!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>[22036] trunk: BUTTON.</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/22036">22036</a></dd>
<dt>Author</dt> <dd>koopersmith</dd>
<dt>Date</dt> <dd>2012-09-27 04:09:43 +0000 (Thu, 27 Sep 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>BUTTON.

Add a &quot;Beta Media&quot; button to the post editor. Currently, it is only capable of inserting images. Other attachment types and galleries need not apply... yet.

* Added `wp.media.string.image( attachment, props )` for generating an image as a string from an attachment and relevant attachment display properties.
* Properly localized the gallery workflow.
* Added `Workflow.update()`, which closes the modal, triggers an `update` event, and resets the selection.
* Added `wp.mce.media` to manage the various media workflows for editors.

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

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesmediaphp">trunk/wp-admin/includes/media.php</a></li>
<li><a href="#trunkwpadminjsmediauploadjs">trunk/wp-admin/js/media-upload.js</a></li>
<li><a href="#trunkwpincludescsseditorcss">trunk/wp-includes/css/editor.css</a></li>
<li><a href="#trunkwpincludesjsmceviewjs">trunk/wp-includes/js/mce-view.js</a></li>
<li><a href="#trunkwpincludesjsmediaviewsjs">trunk/wp-includes/js/media-views.js</a></li>
<li><a href="#trunkwpincludesscriptloaderphp">trunk/wp-includes/script-loader.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/media.php (22035 => 22036)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/media.php        2012-09-27 03:47:21 UTC (rev 22035)
+++ trunk/wp-admin/includes/media.php        2012-09-27 04:09:43 UTC (rev 22036)
</span><span class="lines">@@ -381,6 +381,8 @@
</span><span class="cx"> 
</span><span class="cx">         $img = '&lt;img src=&quot;' . esc_url( admin_url( 'images/media-button.png?ver=20111005' ) ) . '&quot; width=&quot;16&quot; height=&quot;16&quot; /&gt;';
</span><span class="cx"> 
</span><ins>+        echo '&lt;a href=&quot;#&quot; class=&quot;button insert-media&quot; data-editor=&quot;' . esc_attr( $editor_id ) . '&quot; title=&quot;' . esc_attr__( 'Add Media' ) . '&quot;&gt;' . sprintf( __('%s Beta Media'), $img ) . '&lt;/a&gt;';
+
</ins><span class="cx">         echo '&lt;a href=&quot;' . esc_url( get_upload_iframe_src() ) . '&quot; class=&quot;thickbox add_media&quot; id=&quot;' . esc_attr( $editor_id ) . '-add_media&quot; title=&quot;' . esc_attr__( 'Add Media' ) . '&quot; onclick=&quot;return false;&quot;&gt;' . sprintf( $context, $img ) . '&lt;/a&gt;';
</span><span class="cx"> }
</span><span class="cx"> add_action( 'media_buttons', 'media_buttons' );
</span></span></pre></div>
<a id="trunkwpadminjsmediauploadjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/js/media-upload.js (22035 => 22036)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/js/media-upload.js        2012-09-27 03:47:21 UTC (rev 22035)
+++ trunk/wp-admin/js/media-upload.js        2012-09-27 04:09:43 UTC (rev 22036)
</span><span class="lines">@@ -86,3 +86,66 @@
</span><span class="cx">         });
</span><span class="cx"> 
</span><span class="cx"> })(jQuery);
</span><ins>+
+// WordPress, TinyMCE, and Media
+// -----------------------------
+(function($){
+        // Stores the editors' `wp.media.controller.Workflow` instaces.
+        var workflows = {};
+
+        wp.mce.media = {
+                insert: send_to_editor,
+
+                add: function( id, options ) {
+                        var workflow = this.get( id );
+
+                        if ( workflow )
+                                return workflow;
+
+                        workflow = workflows[ id ] = wp.media( _.defaults( options || {}, {
+                                multiple: true
+                        } ) );
+
+                        workflow.on( 'update', function( selection ) {
+                                this.insert( '\n' + selection.map( function( attachment ) {
+                                        return wp.media.string.image( attachment );
+                                }).join('\n\n') + '\n' );
+                        }, this );
+
+                        return workflow;
+                },
+
+                get: function( id ) {
+                        return workflows[ id ];
+                },
+
+                remove: function( id ) {
+                        delete workflows[ id ];
+                },
+
+                init: function() {
+                        $('.insert-media').on( 'click', function( event ) {
+                                var editor = $(this).data('editor'),
+                                        workflow;
+
+                                event.preventDefault();
+
+                                if ( ! editor )
+                                        return;
+
+                                workflow = wp.mce.media.get( editor );
+
+                                // If the workflow exists, just open it.
+                                if ( workflow ) {
+                                        workflow.open();
+                                        return;
+                                }
+
+                                // Initialize the editor's workflow if we haven't yet.
+                                wp.mce.media.add( editor );
+                        });
+                }
+        };
+
+        $( wp.mce.media.init )
+}(jQuery));
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkwpincludescsseditorcss"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/css/editor.css (22035 => 22036)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/css/editor.css        2012-09-27 03:47:21 UTC (rev 22035)
+++ trunk/wp-includes/css/editor.css        2012-09-27 04:09:43 UTC (rev 22036)
</span><span class="lines">@@ -1008,7 +1008,7 @@
</span><span class="cx"> 
</span><span class="cx"> .wp-editor-tools {
</span><span class="cx">         height: 30px;
</span><del>-        padding: 0 10px;
</del><ins>+        padding: 0 10px 0 0;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> .wp-editor-container {
</span><span class="lines">@@ -1079,16 +1079,18 @@
</span><span class="cx">         color: #555;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-.wp-media-buttons {
-        line-height: 1;
-    padding: 9px 0 0;
</del><ins>+.wp-media-buttons .button {
+        margin-right: 5px;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+.wp-media-buttons .insert-media {
+        padding-left: 0.4em;
+}
+
</ins><span class="cx"> .wp-media-buttons a {
</span><span class="cx">         text-decoration: none;
</span><del>-        color: #333;
</del><ins>+        color: #464646;
</ins><span class="cx">         font-size: 12px;
</span><del>-        vertical-align: bottom;
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> .wp-media-buttons img {
</span></span></pre></div>
<a id="trunkwpincludesjsmceviewjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/mce-view.js (22035 => 22036)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/mce-view.js        2012-09-27 03:47:21 UTC (rev 22035)
+++ trunk/wp-includes/js/mce-view.js        2012-09-27 04:09:43 UTC (rev 22036)
</span><span class="lines">@@ -359,45 +359,68 @@
</span><span class="cx"> // Default TinyMCE Views
</span><span class="cx"> // ---------------------
</span><span class="cx"> (function($){
</span><del>-        var mceview = wp.mce.view,
-                mceFreeAttrs;
</del><ins>+        var mceview = wp.mce.view;
</ins><span class="cx"> 
</span><del>-        mceview.add( 'attachment', {
-                pattern: new RegExp( '(?:&lt;a([^&gt;]*)&gt;)?&lt;img([^&gt;]*class=(?:&quot;[^&quot;]*|\'[^\']*)\\bwp-image-(\\d+)[^&gt;]*)&gt;(?:&lt;/a&gt;)?' ),
</del><ins>+        wp.media.string = {};
+        wp.media.string.image = function( attachment, props ) {
+                var classes, img, options, size;
</ins><span class="cx"> 
</span><del>-                text: function( instance ) {
-                        var img     = _.clone( instance.img ),
-                                classes = img['class'].split(/\s+/),
-                                options;
</del><ins>+                attachment = attachment.toJSON();
</ins><span class="cx"> 
</span><del>-                        // Update `img` classes.
-                        if ( instance.align )
-                                classes.push( 'align' + instance.align );
</del><ins>+                props = _.defaults( props || {}, {
+                        img:   {},
+                        align: getUserSetting( 'align', 'none' ),
+                        size:  getUserSetting( 'imgsize', 'medium' ),
+                        link:  getUserSetting( 'urlbutton', 'post' )
+                });
</ins><span class="cx"> 
</span><del>-                        if ( instance.size )
-                                classes.push( 'size-' + instance.size );
</del><ins>+                img     = _.clone( props.img );
+                classes = img['class'] ? img['class'].split(/\s+/) : [];
+                size    = attachment.sizes ? attachment.sizes[ props.size ] : {};
</ins><span class="cx"> 
</span><del>-                        classes.push( 'wp-image-' + instance.model.id );
</del><ins>+                if ( ! size )
+                        delete props.size;
</ins><span class="cx"> 
</span><del>-                        img['class'] = _.compact( classes ).join(' ');
</del><ins>+                img.width  = size.width  || attachment.width;
+                img.height = size.height || attachment.height;
+                img.src    = size.url    || attachment.url;
</ins><span class="cx"> 
</span><del>-                        // Generate `img` tag options.
</del><ins>+                // Update `img` classes.
+                if ( props.align )
+                        classes.push( 'align' + props.align );
+
+                if ( props.size )
+                        classes.push( 'size-' + props.size );
+
+                classes.push( 'wp-image-' + attachment.id );
+
+                img['class'] = _.compact( classes ).join(' ');
+
+                // Generate `img` tag options.
+                options = {
+                        tag:    'img',
+                        attrs:  img,
+                        single: true
+                };
+
+                // Generate the `a` element options, if they exist.
+                if ( props.anchor ) {
</ins><span class="cx">                         options = {
</span><del>-                                tag:    'img',
-                                attrs:  img,
-                                single: true
</del><ins>+                                tag:     'a',
+                                attrs:   props.anchor,
+                                content: options
</ins><span class="cx">                         };
</span><ins>+                }
</ins><span class="cx"> 
</span><del>-                        // Generate the `a` element options, if they exist.
-                        if ( instance.anchor ) {
-                                options = {
-                                        tag:     'a',
-                                        attrs:   instance.anchor,
-                                        content: options
-                                };
-                        }
</del><ins>+                return wp.html.string( options );
+        };
</ins><span class="cx"> 
</span><del>-                        return wp.html.string( options );
</del><ins>+        mceview.add( 'attachment', {
+                pattern: new RegExp( '(?:&lt;a([^&gt;]*)&gt;)?&lt;img([^&gt;]*class=(?:&quot;[^&quot;]*|\'[^\']*)\\bwp-image-(\\d+)[^&gt;]*)&gt;(?:&lt;/a&gt;)?' ),
+
+                text: function( instance ) {
+                        var props = _.pick( instance, 'align', 'size', 'link', 'img', 'anchor' );
+                        return wp.media.string.image( instance.model, props );
</ins><span class="cx">                 },
</span><span class="cx"> 
</span><span class="cx">                 view: {
</span></span></pre></div>
<a id="trunkwpincludesjsmediaviewsjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/media-views.js (22035 => 22036)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/media-views.js        2012-09-27 03:47:21 UTC (rev 22035)
+++ trunk/wp-includes/js/media-views.js        2012-09-27 04:09:43 UTC (rev 22036)
</span><span class="lines">@@ -116,6 +116,12 @@
</span><span class="cx">                         return this;
</span><span class="cx">                 },
</span><span class="cx"> 
</span><ins>+                update: function() {
+                        this.close();
+                        this.trigger( 'update', this.selection );
+                        this.selection.clear();
+                },
+
</ins><span class="cx">                 createSelection: function() {
</span><span class="cx">                         var controller = this;
</span><span class="cx"> 
</span><span class="lines">@@ -479,7 +485,8 @@
</span><span class="cx"> 
</span><span class="cx">                                         'insert-into-post': {
</span><span class="cx">                                                 text:     l10n.insertIntoPost,
</span><del>-                                                priority: 30
</del><ins>+                                                priority: 30,
+                                                click:    _.bind( controller.update, controller )
</ins><span class="cx">                                         },
</span><span class="cx"> 
</span><span class="cx">                                         'add-to-gallery': {
</span><span class="lines">@@ -528,24 +535,23 @@
</span><span class="cx">                         this.toolbarView = new media.view.Toolbar({
</span><span class="cx">                                 items: {
</span><span class="cx">                                         'return-to-library': {
</span><del>-                                                text:  'Return to media library',
</del><ins>+                                                text:     l10n.returnToLibrary,
</ins><span class="cx">                                                 priority: -40,
</span><ins>+
</ins><span class="cx">                                                 click:  function() {
</span><span class="cx">                                                         controller.render('library');
</span><span class="cx">                                                 }
</span><span class="cx">                                         },
</span><span class="cx"> 
</span><span class="cx">                                         'insert-gallery-into-post': {
</span><del>-                                                style: 'primary',
-                                                text:  'Insert gallery into post',
</del><ins>+                                                style:    'primary',
+                                                text:     l10n.insertGalleryIntoPost,
</ins><span class="cx">                                                 priority: 40,
</span><del>-                                                click:  function() {
-                                                        controller.close();
-                                                }
</del><ins>+                                                click:    _.bind( controller.update, controller )
</ins><span class="cx">                                         },
</span><span class="cx"> 
</span><del>-                                        'add-images': {
-                                                text:  'Add images from media library',
</del><ins>+                                        'add-images-from-library': {
+                                                text:     l10n.addImagesFromLibrary,
</ins><span class="cx">                                                 priority: 30
</span><span class="cx">                                         }
</span><span class="cx">                                 }
</span></span></pre></div>
<a id="trunkwpincludesscriptloaderphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/script-loader.php (22035 => 22036)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/script-loader.php        2012-09-27 03:47:21 UTC (rev 22035)
+++ trunk/wp-includes/script-loader.php        2012-09-27 04:09:43 UTC (rev 22036)
</span><span class="lines">@@ -297,7 +297,7 @@
</span><span class="cx">                 'type' =&gt; 'characters' == _x( 'words', 'word count: words or characters?' ) ? 'c' : 'w',
</span><span class="cx">         ) );
</span><span class="cx"> 
</span><del>-        $scripts-&gt;add( 'media-upload', &quot;/wp-admin/js/media-upload$suffix.js&quot;, array( 'thickbox' ), false, 1 );
</del><ins>+        $scripts-&gt;add( 'media-upload', &quot;/wp-admin/js/media-upload$suffix.js&quot;, array( 'thickbox', 'mce-view' ), false, 1 );
</ins><span class="cx"> 
</span><span class="cx">         $scripts-&gt;add( 'hoverIntent', &quot;/wp-includes/js/hoverIntent$suffix.js&quot;, array('jquery'), 'r6', 1 );
</span><span class="cx"> 
</span><span class="lines">@@ -317,12 +317,20 @@
</span><span class="cx">         $scripts-&gt;add( 'media-models', &quot;/wp-includes/js/media-models$suffix.js&quot;, array( 'backbone', 'jquery' ), false, 1 );
</span><span class="cx">         $scripts-&gt;add( 'media-views',  &quot;/wp-includes/js/media-views$suffix.js&quot;,  array( 'media-models', 'wp-plupload' ), false, 1 );
</span><span class="cx">         did_action( 'init' ) &amp;&amp; $scripts-&gt;localize( 'media-views', '_wpMediaViewsL10n', array(
</span><del>-                'insertMedia'         =&gt; __( 'Insert Media' ),
-                'selectMediaSingular' =&gt; __( 'Select a media file:' ),
-                'selectMediaMultiple' =&gt; __( 'Select one or more media files:' ),
-                'createNewGallery'    =&gt; __( 'Create a new gallery' ),
-                'insertIntoPost'      =&gt; __( 'Insert into post' ),
-                'addToGallery'        =&gt; __( 'Add to gallery' ),
</del><ins>+                // Generic
+                'insertMedia'           =&gt; __( 'Insert Media' ),
+                'selectMediaSingular'   =&gt; __( 'Select a media file:' ),
+                'selectMediaMultiple'   =&gt; __( 'Select one or more media files:' ),
+
+                // Library
+                'createNewGallery'      =&gt; __( 'Create a new gallery' ),
+                'insertIntoPost'        =&gt; __( 'Insert into post' ),
+                'addToGallery'          =&gt; __( 'Add to gallery' ),
+
+                // Gallery
+                'returnToLibrary'       =&gt; __( 'Return to media library' ),
+                'insertGalleryIntoPost' =&gt; __( 'Insert gallery into post' ),
+                'addImagesFromLibrary'  =&gt; __( 'Add images from media library' ),
</ins><span class="cx">         ) );
</span><span class="cx"> 
</span><span class="cx">         $scripts-&gt;add( 'shortcode', &quot;/wp-includes/js/shortcode$suffix.js&quot;, array( 'underscore' ), false, 1 );
</span></span></pre>
</div>
</div>

</body>
</html>