Make WordPress Core

Changeset 22987


Ignore:
Timestamp:
12/03/2012 05:32:25 AM (13 years ago)
Author:
ryan
Message:

Add random and reverse sorting options to gallery settings.

Props koopersmith
fixes #22637

Location:
trunk/wp-includes
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/css/media-views.css

    r22986 r22987  
    272272}
    273273
     274.media-sidebar .setting input[type="checkbox"] {
     275    margin-top: 10px;
     276}
     277
    274278.media-sidebar .setting span,
    275279.compat-item label span {
  • trunk/wp-includes/js/media-editor.js

    r22984 r22987  
    190190                args.perPage = -1;
    191191
     192                // Mark the `orderby` override attribute.
     193                if ( 'rand' === attrs.orderby )
     194                    attrs._orderbyRandom = true;
     195
    192196                // Map the `orderby` attribute to the corresponding model property.
    193197                if ( ! attrs.orderby || /^menu_order(?: ID)?$/i.test( attrs.orderby ) )
     
    232236                if ( props.uploadedTo )
    233237                    attrs.id = props.uploadedTo;
     238
     239                // Check if the gallery is randomly ordered.
     240                if ( attrs._orderbyRandom )
     241                    attrs.orderby = 'rand';
     242                delete attrs._orderbyRandom;
    234243
    235244                // If the `ids` attribute is set and `orderby` attribute
  • trunk/wp-includes/js/media-models.js

    r22979 r22987  
    833833        // selected attachments, reset the selection.
    834834        add: function( models, options ) {
    835             if ( ! this.multiple ) {
    836                 models = _.isArray( models ) && models.length ? _.first( models ) : models;
    837                 this.clear( options );
    838             }
     835            if ( ! this.multiple )
     836                this.remove( this.models );
    839837
    840838            return Attachments.prototype.add.call( this, models, options );
    841         },
    842 
    843         // Removes all models from the selection.
    844         clear: function( options ) {
    845             this.remove( this.models, options ).single();
    846             return this;
    847         },
    848 
    849         // Override the selection's reset method.
    850         // Always direct items through add and remove,
    851         // as we need them to fire.
    852         reset: function( models, options ) {
    853             this.clear( options ).add( models, options ).single();
    854             return this;
    855         },
    856 
    857         // Create selection.has, which determines if a model
    858         // exists in the collection based on cid and id,
    859         // instead of direct comparison.
    860         has: function( attachment ) {
    861             return !! ( this.getByCid( attachment.cid ) || this.get( attachment.id ) );
    862839        },
    863840
     
    870847
    871848            // If the single model isn't in the selection, remove it.
    872             if ( this._single && ! this.has( this._single ) )
     849            if ( this._single && ! this.getByCid( this._single.cid ) )
    873850                delete this._single;
    874851
  • trunk/wp-includes/js/media-views.js

    r22985 r22987  
    330330
    331331        reset: function() {
    332             this.get('selection').clear();
     332            this.get('selection').reset();
    333333            this.resetDisplays();
    334334        },
     
    535535
    536536        gallerySettings: function() {
    537             var library = this.get('library');
     537            var library = this.get('library'),
     538                browser;
    538539
    539540            if ( ! library )
     
    542543            library.gallery = library.gallery || new Backbone.Model();
    543544
    544             this.frame.content.view().sidebar.set({
     545            browser = this.frame.content.view();
     546
     547            browser.sidebar.set({
    545548                gallery: new media.view.Settings.Gallery({
    546549                    controller: this,
     
    548551                    priority:   40
    549552                })
     553            });
     554
     555            browser.toolbar.set( 'reverse', {
     556                text:     l10n.reverseOrder,
     557                priority: 80,
     558
     559                click: function() {
     560                    library.reset( library.toArray().reverse() );
     561                }
    550562            });
    551563        }
     
    25062518
    25072519        initialize: function() {
     2520            var selection = this.options.selection;
     2521
    25082522            this.controller = this.options.controller;
    25092523
    25102524            this.model.on( 'change:sizes change:uploading change:caption change:title', this.render, this );
    25112525            this.model.on( 'change:percent', this.progress, this );
     2526
     2527            // Update the selection.
    25122528            this.model.on( 'add', this.select, this );
    25132529            this.model.on( 'remove', this.deselect, this );
     2530            if ( selection )
     2531                selection.on( 'reset', this.updateSelect, this );
    25142532
    25152533            // Update the model's details view.
     
    25192537
    25202538        dispose: function() {
     2539            var selection = this.options.selection;
     2540
     2541            // Make sure all settings are saved before removing the view.
    25212542            this.updateAll();
     2543
     2544            if ( selection )
     2545                selection.off( null, null, this );
     2546
    25222547            media.View.prototype.dispose.apply( this, arguments );
    25232548            return this;
     
    25582583
    25592584            // Check if the model is selected.
    2560             if ( this.selected() )
    2561                 this.select();
     2585            this.updateSelect();
    25622586
    25632587            this.views.render();
     
    25772601                return;
    25782602
    2579             if ( selection.has( model ) ) {
     2603            if ( this.selected() ) {
    25802604                // If the model is the single model, remove it.
    25812605                // If it is not the same as the single model,
     
    25872611        },
    25882612
     2613        updateSelect: function() {
     2614            this[ this.selected() ? 'select' : 'deselect' ]();
     2615        },
     2616
    25892617        selected: function() {
    25902618            var selection = this.options.selection;
    25912619            if ( selection )
    2592                 return selection.has( this.model );
     2620                return !! selection.getByCid( this.model.cid );
    25932621        },
    25942622
     
    33133341        clear: function( event ) {
    33143342            event.preventDefault();
    3315             this.collection.clear();
     3343            this.collection.reset();
    33163344        }
    33173345    });
     
    33893417        clear: function( event ) {
    33903418            event.preventDefault();
    3391             this.collection.clear();
     3419            this.collection.reset();
    33923420        }
    33933421    });
     
    34693497                if ( ! $setting.is(':focus') )
    34703498                    $setting.val( value );
     3499
     3500            // Handle checkboxes.
     3501            } else if ( $setting.is('input[type="checkbox"]') ) {
     3502                $setting.attr( 'checked', !! value );
    34713503            }
    34723504        },
     
    34823514                return;
    34833515
     3516            // Use the correct value for checkboxes.
     3517            if ( $setting.is('input[type="checkbox"]') )
     3518                value = $setting[0].checked;
     3519
     3520            // Update the corresponding setting.
    34843521            this.model.set( $setting.data('setting'), value );
    34853522
     
    35513588            $input.show();
    35523589
    3553             if ( 'post' == linkTo ) {
     3590            if ( 'post' === linkTo ) {
    35543591                $input.val( attachment.get('link') );
    3555             } else if ( 'file' == linkTo ) {
     3592            } else if ( 'file' === linkTo ) {
    35563593                $input.val( attachment.get('url') );
    35573594            } else if ( ! this.model.get('linkUrl') ) {
     
    35593596            }
    35603597
    3561             $input.prop('readonly', 'custom' !== linkTo);
     3598            $input.prop( 'readonly', 'custom' !== linkTo );
    35623599
    35633600            // If the input is visible, focus and select its contents.
  • trunk/wp-includes/media.php

    r22983 r22987  
    671671
    672672    if ( ! empty( $attr['ids'] ) ) {
    673         // 'ids' is explicitly ordered
    674         $attr['orderby'] = 'post__in';
     673        // 'ids' is explicitly ordered, unless you specify otherwise.
     674        if ( empty( $attr['orderby'] ) )
     675            $attr['orderby'] = 'post__in';
    675676        $attr['include'] = $attr['ids'];
    676677    }
     
    14901491        'continueEditing'    => __( 'Continue editing' ),
    14911492        'addToGallery'       => __( 'Add to gallery' ),
     1493        'reverseOrder'       => __( 'Reverse order' ),
    14921494    );
    14931495
     
    18661868            </select>
    18671869        </label>
     1870
     1871        <label class="setting">
     1872            <span><?php _e('Random'); ?></span>
     1873            <input type="checkbox" data-setting="_orderbyRandom" />
     1874        </label>
    18681875    </script>
    18691876
Note: See TracChangeset for help on using the changeset viewer.