Make WordPress Core

Ticket #22637: 22637.2.diff

File 22637.2.diff, 8.4 KB (added by koopersmith, 13 years ago)
  • wp-includes/css/media-views.css

     
    267267        *max-width: 55%; /* IE7 */
    268268}
    269269
     270.media-sidebar .setting input[type="checkbox"] {
     271        margin-top: 10px;
     272}
     273
    270274.media-sidebar .setting span,
    271275.compat-item label span {
    272276        float: left;
  • wp-includes/js/media-editor.js

     
    189189                                args.type    = 'image';
    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 ) )
    194198                                        args.orderby = 'menuOrder';
     
    232236                                if ( props.uploadedTo )
    233237                                        attrs.id = props.uploadedTo;
    234238
     239                                // Check if the gallery is randomly ordered.
     240                                if ( attrs._orderbyRandom )
     241                                        attrs.orderby = 'rand';
     242                                delete attrs._orderbyRandom;
     243
    235244                                // If the `ids` attribute is set and `orderby` attribute
    236245                                // is the default value, clear it for cleaner output.
    237246                                if ( attrs.ids && 'post__in' === attrs.orderby )
  • wp-includes/js/media-models.js

     
    832832                // If the workflow does not support multiple
    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 );
    841839                },
    842840
    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 ) );
    862                 },
    863 
    864841                single: function( model ) {
    865842                        var previous = this._single;
    866843
     
    869846                                this._single = model;
    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
    875852                        this._single = this._single || this.last();
  • wp-includes/js/media-views.js

     
    329329                },
    330330
    331331                reset: function() {
    332                         this.get('selection').clear();
     332                        this.get('selection').reset();
    333333                        this.resetDisplays();
    334334                },
    335335
     
    534534                },
    535535
    536536                gallerySettings: function() {
    537                         var library = this.get('library');
     537                        var library = this.get('library'),
     538                                browser;
    538539
    539540                        if ( ! library )
    540541                                return;
    541542
    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,
    547550                                        model:      library.gallery,
    548551                                        priority:   40
    549552                                })
    550553                        });
     554
     555                        browser.toolbar.set( 'reverse', {
     556                                text:     l10n.reverseOrder,
     557                                priority: 80,
     558
     559                                click: function() {
     560                                        library.reset( library.toArray().reverse() );
     561                                }
     562                        });
    551563                }
    552564        });
    553565
     
    24972509                buttons: {},
    24982510
    24992511                initialize: function() {
     2512                        var selection = this.options.selection;
     2513
    25002514                        this.controller = this.options.controller;
    25012515
    25022516                        this.model.on( 'change:sizes change:uploading change:caption change:title', this.render, this );
    25032517                        this.model.on( 'change:percent', this.progress, this );
     2518
     2519                        // Update the selection.
    25042520                        this.model.on( 'add', this.select, this );
    25052521                        this.model.on( 'remove', this.deselect, this );
     2522                        if ( selection )
     2523                                selection.on( 'reset', this.updateSelect, this );
    25062524
    25072525                        // Update the model's details view.
    25082526                        this.model.on( 'selection:single selection:unsingle', this.details, this );
     
    25102528                },
    25112529
    25122530                dispose: function() {
     2531                        var selection = this.options.selection;
     2532
     2533                        // Make sure all settings are saved before removing the view.
    25132534                        this.updateAll();
     2535
     2536                        if ( selection )
     2537                                selection.off( null, null, this );
     2538
    25142539                        media.View.prototype.dispose.apply( this, arguments );
    25152540                        return this;
    25162541                },
     
    25492574                                delete this.$bar;
    25502575
    25512576                        // Check if the model is selected.
    2552                         if ( this.selected() )
    2553                                 this.select();
     2577                        this.updateSelect();
    25542578
    25552579                        this.views.render();
    25562580                        return this;
     
    25682592                        if ( ! selection )
    25692593                                return;
    25702594
    2571                         if ( selection.has( model ) ) {
     2595                        if ( this.selected() ) {
    25722596                                // If the model is the single model, remove it.
    25732597                                // If it is not the same as the single model,
    25742598                                // it now becomes the single model.
     
    25782602                        }
    25792603                },
    25802604
     2605                updateSelect: function() {
     2606                        this[ this.selected() ? 'select' : 'deselect' ]();
     2607                },
     2608
    25812609                selected: function() {
    25822610                        var selection = this.options.selection;
    25832611                        if ( selection )
    2584                                 return selection.has( this.model );
     2612                                return !! selection.getByCid( this.model.cid );
    25852613                },
    25862614
    25872615                select: function( model, collection ) {
     
    33263354
    33273355                clear: function( event ) {
    33283356                        event.preventDefault();
    3329                         this.collection.clear();
     3357                        this.collection.reset();
    33303358                }
    33313359        });
    33323360
     
    34023430
    34033431                clear: function( event ) {
    34043432                        event.preventDefault();
    3405                         this.collection.clear();
     3433                        this.collection.reset();
    34063434                }
    34073435        });
    34083436
     
    34823510                        } else if ( $setting.is('input[type="text"], textarea') ) {
    34833511                                if ( ! $setting.is(':focus') )
    34843512                                        $setting.val( value );
     3513
     3514                        // Handle checkboxes.
     3515                        } else if ( $setting.is('input[type="checkbox"]') ) {
     3516                                $setting.attr( 'checked', !! value );
    34853517                        }
    34863518                },
    34873519
     
    34953527                        if ( ! $setting.length )
    34963528                                return;
    34973529
     3530                        // Use the correct value for checkboxes.
     3531                        if ( $setting.is('input[type="checkbox"]') )
     3532                                value = $setting[0].checked;
     3533
     3534                        // Update the corresponding setting.
    34983535                        this.model.set( $setting.data('setting'), value );
    34993536
    35003537                        // If the setting has a corresponding user setting,
     
    35643601
    35653602                        $input.show();
    35663603
    3567                         if ( 'post' == linkTo ) {
     3604                        if ( 'post' === linkTo ) {
    35683605                                $input.val( attachment.get('link') );
    3569                         } else if ( 'file' == linkTo ) {
     3606                        } else if ( 'file' === linkTo ) {
    35703607                                $input.val( attachment.get('url') );
    35713608                        } else if ( ! this.model.get('linkUrl') ) {
    35723609                                $input.val('http://');
    35733610                        }
    35743611
    3575                         $input.prop('readonly', 'custom' !== linkTo);
     3612                        $input.prop( 'readonly', 'custom' !== linkTo );
    35763613
    35773614                        // If the input is visible, focus and select its contents.
    35783615                        if ( $input.is(':visible') )
  • wp-includes/media.php

     
    670670        $instance++;
    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        }
    677678
     
    14891490                'updateGallery'      => __( 'Update gallery' ),
    14901491                'continueEditing'    => __( 'Continue editing' ),
    14911492                'addToGallery'       => __( 'Add to gallery' ),
     1493                'reverseOrder'       => __( 'Reverse order' ),
    14921494        );
    14931495
    14941496        $settings = apply_filters( 'media_view_settings', $settings, $post );
     
    18651867                                <?php endfor; ?>
    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
    18701877        <script type="text/html" id="tmpl-embed-link-settings">