<!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>[22247] trunk/wp-includes: Add attachment display settings to 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/22247">22247</a></dd>
<dt>Author</dt> <dd>koopersmith</dd>
<dt>Date</dt> <dd>2012-10-16 19:25:17 +0000 (Tue, 16 Oct 2012)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add attachment display settings to the media modal.
* Add a media view for button groups.
* Add button dropdown containers.
* Add a dropdown property to the button media model.
fixes <a href="http://core.trac.wordpress.org/ticket/22206">#22206</a>, <a href="http://core.trac.wordpress.org/ticket/21814">#21814</a>, see <a href="http://core.trac.wordpress.org/ticket/21390">#21390</a>, <a href="http://core.trac.wordpress.org/ticket/21813">#21813</a>, <a href="http://core.trac.wordpress.org/ticket/21598">#21598</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludescssbuttonscss">trunk/wp-includes/css/buttons.css</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="trunkwpincludescssbuttonscss"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/css/buttons.css (22246 => 22247)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/css/buttons.css        2012-10-16 18:16:29 UTC (rev 22246)
+++ trunk/wp-includes/css/buttons.css        2012-10-16 19:25:17 UTC (rev 22247)
</span><span class="lines">@@ -229,6 +229,7 @@
</span><span class="cx"> ---------------------------------------------------------------------------- */
</span><span class="cx">
</span><span class="cx"> .button-group {
</span><ins>+        position: relative;
</ins><span class="cx">         display: inline-block;
</span><span class="cx">         white-space: nowrap;
</span><span class="cx">         font-size: 0;
</span><span class="lines">@@ -236,7 +237,6 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> .button-group > .button {
</span><del>-        position: relative;
</del><span class="cx">         display: inline-block;
</span><span class="cx">         border-radius: 0;
</span><span class="cx">         margin-right: -1px;
</span><span class="lines">@@ -269,8 +269,34 @@
</span><span class="cx">         content: '\25BE';
</span><span class="cx">         display: inline-block;
</span><span class="cx">         font-size: 16px;
</span><del>-        opacity: 0.8;
</del><ins>+        opacity: 0.9;
</ins><span class="cx">         margin: 0 -0.25em;
</span><span class="cx">         text-align: center;
</span><span class="cx">         vertical-align: middle;
</span><span class="cx"> }
</span><ins>+
+.button .dropdown {
+        display: none;
+        position: absolute;
+        top: 100%;
+        left: 0;
+        margin-top: 5px;
+        padding: 0.8em 1em;
+        border-radius: 3px;
+
+        background: #f5f5f5;
+        color: #333;
+        text-shadow: none;
+        box-shadow:
+                0 0 0 1px rgba( 0, 0, 0, 0.3 ),
+                1px 1px 2px rgba( 0, 0, 0, 0.1 );
+}
+
+.button.active .dropdown {
+        display: block;
+}
+
+.dropdown-flip-x .dropdown {
+        left: auto;
+        right: 0;
+}
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkwpincludescssmediaviewscss"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/css/media-views.css (22246 => 22247)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/css/media-views.css        2012-10-16 18:16:29 UTC (rev 22246)
+++ trunk/wp-includes/css/media-views.css        2012-10-16 19:25:17 UTC (rev 22247)
</span><span class="lines">@@ -86,17 +86,18 @@
</span><span class="cx">         float: left;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-.media-toolbar .media-button {
</del><ins>+.media-toolbar-primary > .media-button,
+.media-toolbar-primary > .media-button-group {
+        margin-left: 10px;
</ins><span class="cx">         float: left;
</span><span class="cx">         margin-top: 16px;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-.media-toolbar-primary .media-button {
-        margin-left: 10px;
-}
-
-.media-toolbar-secondary .media-button {
</del><ins>+.media-toolbar-secondary > .media-button,
+.media-toolbar-secondary > .media-button-group {
</ins><span class="cx">         margin-right: 10px;
</span><ins>+        float: left;
+        margin-top: 16px;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -515,4 +516,22 @@
</span><span class="cx"> .selection-preview .clear-selection {
</span><span class="cx">         float: left;
</span><span class="cx">         line-height: 60px;
</span><ins>+}
+
+/**
+ * Attachment Display Settings
+ */
+
+.attachment-display-settings,
+.button div.attachment-display-settings {
+        padding: 0 1em 1em;
+}
+
+.attachment-display-settings h3 {
+        font-weight: 200;
+        margin: 1.4em 0 0.4em;
+}
+
+.attachment-display-settings h4 {
+        margin: 1.4em 0 0.4em;
</ins><span class="cx"> }
</span><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkwpincludesjsmediaviewsjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/media-views.js (22246 => 22247)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/media-views.js        2012-10-16 18:16:29 UTC (rev 22246)
+++ trunk/wp-includes/js/media-views.js        2012-10-16 19:25:17 UTC (rev 22247)
</span><span class="lines">@@ -350,6 +350,9 @@
</span><span class="cx">                                 delete this.options[ key ];
</span><span class="cx">                         }, this );
</span><span class="cx">
</span><ins>+                        if ( this.options.dropdown )
+                                this.options.dropdown.addClass('dropdown');
+
</ins><span class="cx">                         this.model.on( 'change', this.render, this );
</span><span class="cx">                 },
</span><span class="cx">
</span><span class="lines">@@ -362,10 +365,19 @@
</span><span class="cx">                         if ( this.model.get('size') )
</span><span class="cx">                                 classes.push( 'button-' + this.model.get('size') );
</span><span class="cx">
</span><del>-                        classes = classes.concat( this.options.classes );
</del><ins>+                        classes = _.uniq( classes.concat( this.options.classes ) );
</ins><span class="cx">                         this.el.className = classes.join(' ');
</span><span class="cx">
</span><ins>+
+                        // Detach the dropdown.
+                        if ( this.options.dropdown )
+                                this.options.dropdown.detach();
+
</ins><span class="cx">                         this.$el.text( this.model.get('text') );
</span><ins>+
+                        if ( this.options.dropdown )
+                                this.$el.append( this.options.dropdown );
+
</ins><span class="cx">                         return this;
</span><span class="cx">                 },
</span><span class="cx">
</span><span class="lines">@@ -377,6 +389,33 @@
</span><span class="cx">         });
</span><span class="cx">
</span><span class="cx">         /**
</span><ins>+         * wp.media.view.ButtonGroup
+         */
+        media.view.ButtonGroup = Backbone.View.extend({
+                tagName: 'div',
+                className: 'button-group button-large media-button-group',
+
+                initialize: function() {
+                        this.buttons = _.map( this.options.buttons || [], function( button ) {
+                                if ( button instanceof Backbone.View )
+                                        return button;
+                                else
+                                        return new media.view.Button( button ).render();
+                        });
+
+                        delete this.options.buttons;
+
+                        if ( this.options.classes )
+                                this.$el.addClass( this.options.classes );
+                },
+
+                render: function() {
+                        this.$el.html( $( _.pluck( this.buttons, 'el' ) ).detach() );
+                        return this;
+                }
+        });
+
+        /**
</ins><span class="cx">          * wp.media.view.Attachment
</span><span class="cx">          */
</span><span class="cx">         media.view.Attachment = Backbone.View.extend({
</span><span class="lines">@@ -710,12 +749,39 @@
</span><span class="cx">                                                 }
</span><span class="cx">                                         },
</span><span class="cx">
</span><del>-                                        'insert-into-post': {
-                                                text: l10n.insertIntoPost,
</del><ins>+                                        'insert-into-post': new media.view.ButtonGroup({
</ins><span class="cx">                                                 priority: 30,
</span><del>-                                                click: _.bind( controller.update, controller, 'insert' )
-                                        },
</del><ins>+                                                classes: 'dropdown-flip-x',
+                                                buttons: [
+                                                        {
+                                                                text: l10n.insertIntoPost,
+                                                                click: _.bind( controller.update, controller, 'insert' )
+                                                        },
+                                                        {
+                                                                classes: ['down-arrow'],
+                                                                dropdown: new media.view.AttachmentDisplaySettings().render().$el,
</ins><span class="cx">
</span><ins>+                                                                click: function( event ) {
+                                                                        var $el = this.$el;
+
+                                                                        if ( ! $( event.target ).closest('.dropdown').length )
+                                                                                $el.toggleClass('active');
+
+                                                                        // Stop the event from propagating further so we can bind
+                                                                        // a one-time event to the body (and ensure that a click
+                                                                        // on the dropdown won't trigger said event).
+                                                                        event.stopPropagation();
+
+                                                                        if ( $el.is(':visible') ) {
+                                                                                $(document.body).one( 'click', function() {
+                                                                                        $el.removeClass('active');
+                                                                                });
+                                                                        }
+                                                                }
+                                                        }
+                                                ]
+                                        }).render(),
+
</ins><span class="cx">                                         'add-to-gallery': {
</span><span class="cx">                                                 text: l10n.addToGallery,
</span><span class="cx">                                                 priority: 20
</span><span class="lines">@@ -736,7 +802,9 @@
</span><span class="cx">
</span><span class="cx">                                 this.toolbarView.get('create-new-gallery').$el.toggle( showGallery );
</span><span class="cx">                                 insert = this.toolbarView.get('insert-into-post');
</span><del>-                                insert.model.set( 'style', showGallery ? '' : 'primary' );
</del><ins>+                                _.each( insert.buttons, function( button ) {
+                                        button.model.set( 'style', showGallery ? '' : 'primary' );
+                                });
</ins><span class="cx">                         }, this );
</span><span class="cx">
</span><span class="cx">                         this.$content.append( this.toolbarView.$el );
</span><span class="lines">@@ -1034,4 +1102,92 @@
</span><span class="cx">                         this.collection.clear();
</span><span class="cx">                 }
</span><span class="cx">         });
</span><ins>+
+
+        /**
+         * wp.media.view.AttachmentDisplaySettings
+         */
+        media.view.AttachmentDisplaySettings = Backbone.View.extend({
+                tagName: 'div',
+                className: 'attachment-display-settings',
+                template: media.template('attachment-display-settings'),
+
+                events: {
+                        'click button': 'updateHandler'
+                },
+
+                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'
+                        }
+                },
+
+                initialize: function() {
+                        var settings = this.settings;
+
+                        this.model = new Backbone.Model();
+
+                        _.each( settings, function( setting, key ) {
+                                this.model.set( key, getUserSetting( setting.name, setting.fallback ) );
+                        }, this );
+
+                        this.model.validate = function( attrs ) {
+                                return _.any( attrs, function( value, key ) {
+                                        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 ] )
+                                                setUserSetting( settings[ key ].name, model.get( key ) );
+                                });
+                        }, this );
+
+                        this.model.on( 'change', this.updateChanges, this );
+                },
+
+                render: function() {
+                        this.$el.html( this.template( this.model.toJSON() ) );
+
+                        // Select the correct values.
+                        _( this.model.attributes ).chain().keys().each( this.update, this );
+                        return this;
+                },
+
+                update: function( key ) {
+                        var buttons = this.$('[data-setting="' + key + '"] button').removeClass('active');
+                        buttons.filter( '[value="' + this.model.get( key ) + '"]' ).addClass('active');
+                },
+
+                updateHandler: function( event ) {
+                        var group = $( event.target ).closest('.button-group');
+
+                        event.preventDefault();
+
+                        if ( group.length )
+                                this.model.set( group.data('setting'), event.target.value );
+                },
+
+                updateChanges: function( model, options ) {
+                        if ( options.changes )
+                                _( options.changes ).chain().keys().each( this.update, this );
+                }
+        });
</ins><span class="cx"> }(jQuery));
</span><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkwpincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/media.php (22246 => 22247)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/media.php        2012-10-16 18:16:29 UTC (rev 22246)
+++ trunk/wp-includes/media.php        2012-10-16 19:25:17 UTC (rev 22247)
</span><span class="lines">@@ -1377,6 +1377,37 @@
</span><span class="cx">                 <% } %>
</span><span class="cx">         </script>
</span><span class="cx">
</span><ins>+        <script type="text/html" id="tmpl-attachment-display-settings">
+                <h4><?php _e('Alignment'); ?></h4>
+                <div class="alignment button-group button-large" data-setting="align">
+                        <button class="button" value="left">
+                                <?php esc_attr_e('Left'); ?>
+                        </button>
+                        <button class="button" value="center">
+                                <?php esc_attr_e('Center'); ?>
+                        </button>
+                        <button class="button" value="right">
+                                <?php esc_attr_e('Right'); ?>
+                        </button>
+                        <button class="button" value="none">
+                                <?php esc_attr_e('None'); ?>
+                        </button>
+                </div>
+
+                <h4><?php _e('Link To'); ?></h4>
+                <div class="link-to button-group button-large" data-setting="link">
+                        <button class="button" value="post">
+                                <?php esc_attr_e('Attachment Page'); ?>
+                        </button>
+                        <button class="button" value="file">
+                                <?php esc_attr_e('Media File'); ?>
+                        </button>
+                        <button class="button" value="none">
+                                <?php esc_attr_e('None'); ?>
+                        </button>
+                </div>
+        </script>
+
</ins><span class="cx">         <script type="text/html" id="tmpl-editor-attachment">
</span><span class="cx">                 <div class="editor-attachment-preview">
</span><span class="cx">                         <% if ( url ) { %>
</span></span></pre>
</div>
</div>
</body>
</html>