Make WordPress Core

Ticket #31846: 31846.3.diff

File 31846.3.diff, 13.7 KB (added by kucrut, 10 years ago)
  • src/wp-includes/js/media-grid.js

    diff --git src/wp-includes/js/media-grid.js src/wp-includes/js/media-grid.js
    index 5d0faa2..6360dfe 100644
    media.view.DeleteSelectedPermanentlyButton = require( './views/button/delete-sel 
    5151var Router = Backbone.Router.extend({
    5252        routes: {
    5353                'upload.php?item=:slug':    'showItem',
    54                 'upload.php?search=:query': 'search'
     54                'upload.php?search=:query': 'search',
     55                'upload.php':               'reset'
    5556        },
    5657
    5758        // Map routes against the page URL
    var Router = Backbone.Router.extend({ 
    5960                return 'upload.php' + url;
    6061        },
    6162
     63        reset: function( query ) {
     64                var frame = wp.media.frames.edit;
     65
     66                if ( frame ) {
     67                        frame.close();
     68                }
     69        },
     70
    6271        // Respond to the search route by filling the search field and trigggering the input event
    6372        search: function( query ) {
    6473                jQuery( '#media-search-input' ).val( query ).trigger( 'input' );
    var Router = Backbone.Router.extend({ 
    6776        // Show the modal with a specific item
    6877        showItem: function( query ) {
    6978                var media = wp.media,
    70                         library = media.frame.state().get('library'),
     79                        frame = media.frames.browse,
     80                        library = frame.state().get('library'),
    7181                        item;
    7282
    7383                // Trigger the media frame to open the correct item
    7484                item = library.findWhere( { id: parseInt( query, 10 ) } );
     85
    7586                if ( item ) {
    76                         media.frame.trigger( 'edit:attachment', item );
     87                        frame.trigger( 'edit:attachment', item );
    7788                } else {
    7889                        item = media.attachment( query );
    79                         media.frame.listenTo( item, 'change', function( model ) {
    80                                 media.frame.stopListening( item );
    81                                 media.frame.trigger( 'edit:attachment', model );
     90                        frame.listenTo( item, 'change', function( model ) {
     91                                frame.stopListening( item );
     92                                frame.trigger( 'edit:attachment', model );
    8293                        } );
    8394                        item.fetch();
    8495                }
    EditAttachments = MediaFrame.extend({ 
    401412                // Bind default title creation.
    402413                this.on( 'title:create:default', this.createTitle, this );
    403414
    404                 // Close the modal if the attachment is deleted.
    405                 this.listenTo( this.model, 'change:status destroy', this.close, this );
    406 
    407415                this.on( 'content:create:edit-metadata', this.editMetadataMode, this );
    408416                this.on( 'content:create:edit-image', this.editImageMode, this );
    409417                this.on( 'content:render:edit-image', this.editImageModeRender, this );
     418                this.on( 'refresh', this.rerender, this );
    410419                this.on( 'close', this.detach );
     420
     421                this.bindModelHandlers();
     422                this.listenTo( this.gridRouter, 'route:search', this.close, this );
     423        },
     424
     425        bindModelHandlers: function() {
     426                // Close the modal if the attachment is deleted.
     427                this.listenTo( this.model, 'change:status destroy', this.close, this );
    411428        },
    412429
    413430        createModal: function() {
    EditAttachments = MediaFrame.extend({ 
    424441
    425442                        // Completely destroy the modal DOM element when closing it.
    426443                        this.modal.on( 'close', _.bind( function() {
    427                                 this.modal.remove();
    428444                                $( 'body' ).off( 'keydown.media-modal' ); /* remove the keydown event */
    429445                                // Restore the original focus item if possible
    430446                                $( 'li.attachment[data-id="' + this.model.get( 'id' ) +'"]' ).focus();
    EditAttachments = MediaFrame.extend({ 
    442458         */
    443459        createStates: function() {
    444460                this.states.add([
    445                         new wp.media.controller.EditAttachmentMetadata( { model: this.model } )
     461                        new wp.media.controller.EditAttachmentMetadata({
     462                                model:   this.model,
     463                                library: this.library
     464                        })
    446465                ]);
    447466        },
    448467
    EditAttachments = MediaFrame.extend({ 
    508527        /**
    509528         * Rerender the view.
    510529         */
    511         rerender: function() {
     530        rerender: function( model ) {
     531                this.stopListening( this.model );
     532
     533                this.model = model;
     534
     535                this.bindModelHandlers();
     536
    512537                // Only rerender the `content` region.
    513538                if ( this.content.mode() !== 'edit-metadata' ) {
    514539                        this.content.mode( 'edit-metadata' );
    EditAttachments = MediaFrame.extend({ 
    527552                        this.$( '.left' ).blur();
    528553                        return;
    529554                }
    530                 this.model = this.library.at( this.getCurrentIndex() - 1 );
    531                 this.rerender();
     555                this.trigger( 'refresh', this.library.at( this.getCurrentIndex() - 1 ) );
    532556                this.$( '.left' ).focus();
    533557        },
    534558
    EditAttachments = MediaFrame.extend({ 
    540564                        this.$( '.right' ).blur();
    541565                        return;
    542566                }
    543                 this.model = this.library.at( this.getCurrentIndex() + 1 );
    544                 this.rerender();
     567                this.trigger( 'refresh', this.library.at( this.getCurrentIndex() + 1 ) );
    545568                this.$( '.right' ).focus();
    546569        },
    547570
    EditAttachments = MediaFrame.extend({ 
    576599        },
    577600
    578601        resetRoute: function() {
    579                 this.gridRouter.navigate( this.gridRouter.baseUrl( '' ) );
     602                var searchTerm = this.controller.browserView.toolbar.get( 'search' ).$el.val(),
     603                        url = '' !== searchTerm ? '?search=' + searchTerm : '';
     604
     605                this.gridRouter.navigate( this.gridRouter.baseUrl( url ) );
    580606        }
    581607});
    582608
    Manage = MediaFrame.extend({ 
    662688                this.bindRegionModeHandlers();
    663689                this.render();
    664690                this.bindSearchHandler();
     691
     692                wp.media.frames.browse = this;
    665693        },
    666694
    667695        bindSearchHandler: function() {
    Manage = MediaFrame.extend({ 
    682710
    683711                // Update the URL when entering search string (at most once per second)
    684712                search.on( 'input', _.bind( input, this ) );
    685                 searchView.val( currentSearch ).trigger( 'input' );
    686 
    687                 this.gridRouter.on( 'route:search', function () {
    688                         var href = window.location.href;
    689                         if ( href.indexOf( 'mode=' ) > -1 ) {
    690                                 href = href.replace( /mode=[^&]+/g, 'mode=list' );
    691                         } else {
    692                                 href += href.indexOf( '?' ) > -1 ? '&mode=list' : '?mode=list';
    693                         }
    694                         href = href.replace( 'search=', 's=' );
    695                         listMode.prop( 'href', href );
    696                 } );
     713
     714                this.gridRouter
     715                        .on( 'route:search', function () {
     716                                var href = window.location.href;
     717                                if ( href.indexOf( 'mode=' ) > -1 ) {
     718                                        href = href.replace( /mode=[^&]+/g, 'mode=list' );
     719                                } else {
     720                                        href += href.indexOf( '?' ) > -1 ? '&mode=list' : '?mode=list';
     721                                }
     722                                href = href.replace( 'search=', 's=' );
     723                                listMode.prop( 'href', href );
     724                        })
     725                        .on( 'route:reset', function() {
     726                                searchView.val( '' ).trigger( 'input' );
     727                        });
    697728        },
    698729
    699730        /**
    Manage = MediaFrame.extend({ 
    785816         */
    786817        openEditAttachmentModal: function( model ) {
    787818                // Create a new EditAttachment frame, passing along the library and the attachment model.
    788                 wp.media( {
    789                         frame:       'edit-attachments',
    790                         controller:  this,
    791                         library:     this.state().get('library'),
    792                         model:       model
    793                 } );
     819                if ( wp.media.frames.edit ) {
     820                        wp.media.frames.edit.open().trigger( 'refresh', model );
     821                } else {
     822                        wp.media.frames.edit = wp.media( {
     823                                frame:       'edit-attachments',
     824                                controller:  this,
     825                                library:     this.state().get('library'),
     826                                model:       model
     827                        } );
     828                }
    794829        },
    795830
    796831        /**
  • src/wp-includes/js/media/routers/manage.js

    diff --git src/wp-includes/js/media/routers/manage.js src/wp-includes/js/media/routers/manage.js
    index 7395969..1b6f483 100644
     
    99var Router = Backbone.Router.extend({
    1010        routes: {
    1111                'upload.php?item=:slug':    'showItem',
    12                 'upload.php?search=:query': 'search'
     12                'upload.php?search=:query': 'search',
     13                'upload.php':               'reset'
    1314        },
    1415
    1516        // Map routes against the page URL
    var Router = Backbone.Router.extend({ 
    1718                return 'upload.php' + url;
    1819        },
    1920
     21        reset: function( query ) {
     22                var frame = wp.media.frames.edit;
     23
     24                if ( frame ) {
     25                        frame.close();
     26                }
     27        },
     28
    2029        // Respond to the search route by filling the search field and trigggering the input event
    2130        search: function( query ) {
    2231                jQuery( '#media-search-input' ).val( query ).trigger( 'input' );
    var Router = Backbone.Router.extend({ 
    2534        // Show the modal with a specific item
    2635        showItem: function( query ) {
    2736                var media = wp.media,
    28                         library = media.frame.state().get('library'),
     37                        frame = media.frames.browse,
     38                        library = frame.state().get('library'),
    2939                        item;
    3040
    3141                // Trigger the media frame to open the correct item
    3242                item = library.findWhere( { id: parseInt( query, 10 ) } );
     43
    3344                if ( item ) {
    34                         media.frame.trigger( 'edit:attachment', item );
     45                        frame.trigger( 'edit:attachment', item );
    3546                } else {
    3647                        item = media.attachment( query );
    37                         media.frame.listenTo( item, 'change', function( model ) {
    38                                 media.frame.stopListening( item );
    39                                 media.frame.trigger( 'edit:attachment', model );
     48                        frame.listenTo( item, 'change', function( model ) {
     49                                frame.stopListening( item );
     50                                frame.trigger( 'edit:attachment', model );
    4051                        } );
    4152                        item.fetch();
    4253                }
  • src/wp-includes/js/media/views/frame/edit-attachments.js

    diff --git src/wp-includes/js/media/views/frame/edit-attachments.js src/wp-includes/js/media/views/frame/edit-attachments.js
    index 3d29ff5..a2f7c59 100644
    EditAttachments = MediaFrame.extend({ 
    5959                // Bind default title creation.
    6060                this.on( 'title:create:default', this.createTitle, this );
    6161
    62                 // Close the modal if the attachment is deleted.
    63                 this.listenTo( this.model, 'change:status destroy', this.close, this );
    64 
    6562                this.on( 'content:create:edit-metadata', this.editMetadataMode, this );
    6663                this.on( 'content:create:edit-image', this.editImageMode, this );
    6764                this.on( 'content:render:edit-image', this.editImageModeRender, this );
     65                this.on( 'refresh', this.rerender, this );
    6866                this.on( 'close', this.detach );
     67
     68                this.bindModelHandlers();
     69                this.listenTo( this.gridRouter, 'route:search', this.close, this );
     70        },
     71
     72        bindModelHandlers: function() {
     73                // Close the modal if the attachment is deleted.
     74                this.listenTo( this.model, 'change:status destroy', this.close, this );
    6975        },
    7076
    7177        createModal: function() {
    EditAttachments = MediaFrame.extend({ 
    8288
    8389                        // Completely destroy the modal DOM element when closing it.
    8490                        this.modal.on( 'close', _.bind( function() {
    85                                 this.modal.remove();
    8691                                $( 'body' ).off( 'keydown.media-modal' ); /* remove the keydown event */
    8792                                // Restore the original focus item if possible
    8893                                $( 'li.attachment[data-id="' + this.model.get( 'id' ) +'"]' ).focus();
    EditAttachments = MediaFrame.extend({ 
    100105         */
    101106        createStates: function() {
    102107                this.states.add([
    103                         new wp.media.controller.EditAttachmentMetadata( { model: this.model } )
     108                        new wp.media.controller.EditAttachmentMetadata({
     109                                model:   this.model,
     110                                library: this.library
     111                        })
    104112                ]);
    105113        },
    106114
    EditAttachments = MediaFrame.extend({ 
    166174        /**
    167175         * Rerender the view.
    168176         */
    169         rerender: function() {
     177        rerender: function( model ) {
     178                this.stopListening( this.model );
     179
     180                this.model = model;
     181
     182                this.bindModelHandlers();
     183
    170184                // Only rerender the `content` region.
    171185                if ( this.content.mode() !== 'edit-metadata' ) {
    172186                        this.content.mode( 'edit-metadata' );
    EditAttachments = MediaFrame.extend({ 
    185199                        this.$( '.left' ).blur();
    186200                        return;
    187201                }
    188                 this.model = this.library.at( this.getCurrentIndex() - 1 );
    189                 this.rerender();
     202                this.trigger( 'refresh', this.library.at( this.getCurrentIndex() - 1 ) );
    190203                this.$( '.left' ).focus();
    191204        },
    192205
    EditAttachments = MediaFrame.extend({ 
    198211                        this.$( '.right' ).blur();
    199212                        return;
    200213                }
    201                 this.model = this.library.at( this.getCurrentIndex() + 1 );
    202                 this.rerender();
     214                this.trigger( 'refresh', this.library.at( this.getCurrentIndex() + 1 ) );
    203215                this.$( '.right' ).focus();
    204216        },
    205217
    EditAttachments = MediaFrame.extend({ 
    234246        },
    235247
    236248        resetRoute: function() {
    237                 this.gridRouter.navigate( this.gridRouter.baseUrl( '' ) );
     249                var searchTerm = this.controller.browserView.toolbar.get( 'search' ).$el.val(),
     250                        url = '' !== searchTerm ? '?search=' + searchTerm : '';
     251
     252                this.gridRouter.navigate( this.gridRouter.baseUrl( url ) );
    238253        }
    239254});
    240255
  • src/wp-includes/js/media/views/frame/manage.js

    diff --git src/wp-includes/js/media/views/frame/manage.js src/wp-includes/js/media/views/frame/manage.js
    index 5dd09a9..6664517 100644
    Manage = MediaFrame.extend({ 
    7777                this.bindRegionModeHandlers();
    7878                this.render();
    7979                this.bindSearchHandler();
     80
     81                wp.media.frames.browse = this;
    8082        },
    8183
    8284        bindSearchHandler: function() {
    Manage = MediaFrame.extend({ 
    9799
    98100                // Update the URL when entering search string (at most once per second)
    99101                search.on( 'input', _.bind( input, this ) );
    100                 searchView.val( currentSearch ).trigger( 'input' );
    101 
    102                 this.gridRouter.on( 'route:search', function () {
    103                         var href = window.location.href;
    104                         if ( href.indexOf( 'mode=' ) > -1 ) {
    105                                 href = href.replace( /mode=[^&]+/g, 'mode=list' );
    106                         } else {
    107                                 href += href.indexOf( '?' ) > -1 ? '&mode=list' : '?mode=list';
    108                         }
    109                         href = href.replace( 'search=', 's=' );
    110                         listMode.prop( 'href', href );
    111                 } );
     102
     103                this.gridRouter
     104                        .on( 'route:search', function () {
     105                                var href = window.location.href;
     106                                if ( href.indexOf( 'mode=' ) > -1 ) {
     107                                        href = href.replace( /mode=[^&]+/g, 'mode=list' );
     108                                } else {
     109                                        href += href.indexOf( '?' ) > -1 ? '&mode=list' : '?mode=list';
     110                                }
     111                                href = href.replace( 'search=', 's=' );
     112                                listMode.prop( 'href', href );
     113                        })
     114                        .on( 'route:reset', function() {
     115                                searchView.val( '' ).trigger( 'input' );
     116                        });
    112117        },
    113118
    114119        /**
    Manage = MediaFrame.extend({ 
    200205         */
    201206        openEditAttachmentModal: function( model ) {
    202207                // Create a new EditAttachment frame, passing along the library and the attachment model.
    203                 wp.media( {
    204                         frame:       'edit-attachments',
    205                         controller:  this,
    206                         library:     this.state().get('library'),
    207                         model:       model
    208                 } );
     208                if ( wp.media.frames.edit ) {
     209                        wp.media.frames.edit.open().trigger( 'refresh', model );
     210                } else {
     211                        wp.media.frames.edit = wp.media( {
     212                                frame:       'edit-attachments',
     213                                controller:  this,
     214                                library:     this.state().get('library'),
     215                                model:       model
     216                        } );
     217                }
    209218        },
    210219
    211220        /**