<!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>[23069] trunk/wp-includes/js: When setting the featured image from the dedicated meta box, only show the featured image section in the media chooser.</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/23069">23069</a></dd>
<dt>Author</dt> <dd>markjaquith</dd>
<dt>Date</dt> <dd>2012-12-05 09:43:10 +0000 (Wed, 05 Dec 2012)</dd>
</dl>
<h3>Log Message</h3>
<pre>When setting the featured image from the dedicated meta box, only show the featured image section in the media chooser. props koopersmith. fixes <a href="http://core.trac.wordpress.org/ticket/22731">#22731</a>
* Less distracting
* Some of these sections won't apply for CPTs without an editor</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesjsmediaeditorjs">trunk/wp-includes/js/media-editor.js</a></li>
<li><a href="#trunkwpincludesjsmediaviewsjs">trunk/wp-includes/js/media-views.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesjsmediaeditorjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/media-editor.js (23068 => 23069)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/media-editor.js        2012-12-05 09:25:17 UTC (rev 23068)
+++ trunk/wp-includes/js/media-editor.js        2012-12-05 09:43:10 UTC (rev 23069)
</span><span class="lines">@@ -320,6 +320,74 @@
</span><span class="cx">                 };
</span><span class="cx">         }());
</span><span class="cx">
</span><ins>+        wp.media.featuredImage = {
+                get: function() {
+                        return wp.media.view.settings.post.featuredImageId;
+                },
+
+                set: function( id ) {
+                        var settings = wp.media.view.settings;
+
+                        settings.post.featuredImageId = id;
+
+                        wp.media.post( 'set-post-thumbnail', {
+                                json: true,
+                                post_id: settings.post.id,
+                                thumbnail_id: settings.post.featuredImageId,
+                                _wpnonce: settings.post.nonce
+                        }).done( function( html ) {
+                                $( '.inside', '#postimagediv' ).html( html );
+                        });
+                },
+
+                frame: function() {
+                        if ( this._frame )
+                                return this._frame;
+
+                        this._frame = wp.media({
+                                state: 'featured-image',
+                                states: [ new wp.media.controller.FeaturedImage() ]
+                        });
+
+                        this._frame.on( 'toolbar:create:featured-image', function( toolbar ) {
+                                this.createSelectToolbar( toolbar, {
+                                        text: wp.media.view.l10n.setFeaturedImage
+                                });
+                        }, this._frame );
+
+                        this._frame.state('featured-image').on( 'select', this.select );
+                        return this._frame;
+                },
+
+                select: function() {
+                        var settings = wp.media.view.settings,
+                                selection = this.get('selection').single();
+
+                        if ( ! settings.post.featuredImageId )
+                                return;
+
+                        wp.media.featuredImage.set( selection ? selection.id : -1 );
+                },
+
+                init: function() {
+                        // Open the content media manager to the 'featured image' tab when
+                        // the post thumbnail is clicked.
+                        $('#postimagediv').on( 'click', '#set-post-thumbnail', function( event ) {
+                                event.preventDefault();
+                                // Stop propagation to prevent thickbox from activating.
+                                event.stopPropagation();
+
+                                wp.media.featuredImage.frame().open();
+
+                        // Update the featured image id when the 'remove' link is clicked.
+                        }).on( 'click', '#remove-post-thumbnail', function() {
+                                wp.media.view.settings.post.featuredImageId = -1;
+                        });
+                }
+        };
+
+        $( wp.media.featuredImage.init );
+
</ins><span class="cx">         wp.media.editor = {
</span><span class="cx">                 insert: function( h ) {
</span><span class="cx">                         var mce = typeof(tinymce) != 'undefined',
</span><span class="lines">@@ -443,24 +511,7 @@
</span><span class="cx">                                 }
</span><span class="cx">                         }, this );
</span><span class="cx">
</span><del>-                        workflow.state('featured-image').on( 'select', function() {
-                                var settings = wp.media.view.settings,
-                                        selection = this.get('selection').single();
-
-                                if ( ! settings.post.featuredImageId )
-                                        return;
-
-                                settings.post.featuredImageId = selection ? selection.id : -1;
-                                wp.media.post( 'set-post-thumbnail', {
-                                        json: true,
-                                        post_id: settings.post.id,
-                                        thumbnail_id: settings.post.featuredImageId,
-                                        _wpnonce: settings.post.nonce
-                                }).done( function( html ) {
-                                        $( '.inside', '#postimagediv' ).html( html );
-                                });
-                        });
-
</del><ins>+                        workflow.state('featured-image').on( 'select', wp.media.featuredImage.select );
</ins><span class="cx">                         workflow.setState( workflow.options.state );
</span><span class="cx">                         return workflow;
</span><span class="cx">                 },
</span><span class="lines">@@ -586,37 +637,6 @@
</span><span class="cx">
</span><span class="cx">                                 wp.media.editor.open( editor );
</span><span class="cx">                         });
</span><del>-
-                        // Open the content media manager to the 'featured image' tab when
-                        // the post thumbnail is clicked.
-                        $('#postimagediv').on( 'click', '#set-post-thumbnail', function( event ) {
-                                event.preventDefault();
-                                // Stop propagation to prevent thickbox from activating.
-                                event.stopPropagation();
-
-                                // Always get the 'content' frame, since this is tailored to post.php.
-                                var frame = wp.media.editor.add('content'),
-                                        initialState = frame.state().id,
-                                        escape;
-
-                                escape = function() {
-                                        // Only run this event once.
-                                        this.off( 'escape', escape );
-
-                                        // If we're still on the 'featured-image' state, restore
-                                        // the initial state.
-                                        if ( 'featured-image' === this.state().id )
-                                                this.setState( initialState );
-                                };
-
-                                frame.on( 'escape', escape, frame );
-
-                                frame.setState('featured-image').open();
-
-                        // Update the featured image id when the 'remove' link is clicked.
-                        }).on( 'click', '#remove-post-thumbnail', function() {
-                                wp.media.view.settings.post.featuredImageId = -1;
-                        });
</del><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 (23068 => 23069)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/media-views.js        2012-12-05 09:25:17 UTC (rev 23068)
+++ trunk/wp-includes/js/media-views.js        2012-12-05 09:43:10 UTC (rev 23069)
</span><span class="lines">@@ -289,7 +289,7 @@
</span><span class="cx">                         this.frame.router.render( mode );
</span><span class="cx">
</span><span class="cx">                         view = router.get();
</span><del>-                        if ( view.select )
</del><ins>+                        if ( view && view.select )
</ins><span class="cx">                                 view.select( this.frame.content.mode() );
</span><span class="cx">                 },
</span><span class="cx">
</span><span class="lines">@@ -304,7 +304,7 @@
</span><span class="cx">                         menu.mode( mode );
</span><span class="cx">
</span><span class="cx">                         view = menu.get();
</span><del>-                        if ( view.select )
</del><ins>+                        if ( view && view.select )
</ins><span class="cx">                                 view.select( this.id );
</span><span class="cx">                 },
</span><span class="cx">
</span><span class="lines">@@ -357,6 +357,7 @@
</span><span class="cx">                         sidebar: 'settings',
</span><span class="cx">                         content: 'upload',
</span><span class="cx">                         router: 'browse',
</span><ins>+                        menu: 'default',
</ins><span class="cx">                         searchable: true,
</span><span class="cx">                         filterable: false,
</span><span class="cx">                         sortable: true,
</span><span class="lines">@@ -638,7 +639,6 @@
</span><span class="cx">                         id: 'featured-image',
</span><span class="cx">                         filterable: 'uploaded',
</span><span class="cx">                         multiple: false,
</span><del>-                        menu: 'main',
</del><span class="cx">                         toolbar: 'featured-image',
</span><span class="cx">                         title: l10n.featuredImageTitle,
</span><span class="cx">                         priority: 60
</span><span class="lines">@@ -676,6 +676,17 @@
</span><span class="cx">                 },
</span><span class="cx">
</span><span class="cx">                 activate: function() {
</span><ins>+                        this.updateSelection();
+                        this.frame.on( 'open', this.updateSelection, this );
+                        media.controller.Library.prototype.activate.apply( this, arguments );
+                },
+
+                deactivate: function() {
+                        this.frame.off( 'open', this.updateSelection, this );
+                        media.controller.Library.prototype.deactivate.apply( this, arguments );
+                },
+
+                updateSelection: function() {
</ins><span class="cx">                         var selection = this.get('selection'),
</span><span class="cx">                                 id = media.view.settings.post.featuredImageId,
</span><span class="cx">                                 attachment;
</span><span class="lines">@@ -686,7 +697,6 @@
</span><span class="cx">                         }
</span><span class="cx">
</span><span class="cx">                         selection.reset( attachment ? [ attachment ] : [] );
</span><del>-                        media.controller.Library.prototype.activate.apply( this, arguments );
</del><span class="cx">                 }
</span><span class="cx">         });
</span><span class="cx">
</span><span class="lines">@@ -697,7 +707,7 @@
</span><span class="cx">                 defaults: {
</span><span class="cx">                         id: 'embed',
</span><span class="cx">                         url: '',
</span><del>-                        menu: 'main',
</del><ins>+                        menu: 'default',
</ins><span class="cx">                         content: 'embed',
</span><span class="cx">                         toolbar: 'main-embed',
</span><span class="cx">                         type: 'link',
</span><span class="lines">@@ -1200,6 +1210,9 @@
</span><span class="cx">                                 model.frame = this;
</span><span class="cx">                                 model.trigger('ready');
</span><span class="cx">                         }, this );
</span><ins>+
+                        if ( this.options.states )
+                                this.states.add( this.options.states );
</ins><span class="cx">                 },
</span><span class="cx">
</span><span class="cx">                 reset: function() {
</span><span class="lines">@@ -1263,6 +1276,9 @@
</span><span class="cx">                         // Bind default title creation.
</span><span class="cx">                         this.on( 'title:create:default', this.createTitle, this );
</span><span class="cx">                         this.title.mode('default');
</span><ins>+
+                        // Bind default menu.
+                        this.on( 'menu:create:default', this.createMenu, this );
</ins><span class="cx">                 },
</span><span class="cx">
</span><span class="cx">                 render: function() {
</span><span class="lines">@@ -1319,12 +1335,12 @@
</span><span class="cx">                                         src: tabUrl + '&tab=' + id,
</span><span class="cx">                                         title: title,
</span><span class="cx">                                         content: 'iframe',
</span><del>-                                        menu: 'main'
</del><ins>+                                        menu: 'default'
</ins><span class="cx">                                 }, options ) );
</span><span class="cx">                         }, this );
</span><span class="cx">
</span><span class="cx">                         this.on( 'content:create:iframe', this.iframeContent, this );
</span><del>-                        this.on( 'menu:render:main', this.iframeMenu, this );
</del><ins>+                        this.on( 'menu:render:default', this.iframeMenu, this );
</ins><span class="cx">                         this.on( 'open', this.hijackThickbox, this );
</span><span class="cx">                         this.on( 'close', this.restoreThickbox, this );
</span><span class="cx">                 },
</span><span class="lines">@@ -1418,6 +1434,9 @@
</span><span class="cx">                 createStates: function() {
</span><span class="cx">                         var options = this.options;
</span><span class="cx">
</span><ins>+                        if ( this.options.states )
+                                return;
+
</ins><span class="cx">                         // Add the default states.
</span><span class="cx">                         this.states.add([
</span><span class="cx">                                 // Main states.
</span><span class="lines">@@ -1425,7 +1444,6 @@
</span><span class="cx">                                         selection: options.selection,
</span><span class="cx">                                         library: media.query( options.library ),
</span><span class="cx">                                         multiple: options.multiple,
</span><del>-                                        menu: 'main',
</del><span class="cx">                                         title: options.title,
</span><span class="cx">                                         priority: 20
</span><span class="cx">                                 })
</span><span class="lines">@@ -1433,7 +1451,6 @@
</span><span class="cx">                 },
</span><span class="cx">
</span><span class="cx">                 bindHandlers: function() {
</span><del>-                        this.on( 'menu:create:main', this.createMenu, this );
</del><span class="cx">                         this.on( 'router:create:browse', this.createRouter, this );
</span><span class="cx">                         this.on( 'router:render:browse', this.browseRouter, this );
</span><span class="cx">                         this.on( 'content:create:browse', this.browseContent, this );
</span><span class="lines">@@ -1519,7 +1536,6 @@
</span><span class="cx">                                         id: 'insert',
</span><span class="cx">                                         title: l10n.insertMediaTitle,
</span><span class="cx">                                         priority: 20,
</span><del>-                                        menu: 'main',
</del><span class="cx">                                         toolbar: 'main-insert',
</span><span class="cx">                                         filterable: 'all',
</span><span class="cx">                                         library: media.query( options.library ),
</span><span class="lines">@@ -1538,7 +1554,6 @@
</span><span class="cx">                                         id: 'gallery',
</span><span class="cx">                                         title: l10n.createGalleryTitle,
</span><span class="cx">                                         priority: 40,
</span><del>-                                        menu: 'main',
</del><span class="cx">                                         toolbar: 'main-gallery',
</span><span class="cx">                                         filterable: 'uploaded',
</span><span class="cx">                                         multiple: 'add',
</span><span class="lines">@@ -1568,10 +1583,7 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx">                         if ( media.view.settings.post.featuredImageId ) {
</span><del>-                                this.states.add( new media.controller.FeaturedImage({
-                                        controller: this,
-                                        menu: 'main'
-                                }) );
</del><ins>+                                this.states.add( new media.controller.FeaturedImage() );
</ins><span class="cx">                         }
</span><span class="cx">                 },
</span><span class="cx">
</span><span class="lines">@@ -1585,7 +1597,7 @@
</span><span class="cx">
</span><span class="cx">                         var handlers = {
</span><span class="cx">                                         menu: {
</span><del>-                                                'main': 'mainMenu',
</del><ins>+                                                'default': 'mainMenu',
</ins><span class="cx">                                                 'gallery': 'galleryMenu'
</span><span class="cx">                                         },
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>