<!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>[22466] trunk: Media: Improve sidebar handling and make attachment display properties attachment-specific.</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/22466">22466</a></dd>
<dt>Author</dt> <dd>koopersmith</dd>
<dt>Date</dt> <dd>2012-11-08 14:15:09 +0000 (Thu, 08 Nov 2012)</dd>
</dl>
<h3>Log Message</h3>
<pre>Media: Improve sidebar handling and make attachment display properties attachment-specific.
`wp.mce.media`
* Watch all workflows for the `insert` event and attempt to insert the current state's `selection` if it exists.
* Fetch and pass attachment display properties through to `wp.media.string.image()`.
`wp.media.controller.Region`
* Separate the concept of events and modes.
* All events triggered on a `Region` trigger both `event` and `event:mode` callbacks.
* When a mode is deactivated, `deactivate` and `deactivate:mode` events are fired.
* When a mode is activated, `activate` and `activate:mode` events are fired.
`wp.media.controller.Library`
* Remove the `details()`, `buildDetails()`, and `clearDetails()` methods that juggled sidebar views. Instead, handle the sidebar views using modes.
`wp.media.controller.Gallery`
* Shift the overloaded `sidebar()` method to use modes.
`wp.media.view.MediaFrame.Post`
* Declare `activate:mode` event bindings using an nested object to reduce repetition.
* Update sidebar activation callbacks.
`wp.media.view.Settings`
* Refactor to leverage HTML data attributes and implicit values (instead of setting the fallback whenever an object was created). This has the additional benefit that gallery shortcode parameters are not output when the user has left them set to the default.
see <a href="http://core.trac.wordpress.org/ticket/21390">#21390</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminjsmediauploadjs">trunk/wp-admin/js/media-upload.js</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="trunkwpadminjsmediauploadjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/js/media-upload.js (22465 => 22466)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/js/media-upload.js        2012-11-08 13:52:40 UTC (rev 22465)
+++ trunk/wp-admin/js/media-upload.js        2012-11-08 14:15:09 UTC (rev 22466)
</span><span class="lines">@@ -107,10 +107,22 @@
</span><span class="cx">                                 multiple: true
</span><span class="cx">                         } ) );
</span><span class="cx">
</span><del>-                        workflow.get('library').on( 'insert', function( selection ) {
</del><ins>+                        workflow.on( 'insert', function() {
+                                var state = workflow.state(),
+                                        selection = state.get('selection'),
+                                        details = state.get('details');
+
+                                if ( ! selection || ! details )
+                                        return;
+
</ins><span class="cx">                                 this.insert( selection.map( function( attachment ) {
</span><ins>+                                        var detail = details[ attachment.cid ];
+
+                                        if ( detail )
+                                                detail = detail.toJSON();
+
</ins><span class="cx">                                         if ( 'image' === attachment.get('type') )
</span><del>-                                                return wp.media.string.image( attachment ) + ' ';
</del><ins>+                                                return wp.media.string.image( attachment, detail ) + ' ';
</ins><span class="cx">                                         else
</span><span class="cx">                                                 return wp.media.string.link( attachment ) + ' ';
</span><span class="cx">                                 }).join('') );
</span></span></pre></div>
<a id="trunkwpincludescssmediaviewscss"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/css/media-views.css (22465 => 22466)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/css/media-views.css        2012-11-08 13:52:40 UTC (rev 22465)
+++ trunk/wp-includes/css/media-views.css        2012-11-08 14:15:09 UTC (rev 22466)
</span><span class="lines">@@ -759,6 +759,10 @@
</span><span class="cx"> * Attachment Details
</span><span class="cx"> */
</span><span class="cx">
</span><ins>+.attachment-details {
+        overflow: auto;
+}
+
</ins><span class="cx"> .attachment-details-preview {
</span><span class="cx">         cursor: default;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkwpincludesjsmediaviewsjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/media-views.js (22465 => 22466)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/media-views.js        2012-11-08 13:52:40 UTC (rev 22465)
+++ trunk/wp-includes/js/media-views.js        2012-11-08 14:15:09 UTC (rev 22466)
</span><span class="lines">@@ -58,7 +58,7 @@
</span><span class="cx">         media.controller.Region = function( options ) {
</span><span class="cx">                 _.extend( this, _.pick( options || {}, 'id', 'controller' ) );
</span><span class="cx">
</span><del>-                this.on( 'empty', this.empty, this );
</del><ins>+                this.on( 'activate:empty', this.empty, this );
</ins><span class="cx">                 this.mode('empty');
</span><span class="cx">         };
</span><span class="cx">
</span><span class="lines">@@ -66,14 +66,26 @@
</span><span class="cx">         media.controller.Region.extend = Backbone.Model.extend;
</span><span class="cx">
</span><span class="cx">         _.extend( media.controller.Region.prototype, Backbone.Events, {
</span><del>-                trigger: function( id ) {
-                        this._mode = id;
-                        return Backbone.Events.trigger.apply( this, arguments );
-                },
</del><ins>+                trigger: (function() {
+                        var eventSplitter = /\s+/,
+                                trigger = Backbone.Events.trigger;
</ins><span class="cx">
</span><ins>+                        return function( events ) {
+                                var mode = ':' + this._mode,
+                                        modeEvents = events.split( eventSplitter ).join( mode ) + mode;
+
+                                trigger.apply( this, arguments );
+                                trigger.apply( this, [ modeEvents ].concat( _.rest( arguments ) ) );
+                                return this;
+                        };
+                }()),
+
</ins><span class="cx">                 mode: function( mode ) {
</span><del>-                        if ( mode )
-                                return this.trigger( mode );
</del><ins>+                        if ( mode ) {
+                                this.trigger('deactivate');
+                                this._mode = mode;
+                                return this.trigger('activate');
+                        }
</ins><span class="cx">                         return this._mode;
</span><span class="cx">                 },
</span><span class="cx">
</span><span class="lines">@@ -270,6 +282,9 @@
</span><span class="cx">                         if ( ! this.get('gutter') )
</span><span class="cx">                                 this.set( 'gutter', 8 );
</span><span class="cx">
</span><ins>+                        if ( ! this.get('details') )
+                                this.set( 'details', [] );
+
</ins><span class="cx">                         media.controller.State.prototype.initialize.apply( this, arguments );
</span><span class="cx">                 },
</span><span class="cx">
</span><span class="lines">@@ -281,8 +296,7 @@
</span><span class="cx">                         if ( this.get('multiple') )
</span><span class="cx">                                 wp.Uploader.queue.on( 'add', this.selectUpload, this );
</span><span class="cx">
</span><del>-                        selection.on( 'selection:single', this.buildDetails, this );
-                        selection.on( 'selection:unsingle', this.clearDetails, this );
</del><ins>+                        selection.on( 'selection:single selection:unsingle', this.sidebar, this );
</ins><span class="cx">                         selection.on( 'add remove reset', this.refreshToolbar, this );
</span><span class="cx">
</span><span class="cx">                         this._updateEmpty();
</span><span class="lines">@@ -306,8 +320,12 @@
</span><span class="cx">                 },
</span><span class="cx">
</span><span class="cx">                 sidebar: function() {
</span><del>-                        media.controller.State.prototype.sidebar.apply( this, arguments );
-                        this.details();
</del><ins>+                        var sidebar = this.frame.sidebar;
+
+                        if ( this.get('selection').single() )
+                                sidebar.mode( this.get('sidebar') );
+                        else
+                                sidebar.mode('clear');
</ins><span class="cx">                 },
</span><span class="cx">
</span><span class="cx">                 content: function() {
</span><span class="lines">@@ -344,31 +362,6 @@
</span><span class="cx">                         this.get('selection').add( attachment );
</span><span class="cx">                 },
</span><span class="cx">
</span><del>-                details: function() {
-                        var single = this.get('selection').single();
-                        this[ single ? 'buildDetails' : 'clearDetails' ]( single );
-                },
-
-                buildDetails: function( model ) {
-                        var frame = this.frame;
-                        frame.sidebar.view().add( 'details', new media.view.Attachment.Details({
-                                controller: frame,
-                                model: model,
-                                priority: 80
-                        }).render() );
-                        return this;
-                },
-
-                clearDetails: function( model ) {
-                        if ( this.get('selection').single() )
-                                return this;
-
-                        this.frame.sidebar.view().add( 'details', new Backbone.View({
-                                priority: 80
-                        }).render() );
-                        return this;
-                },
-
</del><span class="cx">                 toggleSelection: function( model ) {
</span><span class="cx">                         var selection = this.get('selection');
</span><span class="cx">
</span><span class="lines">@@ -436,18 +429,9 @@
</span><span class="cx">                 },
</span><span class="cx">
</span><span class="cx">                 sidebar: function() {
</span><del>-                        var frame = this.frame;
-
-                        media.controller.State.prototype.sidebar.apply( this, arguments );
-                        this.details();
-
-                        frame.sidebar.view().add({
-                                settings: new media.view.Settings.Gallery({
-                                        controller: frame,
-                                        model: this.get('library').props,
-                                        priority: 40
-                                }).render()
-                        });
</del><ins>+                        media.controller.Library.prototype.sidebar.apply( this, arguments );
+                        this.frame.sidebar.trigger('gallery-settings');
+                        return this;
</ins><span class="cx">                 }
</span><span class="cx">         });
</span><span class="cx">
</span><span class="lines">@@ -590,23 +574,42 @@
</span><span class="cx">                 },
</span><span class="cx">
</span><span class="cx">                 bindHandlers: function() {
</span><del>-                        this.menu.on( 'main', this.mainMenu, this );
-                        this.menu.on( 'batch', this.batchMenu, this );
-                        this.menu.on( 'gallery', this.galleryMenu, this );
</del><ins>+                        var handlers = {
+                                        menu: {
+                                                main: 'mainMenu',
+                                                batch: 'batchMenu',
+                                                gallery: 'galleryMenu'
+                                        },
</ins><span class="cx">
</span><del>-                        this.content.on( 'browse', this.browseContent, this );
-                        this.content.on( 'upload', this.uploadContent, this );
-                        this.content.on( 'embed', this.embedContent, this );
</del><ins>+                                        content: {
+                                                browse: 'browseContent',
+                                                upload: 'uploadContent',
+                                                embed: 'embedContent'
+                                        },
</ins><span class="cx">
</span><del>-                        this.sidebar.on( 'settings', this.settingsSidebar, this );
-                        this.sidebar.on( 'attachment-settings', this.attachmentSettingsSidebar, this );
</del><ins>+                                        sidebar: {
+                                                'clear': 'clearSidebar',
+                                                'settings': 'settingsSidebar',
+                                                'attachment-settings': 'attachmentSettingsSidebar'
+                                        },
</ins><span class="cx">
</span><del>-                        this.toolbar.on( 'main-attachments', this.mainAttachmentsToolbar, this );
-                        this.toolbar.on( 'main-embed', this.mainEmbedToolbar, this );
-                        this.toolbar.on( 'batch-edit', this.batchEditToolbar, this );
-                        this.toolbar.on( 'batch-add', this.batchAddToolbar, this );
-                        this.toolbar.on( 'gallery-edit', this.galleryEditToolbar, this );
-                        this.toolbar.on( 'gallery-add', this.galleryAddToolbar, this );
</del><ins>+                                        toolbar: {
+                                                'main-attachments': 'mainAttachmentsToolbar',
+                                                'main-embed': 'mainEmbedToolbar',
+                                                'batch-edit': 'batchEditToolbar',
+                                                'batch-add': 'batchAddToolbar',
+                                                'gallery-edit': 'galleryEditToolbar',
+                                                'gallery-add': 'galleryAddToolbar'
+                                        }
+                                };
+
+                        _.each( handlers, function( regionHandlers, region ) {
+                                _.each( regionHandlers, function( callback, handler ) {
+                                        this[ region ].on( 'activate:' + handler, this[ callback ], this );
+                                }, this );
+                        }, this );
+
+                        this.sidebar.on( 'gallery-settings', this.onSidebarGallerySettings, this );
</ins><span class="cx">                 },
</span><span class="cx">
</span><span class="cx">                 createSelection: function() {
</span><span class="lines">@@ -621,43 +624,47 @@
</span><span class="cx">                 },
</span><span class="cx">
</span><span class="cx">                 createStates: function() {
</span><del>-                        var options = this.options;
</del><ins>+                        var options = this.options,
+                                main, gallery;
</ins><span class="cx">
</span><ins>+                        main = {
+                                multiple: this.options.multiple,
+                                menu: 'main',
+                                sidebar: 'attachment-settings',
+
+                                // Update user settings when users adjust the
+                                // attachment display settings.
+                                displayUserSettings: true
+                        };
+
+                        gallery = {
+                                multiple: true,
+                                menu: 'gallery',
+                                toolbar: 'gallery-add'
+                        };
+
</ins><span class="cx">                         // Add the default states.
</span><span class="cx">                         this.states.add([
</span><del>-                                new media.controller.Library({
</del><ins>+                                new media.controller.Library( _.defaults({
</ins><span class="cx">                                         selection: options.selection,
</span><del>-                                        library: media.query( options.library ),
-                                        multiple: this.options.multiple,
-                                        menu: 'main',
-                                        sidebar: 'attachment-settings'
-                                }),
</del><ins>+                                        library: media.query( options.library )
+                                }, main ) ),
</ins><span class="cx">
</span><del>-                                new media.controller.Upload({
-                                        multiple: this.options.multiple,
-                                        menu: 'main',
-                                        sidebar: 'attachment-settings'
-                                }),
</del><ins>+                                new media.controller.Upload( main ),
</ins><span class="cx">
</span><span class="cx">                                 new media.controller.Gallery({
</span><span class="cx">                                         editing: options.editing,
</span><span class="cx">                                         menu: 'gallery'
</span><span class="cx">                                 }),
</span><span class="cx">
</span><del>-                                new media.controller.Library({
-                                        id: 'gallery-library',
-                                        library: media.query({ type: 'image' }),
-                                        multiple: true,
-                                        menu: 'gallery',
-                                        toolbar: 'gallery-add'
-                                }),
</del><ins>+                                new media.controller.Library( _.defaults({
+                                        id: 'gallery-library',
+                                        library: media.query({ type: 'image' })
+                                }, gallery ) ),
</ins><span class="cx">
</span><del>-                                new media.controller.Upload({
-                                        id: 'gallery-upload',
-                                        multiple: true,
-                                        menu: 'gallery',
-                                        toolbar: 'gallery-add'
-                                })
</del><ins>+                                new media.controller.Upload( _.defaults({
+                                        id: 'gallery-upload'
+                                }, gallery ) )
</ins><span class="cx">                         ]);
</span><span class="cx">
</span><span class="cx">                         this.get('gallery-edit').on( 'change:library', this.updateGalleryLibraries, this ).set({
</span><span class="lines">@@ -813,24 +820,60 @@
</span><span class="cx">                 embedContent: function() {},
</span><span class="cx">
</span><span class="cx">                 // Sidebars
</span><del>-                settingsSidebar: function() {
</del><ins>+                clearSidebar: function() {
</ins><span class="cx">                         this.sidebar.view( new media.view.Sidebar({
</span><span class="cx">                                 controller: this
</span><span class="cx">                         }) );
</span><span class="cx">                 },
</span><span class="cx">
</span><del>-                attachmentSettingsSidebar: function() {
</del><ins>+                settingsSidebar: function( options ) {
</ins><span class="cx">                         this.sidebar.view( new media.view.Sidebar({
</span><span class="cx">                                 controller: this,
</span><ins>+                                silent: options && options.silent,
+
</ins><span class="cx">                                 views: {
</span><del>-                                        settings: new media.view.Settings.AttachmentDisplay({
</del><ins>+                                        details: new media.view.Attachment.Details({
</ins><span class="cx">                                                 controller: this,
</span><del>-                                                priority: 20
</del><ins>+                                                model: this.state().get('selection').single(),
+                                                priority: 80
</ins><span class="cx">                                         }).render()
</span><span class="cx">                                 }
</span><span class="cx">                         }) );
</span><span class="cx">                 },
</span><span class="cx">
</span><ins>+                onSidebarGallerySettings: function( options ) {
+                        this.sidebar.view().add({
+                                gallery: new media.view.Settings.Gallery({
+                                        controller: this,
+                                        model: this.state().get('library').props,
+                                        priority: 40
+                                }).render()
+                        }, options );
+                },
+
+                attachmentSettingsSidebar: function( options ) {
+                        var state = this.state(),
+                                display = state.get('details'),
+                                single = state.get('selection').single().cid;
+
+                        this.settingsSidebar({ silent: true });
+
+                        display[ single ] = display[ single ] || new Backbone.Model({
+                                align: getUserSetting( 'align', 'none' ),
+                                size: getUserSetting( 'imgsize', 'medium' ),
+                                link: getUserSetting( 'urlbutton', 'post' )
+                        });
+
+                        this.sidebar.view().add({
+                                display: new media.view.Settings.AttachmentDisplay({
+                                        controller: this,
+                                        model: display[ single ],
+                                        priority: 100,
+                                        userSettings: state.get('displayUserSettings')
+                                }).render()
+                        }, options );
+                },
+
</ins><span class="cx">                 // Toolbars
</span><span class="cx">                 mainAttachmentsToolbar: function() {
</span><span class="cx">                         this.toolbar.view( new media.view.Toolbar.Insert.Post({
</span><span class="lines">@@ -2125,44 +2168,15 @@
</span><span class="cx">                         'change textarea': 'updateHandler'
</span><span class="cx">                 },
</span><span class="cx">
</span><del>-                settings: {},
-
</del><span class="cx">                 initialize: function() {
</span><del>-                        var settings = this.settings;
-
</del><span class="cx">                         this.model = this.model || new Backbone.Model();
</span><del>-
-                        _.each( settings, function( setting, key ) {
-                                if ( setting.name )
-                                        this.model.set( key, getUserSetting( setting.name, setting.fallback ) );
-                                else
-                                        this.model.set( key, this.model.get( key ) || setting.fallback );
-                        }, this );
-
-                        this.model.validate = function( attrs ) {
-                                return _.any( attrs, function( value, key ) {
-                                        // If we don't have a `setting` for the `key`, assume the
-                                        // `value` is valid. Otherwise, check if the `value` exists
-                                        // in the `setting.accepts` array.
-                                        return settings[ key ] && ! _.contains( settings[ key ].accepts, value );
-                                });
-                        };
-
-                        this.model.on( 'change', function( model, options ) {
-                                if ( ! options.changes )
-                                        return;
-
-                                _.each( _.keys( options.changes ), function( key ) {
-                                        if ( settings[ key ] && settings[ key ].name )
-                                                setUserSetting( settings[ key ].name, model.get( key ) );
-                                });
-                        }, this );
-
</del><span class="cx">                         this.model.on( 'change', this.updateChanges, this );
</span><span class="cx">                 },
</span><span class="cx">
</span><span class="cx">                 render: function() {
</span><del>-                        this.$el.html( this.template( this.model.toJSON() ) );
</del><ins>+                        this.$el.html( this.template( _.defaults({
+                                model: this.model.toJSON()
+                        }, this.options ) ) );
</ins><span class="cx">
</span><span class="cx">                         // Select the correct values.
</span><span class="cx">                         _( this.model.attributes ).chain().keys().each( this.update, this );
</span><span class="lines">@@ -2170,28 +2184,44 @@
</span><span class="cx">                 },
</span><span class="cx">
</span><span class="cx">                 update: function( key ) {
</span><del>-                        var setting = this.settings[ key ],
</del><ins>+                        var value = this.model.get( key ),
</ins><span class="cx">                                 $setting = this.$('[data-setting="' + key + '"]'),
</span><span class="cx">                                 $buttons;
</span><span class="cx">
</span><del>-                        if ( ! setting )
</del><ins>+                        // Bail if we didn't find a matching setting.
+                        if ( ! $setting.length )
</ins><span class="cx">                                 return;
</span><span class="cx">
</span><del>-                        if ( 'select' === setting.type ) {
-                                $setting.find('[value="' + this.model.get( key ) + '"]').attr( 'selected', true );
-                        } else {
</del><ins>+                        // Attempt to determine how the setting is rendered and update
+                        // the selected value.
+
+                        // Handle dropdowns.
+                        if ( $setting.is('select') ) {
+                                $setting.find('[value="' + value + '"]').attr( 'selected', true );
+
+                        // Handle button groups.
+                        } else if ( $setting.hasClass('button-group') ) {
</ins><span class="cx">                                 $buttons = $setting.find('button').removeClass('active');
</span><del>-                                $buttons.filter( '[value="' + this.model.get( key ) + '"]' ).addClass('active');
</del><ins>+                                $buttons.filter( '[value="' + value + '"]' ).addClass('active');
</ins><span class="cx">                         }
</span><span class="cx">                 },
</span><span class="cx">
</span><span class="cx">                 updateHandler: function( event ) {
</span><del>-                        var $setting = $( event.target ).closest('[data-setting]');
</del><ins>+                        var $setting = $( event.target ).closest('[data-setting]'),
+                                value = event.target.value,
+                                userSetting;
</ins><span class="cx">
</span><span class="cx">                         event.preventDefault();
</span><span class="cx">
</span><del>-                        if ( $setting.length )
-                                this.model.set( $setting.data('setting'), event.target.value );
</del><ins>+                        if ( ! $setting.length )
+                                return;
+
+                        this.model.set( $setting.data('setting'), value );
+
+                        // If the setting has a corresponding user setting,
+                        // update that as well.
+                        if ( userSetting = $setting.data('userSetting') )
+                                setUserSetting( userSetting, value );
</ins><span class="cx">                 },
</span><span class="cx">
</span><span class="cx">                 updateChanges: function( model, options ) {
</span><span class="lines">@@ -2207,23 +2237,11 @@
</span><span class="cx">                 className: 'attachment-display-settings',
</span><span class="cx">                 template: media.template('attachment-display-settings'),
</span><span class="cx">
</span><del>-                settings: {
-                        align: {
-                                accepts: ['left','center','right','none'],
-                                name: 'align',
-                                fallback: 'none'
-                        },
-                        link: {
-                                accepts: ['post','file','none'],
-                                name: 'urlbutton',
-                                fallback: 'post'
-                        },
-                        size: {
-                                // @todo: Dynamically generate these.
-                                accepts: ['thumbnail','medium','large','full'],
-                                name: 'imgsize',
-                                fallback: 'medium'
-                        }
</del><ins>+                initialize: function() {
+                        _.defaults( this.options, {
+                                userSettings: false
+                        });
+                        media.view.Settings.prototype.initialize.apply( this, arguments );
</ins><span class="cx">                 }
</span><span class="cx">         });
</span><span class="cx">
</span><span class="lines">@@ -2232,19 +2250,7 @@
</span><span class="cx">          */
</span><span class="cx">         media.view.Settings.Gallery = media.view.Settings.extend({
</span><span class="cx">                 className: 'gallery-settings',
</span><del>-                template: media.template('gallery-settings'),
-
-                settings: {
-                        columns: {
-                                accepts: _.invoke( _.range( 1, 10 ), 'toString' ),
-                                fallback: '3',
-                                type: 'select'
-                        },
-                        link: {
-                                accepts: ['post','file'],
-                                fallback: 'post'
-                        }
-                }
</del><ins>+                template: media.template('gallery-settings')
</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 (22465 => 22466)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/media.php        2012-11-08 13:52:40 UTC (rev 22465)
+++ trunk/wp-includes/media.php        2012-11-08 14:15:09 UTC (rev 22466)
</span><span class="lines">@@ -1417,7 +1417,12 @@
</span><span class="cx">                 <h3><?php _e('Attachment Display Settings'); ?></h3>
</span><span class="cx">
</span><span class="cx">                 <h4><?php _e('Alignment'); ?></h4>
</span><del>-                <div class="alignment button-group button-large" data-setting="align">
</del><ins>+                <div class="alignment button-group button-large"
+                        data-setting="align"
+                        <# if ( userSettings ) { #>
+                                data-user-setting="align"
+                        <# } #>>
+
</ins><span class="cx">                         <button class="button" value="left">
</span><span class="cx">                                 <?php esc_attr_e('Left'); ?>
</span><span class="cx">                         </button>
</span><span class="lines">@@ -1427,14 +1432,19 @@
</span><span class="cx">                         <button class="button" value="right">
</span><span class="cx">                                 <?php esc_attr_e('Right'); ?>
</span><span class="cx">                         </button>
</span><del>-                        <button class="button" value="none">
</del><ins>+                        <button class="button active" value="none">
</ins><span class="cx">                                 <?php esc_attr_e('None'); ?>
</span><span class="cx">                         </button>
</span><span class="cx">                 </div>
</span><span class="cx">
</span><span class="cx">                 <h4><?php _e('Link To'); ?></h4>
</span><del>-                <div class="link-to button-group button-large" data-setting="link">
-                        <button class="button" value="post">
</del><ins>+                <div class="link-to button-group button-large"
+                        data-setting="link"
+                        <# if ( userSettings ) { #>
+                                data-user-setting="urlbutton"
+                        <# } #>>
+
+                        <button class="button active" value="post">
</ins><span class="cx">                                 <?php esc_attr_e('Attachment Page'); ?>
</span><span class="cx">                         </button>
</span><span class="cx">                         <button class="button" value="file">
</span><span class="lines">@@ -1450,8 +1460,10 @@
</span><span class="cx">                 <h3><?php _e('Gallery Settings'); ?></h3>
</span><span class="cx">
</span><span class="cx">                 <h4><?php _e('Link To'); ?></h4>
</span><del>-                <div class="link-to button-group" data-setting="link">
-                        <button class="button" value="post">
</del><ins>+                <div class="link-to button-group"
+                        data-setting="link">
+
+                        <button class="button active" value="post">
</ins><span class="cx">                                 <?php esc_attr_e('Attachment Page'); ?>
</span><span class="cx">                         </button>
</span><span class="cx">                         <button class="button" value="file">
</span><span class="lines">@@ -1461,9 +1473,10 @@
</span><span class="cx">
</span><span class="cx">                 <h4><?php _e('Gallery Columns'); ?></h4>
</span><span class="cx">
</span><del>-                <select class="columns" name="columns" data-setting="columns">
</del><ins>+                <select class="columns" name="columns"
+                        data-setting="columns">
</ins><span class="cx">                         <?php for ( $i = 1; $i <= 9; $i++ ) : ?>
</span><del>-                                <option value="<?php echo esc_attr( $i ); ?>">
</del><ins>+                                <option value="<?php echo esc_attr( $i ); ?>" <?php selected( $i, 3 ); ?>>
</ins><span class="cx">                                         <?php echo esc_html( $i ); ?>
</span><span class="cx">                                 </option>
</span><span class="cx">                         <?php endfor; ?>
</span></span></pre>
</div>
</div>
</body>
</html>