<!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>[22987] trunk/wp-includes: Add random and reverse sorting options to gallery settings.</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/22987">22987</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2012-12-03 05:32:25 +0000 (Mon, 03 Dec 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add random and reverse sorting options to gallery settings.

Props koopersmith
fixes <a href="http://core.trac.wordpress.org/ticket/22637">#22637</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludescssmediaviewscss">trunk/wp-includes/css/media-views.css</a></li>
<li><a href="#trunkwpincludesjsmediaeditorjs">trunk/wp-includes/js/media-editor.js</a></li>
<li><a href="#trunkwpincludesjsmediamodelsjs">trunk/wp-includes/js/media-models.js</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 (22986 => 22987)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/css/media-views.css        2012-12-03 05:17:23 UTC (rev 22986)
+++ trunk/wp-includes/css/media-views.css        2012-12-03 05:32:25 UTC (rev 22987)
</span><span class="lines">@@ -271,6 +271,10 @@
</span><span class="cx">         *max-width: 55%; /* IE7 */
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+.media-sidebar .setting input[type=&quot;checkbox&quot;] {
+        margin-top: 10px;
+}
+
</ins><span class="cx"> .media-sidebar .setting span,
</span><span class="cx"> .compat-item label span {
</span><span class="cx">         float: left;
</span></span></pre></div>
<a id="trunkwpincludesjsmediaeditorjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/media-editor.js (22986 => 22987)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/media-editor.js        2012-12-03 05:17:23 UTC (rev 22986)
+++ trunk/wp-includes/js/media-editor.js        2012-12-03 05:32:25 UTC (rev 22987)
</span><span class="lines">@@ -189,6 +189,10 @@
</span><span class="cx">                                 args.type    = 'image';
</span><span class="cx">                                 args.perPage = -1;
</span><span class="cx"> 
</span><ins>+                                // Mark the `orderby` override attribute.
+                                if ( 'rand' === attrs.orderby )
+                                        attrs._orderbyRandom = true;
+
</ins><span class="cx">                                 // Map the `orderby` attribute to the corresponding model property.
</span><span class="cx">                                 if ( ! attrs.orderby || /^menu_order(?: ID)?$/i.test( attrs.orderby ) )
</span><span class="cx">                                         args.orderby = 'menuOrder';
</span><span class="lines">@@ -232,6 +236,11 @@
</span><span class="cx">                                 if ( props.uploadedTo )
</span><span class="cx">                                         attrs.id = props.uploadedTo;
</span><span class="cx"> 
</span><ins>+                                // Check if the gallery is randomly ordered.
+                                if ( attrs._orderbyRandom )
+                                        attrs.orderby = 'rand';
+                                delete attrs._orderbyRandom;
+
</ins><span class="cx">                                 // If the `ids` attribute is set and `orderby` attribute
</span><span class="cx">                                 // is the default value, clear it for cleaner output.
</span><span class="cx">                                 if ( attrs.ids &amp;&amp; 'post__in' === attrs.orderby )
</span></span></pre></div>
<a id="trunkwpincludesjsmediamodelsjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/media-models.js (22986 => 22987)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/media-models.js        2012-12-03 05:17:23 UTC (rev 22986)
+++ trunk/wp-includes/js/media-models.js        2012-12-03 05:32:25 UTC (rev 22987)
</span><span class="lines">@@ -832,35 +832,12 @@
</span><span class="cx">                 // If the workflow does not support multiple
</span><span class="cx">                 // selected attachments, reset the selection.
</span><span class="cx">                 add: function( models, options ) {
</span><del>-                        if ( ! this.multiple ) {
-                                models = _.isArray( models ) &amp;&amp; models.length ? _.first( models ) : models;
-                                this.clear( options );
-                        }
</del><ins>+                        if ( ! this.multiple )
+                                this.remove( this.models );
</ins><span class="cx"> 
</span><span class="cx">                         return Attachments.prototype.add.call( this, models, options );
</span><span class="cx">                 },
</span><span class="cx"> 
</span><del>-                // Removes all models from the selection.
-                clear: function( options ) {
-                        this.remove( this.models, options ).single();
-                        return this;
-                },
-
-                // Override the selection's reset method.
-                // Always direct items through add and remove,
-                // as we need them to fire.
-                reset: function( models, options ) {
-                        this.clear( options ).add( models, options ).single();
-                        return this;
-                },
-
-                // Create selection.has, which determines if a model
-                // exists in the collection based on cid and id,
-                // instead of direct comparison.
-                has: function( attachment ) {
-                        return !! ( this.getByCid( attachment.cid ) || this.get( attachment.id ) );
-                },
-
</del><span class="cx">                 single: function( model ) {
</span><span class="cx">                         var previous = this._single;
</span><span class="cx"> 
</span><span class="lines">@@ -869,7 +846,7 @@
</span><span class="cx">                                 this._single = model;
</span><span class="cx"> 
</span><span class="cx">                         // If the single model isn't in the selection, remove it.
</span><del>-                        if ( this._single &amp;&amp; ! this.has( this._single ) )
</del><ins>+                        if ( this._single &amp;&amp; ! this.getByCid( this._single.cid ) )
</ins><span class="cx">                                 delete this._single;
</span><span class="cx"> 
</span><span class="cx">                         this._single = this._single || this.last();
</span></span></pre></div>
<a id="trunkwpincludesjsmediaviewsjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/media-views.js (22986 => 22987)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/media-views.js        2012-12-03 05:17:23 UTC (rev 22986)
+++ trunk/wp-includes/js/media-views.js        2012-12-03 05:32:25 UTC (rev 22987)
</span><span class="lines">@@ -329,7 +329,7 @@
</span><span class="cx">                 },
</span><span class="cx"> 
</span><span class="cx">                 reset: function() {
</span><del>-                        this.get('selection').clear();
</del><ins>+                        this.get('selection').reset();
</ins><span class="cx">                         this.resetDisplays();
</span><span class="cx">                 },
</span><span class="cx"> 
</span><span class="lines">@@ -534,20 +534,32 @@
</span><span class="cx">                 },
</span><span class="cx"> 
</span><span class="cx">                 gallerySettings: function() {
</span><del>-                        var library = this.get('library');
</del><ins>+                        var library = this.get('library'),
+                                browser;
</ins><span class="cx"> 
</span><span class="cx">                         if ( ! library )
</span><span class="cx">                                 return;
</span><span class="cx"> 
</span><span class="cx">                         library.gallery = library.gallery || new Backbone.Model();
</span><span class="cx"> 
</span><del>-                        this.frame.content.view().sidebar.set({
</del><ins>+                        browser = this.frame.content.view();
+
+                        browser.sidebar.set({
</ins><span class="cx">                                 gallery: new media.view.Settings.Gallery({
</span><span class="cx">                                         controller: this,
</span><span class="cx">                                         model:      library.gallery,
</span><span class="cx">                                         priority:   40
</span><span class="cx">                                 })
</span><span class="cx">                         });
</span><ins>+
+                        browser.toolbar.set( 'reverse', {
+                                text:     l10n.reverseOrder,
+                                priority: 80,
+
+                                click: function() {
+                                        library.reset( library.toArray().reverse() );
+                                }
+                        });
</ins><span class="cx">                 }
</span><span class="cx">         });
</span><span class="cx"> 
</span><span class="lines">@@ -2505,12 +2517,18 @@
</span><span class="cx">                 buttons: {},
</span><span class="cx"> 
</span><span class="cx">                 initialize: function() {
</span><ins>+                        var selection = this.options.selection;
+
</ins><span class="cx">                         this.controller = this.options.controller;
</span><span class="cx"> 
</span><span class="cx">                         this.model.on( 'change:sizes change:uploading change:caption change:title', this.render, this );
</span><span class="cx">                         this.model.on( 'change:percent', this.progress, this );
</span><ins>+
+                        // Update the selection.
</ins><span class="cx">                         this.model.on( 'add', this.select, this );
</span><span class="cx">                         this.model.on( 'remove', this.deselect, this );
</span><ins>+                        if ( selection )
+                                selection.on( 'reset', this.updateSelect, this );
</ins><span class="cx"> 
</span><span class="cx">                         // Update the model's details view.
</span><span class="cx">                         this.model.on( 'selection:single selection:unsingle', this.details, this );
</span><span class="lines">@@ -2518,7 +2536,14 @@
</span><span class="cx">                 },
</span><span class="cx"> 
</span><span class="cx">                 dispose: function() {
</span><ins>+                        var selection = this.options.selection;
+
+                        // Make sure all settings are saved before removing the view.
</ins><span class="cx">                         this.updateAll();
</span><ins>+
+                        if ( selection )
+                                selection.off( null, null, this );
+
</ins><span class="cx">                         media.View.prototype.dispose.apply( this, arguments );
</span><span class="cx">                         return this;
</span><span class="cx">                 },
</span><span class="lines">@@ -2557,8 +2582,7 @@
</span><span class="cx">                                 delete this.$bar;
</span><span class="cx"> 
</span><span class="cx">                         // Check if the model is selected.
</span><del>-                        if ( this.selected() )
-                                this.select();
</del><ins>+                        this.updateSelect();
</ins><span class="cx"> 
</span><span class="cx">                         this.views.render();
</span><span class="cx">                         return this;
</span><span class="lines">@@ -2576,7 +2600,7 @@
</span><span class="cx">                         if ( ! selection )
</span><span class="cx">                                 return;
</span><span class="cx"> 
</span><del>-                        if ( selection.has( model ) ) {
</del><ins>+                        if ( this.selected() ) {
</ins><span class="cx">                                 // If the model is the single model, remove it.
</span><span class="cx">                                 // If it is not the same as the single model,
</span><span class="cx">                                 // it now becomes the single model.
</span><span class="lines">@@ -2586,10 +2610,14 @@
</span><span class="cx">                         }
</span><span class="cx">                 },
</span><span class="cx"> 
</span><ins>+                updateSelect: function() {
+                        this[ this.selected() ? 'select' : 'deselect' ]();
+                },
+
</ins><span class="cx">                 selected: function() {
</span><span class="cx">                         var selection = this.options.selection;
</span><span class="cx">                         if ( selection )
</span><del>-                                return selection.has( this.model );
</del><ins>+                                return !! selection.getByCid( this.model.cid );
</ins><span class="cx">                 },
</span><span class="cx"> 
</span><span class="cx">                 select: function( model, collection ) {
</span><span class="lines">@@ -3312,7 +3340,7 @@
</span><span class="cx"> 
</span><span class="cx">                 clear: function( event ) {
</span><span class="cx">                         event.preventDefault();
</span><del>-                        this.collection.clear();
</del><ins>+                        this.collection.reset();
</ins><span class="cx">                 }
</span><span class="cx">         });
</span><span class="cx"> 
</span><span class="lines">@@ -3388,7 +3416,7 @@
</span><span class="cx"> 
</span><span class="cx">                 clear: function( event ) {
</span><span class="cx">                         event.preventDefault();
</span><del>-                        this.collection.clear();
</del><ins>+                        this.collection.reset();
</ins><span class="cx">                 }
</span><span class="cx">         });
</span><span class="cx"> 
</span><span class="lines">@@ -3468,6 +3496,10 @@
</span><span class="cx">                         } else if ( $setting.is('input[type=&quot;text&quot;], textarea') ) {
</span><span class="cx">                                 if ( ! $setting.is(':focus') )
</span><span class="cx">                                         $setting.val( value );
</span><ins>+
+                        // Handle checkboxes.
+                        } else if ( $setting.is('input[type=&quot;checkbox&quot;]') ) {
+                                $setting.attr( 'checked', !! value );
</ins><span class="cx">                         }
</span><span class="cx">                 },
</span><span class="cx"> 
</span><span class="lines">@@ -3481,6 +3513,11 @@
</span><span class="cx">                         if ( ! $setting.length )
</span><span class="cx">                                 return;
</span><span class="cx"> 
</span><ins>+                        // Use the correct value for checkboxes.
+                        if ( $setting.is('input[type=&quot;checkbox&quot;]') )
+                                value = $setting[0].checked;
+
+                        // Update the corresponding setting.
</ins><span class="cx">                         this.model.set( $setting.data('setting'), value );
</span><span class="cx"> 
</span><span class="cx">                         // If the setting has a corresponding user setting,
</span><span class="lines">@@ -3550,15 +3587,15 @@
</span><span class="cx"> 
</span><span class="cx">                         $input.show();
</span><span class="cx"> 
</span><del>-                        if ( 'post' == linkTo ) {
</del><ins>+                        if ( 'post' === linkTo ) {
</ins><span class="cx">                                 $input.val( attachment.get('link') );
</span><del>-                        } else if ( 'file' == linkTo ) {
</del><ins>+                        } else if ( 'file' === linkTo ) {
</ins><span class="cx">                                 $input.val( attachment.get('url') );
</span><span class="cx">                         } else if ( ! this.model.get('linkUrl') ) {
</span><span class="cx">                                 $input.val('http://');
</span><span class="cx">                         }
</span><span class="cx"> 
</span><del>-                        $input.prop('readonly', 'custom' !== linkTo);
</del><ins>+                        $input.prop( 'readonly', 'custom' !== linkTo );
</ins><span class="cx"> 
</span><span class="cx">                         // If the input is visible, focus and select its contents.
</span><span class="cx">                         if ( $input.is(':visible') )
</span></span></pre></div>
<a id="trunkwpincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/media.php (22986 => 22987)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/media.php        2012-12-03 05:17:23 UTC (rev 22986)
+++ trunk/wp-includes/media.php        2012-12-03 05:32:25 UTC (rev 22987)
</span><span class="lines">@@ -670,8 +670,9 @@
</span><span class="cx">         $instance++;
</span><span class="cx"> 
</span><span class="cx">         if ( ! empty( $attr['ids'] ) ) {
</span><del>-                // 'ids' is explicitly ordered
-                $attr['orderby'] = 'post__in';
</del><ins>+                // 'ids' is explicitly ordered, unless you specify otherwise.
+                if ( empty( $attr['orderby'] ) )
+                        $attr['orderby'] = 'post__in';
</ins><span class="cx">                 $attr['include'] = $attr['ids'];
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -1489,6 +1490,7 @@
</span><span class="cx">                 'updateGallery'      =&gt; __( 'Update gallery' ),
</span><span class="cx">                 'continueEditing'    =&gt; __( 'Continue editing' ),
</span><span class="cx">                 'addToGallery'       =&gt; __( 'Add to gallery' ),
</span><ins>+                'reverseOrder'       =&gt; __( 'Reverse order' ),
</ins><span class="cx">         );
</span><span class="cx"> 
</span><span class="cx">         $settings = apply_filters( 'media_view_settings', $settings, $post );
</span><span class="lines">@@ -1865,6 +1867,11 @@
</span><span class="cx">                                 &lt;?php endfor; ?&gt;
</span><span class="cx">                         &lt;/select&gt;
</span><span class="cx">                 &lt;/label&gt;
</span><ins>+
+                &lt;label class=&quot;setting&quot;&gt;
+                        &lt;span&gt;&lt;?php _e('Random'); ?&gt;&lt;/span&gt;
+                        &lt;input type=&quot;checkbox&quot; data-setting=&quot;_orderbyRandom&quot; /&gt;
+                &lt;/label&gt;
</ins><span class="cx">         &lt;/script&gt;
</span><span class="cx"> 
</span><span class="cx">         &lt;script type=&quot;text/html&quot; id=&quot;tmpl-embed-link-settings&quot;&gt;
</span></span></pre>
</div>
</div>

</body>
</html>