<!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>[21769] trunk/wp-includes: Adds UI for media modal toolbars, buttons, and the selected item(s) status.</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/21769">21769</a></dd>
<dt>Author</dt> <dd>koopersmith</dd>
<dt>Date</dt> <dd>2012-09-06 07:46:15 +0000 (Thu, 06 Sep 2012)</dd>
</dl>
<h3>Log Message</h3>
<pre>Adds UI for media modal toolbars, buttons, and the selected item(s) status.
Currently uses actions for inserting media into a post as an example (hence the raw text). To test a workflow that supports multiple selection, run the following in your browser's JavaScript console:
        wp.media({ multiple: true });
see <a href="http://core.trac.wordpress.org/ticket/21390">#21390</a>, <a href="http://core.trac.wordpress.org/ticket/21808">#21808</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<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="trunkwpincludescssmediaviewscss"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/css/media-views.css (21768 => 21769)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/css/media-views.css        2012-09-05 20:33:34 UTC (rev 21768)
+++ trunk/wp-includes/css/media-views.css        2012-09-06 07:46:15 UTC (rev 21769)
</span><span class="lines">@@ -54,6 +54,37 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><ins>+ * Toolbar
+ */
+.media-toolbar {
+        position: relative;
+        z-index: 50;
+        height: 60px;
+        border-bottom: 1px solid #dfdfdf;
+}
+
+.media-toolbar-primary {
+        float: right;
+}
+
+.media-toolbar-secondary {
+        float: left;
+}
+
+.media-toolbar .media-button {
+        float: left;
+        margin-top: 19px;
+}
+
+.media-toolbar-primary .media-button {
+        margin-left: 10px;
+}
+
+.media-toolbar-secondary .media-button {
+        margin-right: 10px;
+}
+
+/**
</ins><span class="cx"> * Workspace
</span><span class="cx"> */
</span><span class="cx"> .media-workspace {
</span><span class="lines">@@ -98,6 +129,7 @@
</span><span class="cx">         width: auto;
</span><span class="cx">         right: 0;
</span><span class="cx">         border-color: #83B4D8;
</span><ins>+        box-shadow: 0 0 0 10px #fff;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> .existing-attachments {
</span><span class="lines">@@ -106,12 +138,56 @@
</span><span class="cx">         left: 200px;
</span><span class="cx">         right: 0;
</span><span class="cx">         bottom: 0;
</span><ins>+        margin: 0 20px;
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+.media-workspace .attachments,
+.media-workspace .media-toolbar {
+        -webkit-transition-property: left, right, top, bottom, margin;
+        -moz-transition-property: left, right, top, bottom, margin;
+        -ms-transition-property: left, right, top, bottom, margin;
+        -o-transition-property: left, right, top, bottom, margin;
+        transition-property: left, right, top, bottom, margin;
+
+        -webkit-transition-duration: 0.2s;
+        -moz-transition-duration: 0.2s;
+        -ms-transition-duration: 0.2s;
+        -o-transition-duration: 0.2s;
+        transition-duration: 0.2s;
+}
+
+.media-workspace .attachments {
+        position: absolute;
+        top: 0;
+        left: 0;
+        right: 0;
+        bottom: 0;
+        height: auto;
+        width: auto;
+}
+
+.media-workspace.with-toolbar .attachments {
+        top: 61px;
+}
+
+.media-workspace .media-toolbar {
+        margin-top: -61px;
+}
+
+.media-workspace.with-toolbar .media-toolbar {
+        margin-top: 0;
+}
+
+.media-workspace .media-toolbar .add-to-gallery,
+.media-workspace .media-toolbar .create-new-gallery {
+        display: none;
+}
+
</ins><span class="cx"> /**
</span><span class="cx"> * Attachments
</span><span class="cx"> */
</span><span class="cx"> .attachments {
</span><ins>+        position: relative;
</ins><span class="cx">         width: 100%;
</span><span class="cx">         height: 100%;
</span><span class="cx"> }
</span><span class="lines">@@ -128,15 +204,15 @@
</span><span class="cx"> .attachments-header h3 {
</span><span class="cx">         float: left;
</span><span class="cx">         margin: 0;
</span><del>-        padding: 0 0 0 10px;
</del><ins>+        padding: 0;
</ins><span class="cx">         line-height: 50px;
</span><span class="cx">         font-size: 18px;
</span><span class="cx">         font-weight: 200;
</span><span class="cx"> }
</span><span class="cx"> .attachments-header input {
</span><span class="cx">         float: right;
</span><del>-        margin-top: 10px;
-        margin-right: 10px;
</del><ins>+        margin-top: 12px;
+        line-height: 18px;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> .attachments ul {
</span><span class="lines">@@ -146,7 +222,7 @@
</span><span class="cx">         right: 0;
</span><span class="cx">         bottom: 0;
</span><span class="cx">         overflow: auto;
</span><del>-        margin: 0 10px 20px;
</del><ins>+        margin: 0 -10px 20px;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -171,6 +247,21 @@
</span><span class="cx">         border-color: #21759b;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+.attachment.selected:after {
+        content: '\2713';
+        display: block;
+        height: 24px;
+        width: 24px;
+        position: absolute;
+        top: 0;
+        left: 0;
+        line-height: 24px;
+        font-size: 18px;
+        text-align: center;
+        color: #fff;
+        background: #21759b;
+}
+
</ins><span class="cx"> .attachment-thumbnail {
</span><span class="cx">         position: absolute;
</span><span class="cx">         top: 0;
</span><span class="lines">@@ -275,4 +366,68 @@
</span><span class="cx">
</span><span class="cx"> .uploading .upload-attachments .media-progress-bar {
</span><span class="cx">         display: block;
</span><ins>+}
+
+/**
+ * Selection Preview
+ */
+
+.selection-preview {
+        position: relative;
+        height: 60px;
+        overflow: hidden;
+}
+
+.selected-img {
+        float: left;
+        position: relative;
+        margin-right: 14px;
+}
+
+.selection-preview img {
+        max-width: 40px;
+        max-height: 40px;
+        float: left;
+        margin-top: 6px;
+        margin-left: 1px;
+        border: 2px solid white;
+        box-shadow:
+         0 0 0 1px #ccc,
+         3px 3px 0 0 #fff,
+         3px 3px 0 1px #ccc,
+         6px 6px 0 0 #fff,
+         6px 6px 0 1px #ccc;
+}
+
+.selection-preview .selected-count-1 img {
+        margin-top: 8px;
+        box-shadow: 0 0 0 1px #ccc;
+}
+
+.selection-preview .selected-count-2 img {
+        margin-top: 7px;
+        box-shadow:
+         0 0 0 1px #ccc,
+         3px 3px 0 0 #fff,
+         3px 3px 0 1px #ccc;
+}
+
+.selection-preview .count {
+        position: absolute;
+        bottom: 0;
+        right: 0;
+        height: 16px;
+        min-width: 8px;
+        padding: 0 4px;
+        font-size: 12px;
+        text-align: center;
+        font-weight: bold;
+        color: #999;
+        background: #fff;
+        box-shadow: -1px -1px 2px -1px rgba( 0, 0, 0, 0.2 );
+}
+
+.selection-preview .clear-selection {
+        float: left;
+        line-height: 60px;
</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 (21768 => 21769)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/media-views.js        2012-09-05 20:33:34 UTC (rev 21768)
+++ trunk/wp-includes/js/media-views.js        2012-09-06 07:46:15 UTC (rev 21769)
</span><span class="lines">@@ -139,6 +139,102 @@
</span><span class="cx">         });
</span><span class="cx">
</span><span class="cx">         /**
</span><ins>+         * wp.media.view.Toolbar
+         */
+        media.view.Toolbar = Backbone.View.extend({
+                tagName: 'div',
+                className: 'media-toolbar',
+
+                initialize: function() {
+                        this._views = {};
+                        this.$primary = $('<div class="media-toolbar-primary" />').prependTo( this.$el );
+                        this.$secondary = $('<div class="media-toolbar-secondary" />').prependTo( this.$el );
+
+                        if ( this.options.items ) {
+                                _.each( this.options.items, function( view, id ) {
+                                        this.add( id, view, { silent: true } );
+                                }, this );
+                                this.render();
+                        }
+                },
+
+                render: function() {
+                        var views = _.chain( this._views ).sortBy( function( view ) {
+                                return view.options.priority || 10;
+                        }).groupBy( function( view ) {
+                                return ( view.options.priority || 10 ) > 0 ? 'primary' : 'secondary';
+                        }).value();
+
+                        // Make sure to detach the elements we want to reuse.
+                        // Otherwise, `jQuery.html()` will unbind their events.
+                        $( _.pluck( this._views, 'el' ) ).detach();
+                        this.$primary.html( _.pluck( views.primary, 'el' ) );
+                        this.$secondary.html( _.pluck( views.secondary, 'el' ) );
+
+                        return this;
+                },
+
+                add: function( id, view, options ) {
+                        if ( ! ( view instanceof Backbone.View ) ) {
+                                view.classes = [ id ].concat( view.classes || [] );
+                                view = new media.view.Button( view ).render();
+                        }
+
+                        this._views[ id ] = view;
+                        if ( ! options || ! options.silent )
+                                this.render();
+                        return this;
+                },
+
+                remove: function( id, options ) {
+                        delete this._views[ id ];
+                        if ( ! options || ! options.silent )
+                                this.render();
+                        return this;
+                }
+        });
+
+
+        /**
+         * wp.media.view.Button
+         */
+        media.view.Button = Backbone.View.extend({
+                tagName: 'a',
+                className: 'media-button',
+                attributes: { href: '#' },
+
+                events: {
+                        'click': 'click'
+                },
+
+                initialize: function() {
+                        _.defaults( this.options, {
+                                style: 'secondary',
+                                text: '',
+                                classes: []
+                        });
+                },
+
+                render: function() {
+                        var classes = [ this.className ];
+
+                        if ( this.options.style )
+                                classes.push( 'button-' + this.options.style );
+
+                        classes = classes.concat( this.options.classes );
+                        this.el.className = classes.join(' ');
+                        this.$el.text( this.options.text );
+                        return this;
+                },
+
+                click: function( event ) {
+                        event.preventDefault();
+                        if ( this.options.click )
+                                this.options.click.apply( this, arguments );
+                }
+        });
+
+        /**
</ins><span class="cx">          * wp.media.view.Workspace
</span><span class="cx">          */
</span><span class="cx">         media.view.Workspace = Backbone.View.extend({
</span><span class="lines">@@ -159,6 +255,12 @@
</span><span class="cx">                                 uploader: {}
</span><span class="cx">                         });
</span><span class="cx">
</span><ins>+                        this.$content = $('<div class="existing-attachments" />');
+
+                        // If this supports multiple attachments, initialize the sample toolbar view.
+                        if ( this.controller.get('multiple') )
+                                this.initToolbarView();
+
</ins><span class="cx">                         this.attachmentsView = new media.view.Attachments({
</span><span class="cx">                                 controller: this.controller,
</span><span class="cx">                                 directions: 'Select stuff.',
</span><span class="lines">@@ -167,7 +269,6 @@
</span><span class="cx">                                 })
</span><span class="cx">                         });
</span><span class="cx">
</span><del>-                        this.$content = $('<div class="existing-attachments" />');
</del><span class="cx">                         this.$content.append( this.attachmentsView.$el );
</span><span class="cx">
</span><span class="cx">                         // Track uploading attachments.
</span><span class="lines">@@ -242,6 +343,42 @@
</span><span class="cx">                                         file.attachment.destroy();
</span><span class="cx">                                 }
</span><span class="cx">                         }, this.options.uploader ) );
</span><ins>+                },
+
+                // Initializes the toolbar view. Currently uses defaults set for
+                // inserting media into a post. This should be pulled out into the
+                // appropriate workflow when the time comes, but is currently here
+                // to test multiple selections.
+                initToolbarView: function() {
+                        this.toolbarView = new media.view.Toolbar({
+                                items: {
+                                        'selection-preview': new media.view.SelectionPreview({
+                                                controller: this.controller,
+                                                collection: this.controller.selection,
+                                                priority: -40
+                                        }),
+                                        'insert-into-post': {
+                                                style: 'primary',
+                                                text: 'Insert into post',
+                                                priority: 40
+                                        },
+                                        'create-new-gallery': {
+                                                style: 'primary',
+                                                text: 'Create a new gallery',
+                                                priority: 30
+                                        },
+                                        'add-to-gallery': {
+                                                text: 'Add to gallery',
+                                                priority: 20
+                                        }
+                                }
+                        });
+
+                        this.controller.selection.on( 'add remove', function() {
+                                this.$el.toggleClass( 'with-toolbar', !! this.controller.selection.length );
+                        }, this );
+
+                        this.$content.append( this.toolbarView.$el );
</ins><span class="cx">                 }
</span><span class="cx">         });
</span><span class="cx">
</span><span class="lines">@@ -426,4 +563,47 @@
</span><span class="cx">                                 this.$el.removeClass('selected');
</span><span class="cx">                 }
</span><span class="cx">         });
</span><ins>+
+        /**
+         * wp.media.view.SelectionPreview
+         */
+        media.view.SelectionPreview = Backbone.View.extend({
+                tagName: 'div',
+                className: 'selection-preview',
+                template: media.template('media-selection-preview'),
+
+                events: {
+                        'click .clear-selection': 'clear'
+                },
+
+                initialize: function() {
+                        this.controller = this.options.controller;
+                        this.collection.on( 'add change:url remove', this.render, this );
+                        this.render();
+                },
+
+                render: function() {
+                        var options = {},
+                                first, sizes, amount;
+
+                        // If nothing is selected, display nothing.
+                        if ( ! this.collection.length ) {
+                                this.$el.empty();
+                                return this;
+                        }
+
+                        options.count = this.collection.length;
+                        first = this.collection.first();
+                        sizes = first.get('sizes');
+                        options.thumbnail = ( sizes && sizes.thumbnail ) ? sizes.thumbnail.url : first.get('url');
+
+                        this.$el.html( this.template( options ) );
+                        return this;
+                },
+
+                clear: function( event ) {
+                        event.preventDefault();
+                        this.collection.clear();
+                }
+        });
</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 (21768 => 21769)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/media.php        2012-09-05 20:33:34 UTC (rev 21768)
+++ trunk/wp-includes/media.php        2012-09-06 07:46:15 UTC (rev 21769)
</span><span class="lines">@@ -1649,5 +1649,16 @@
</span><span class="cx">                 </div>
</span><span class="cx">                 <div class="describe"></div>
</span><span class="cx">         </script>
</span><ins>+
+        <script type="text/html" id="tmpl-media-selection-preview">
+                <div class="selected-img selected-count-<%- count %>">
+                        <% if ( thumbnail ) { %>
+                                <img src="<%- thumbnail %>" />
+                        <% } %>
+
+                        <span class="count"><%- count %></span>
+                </div>
+                <a class="clear-selection" href="#"><?php _e('Clear selection'); ?></a>
+        </script>
</ins><span class="cx">         <?php
</span><span class="cx"> }
</span></span></pre>
</div>
</div>
</body>
</html>