Ticket #31846: 31846.3.diff
| File 31846.3.diff, 13.7 KB (added by , 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 51 51 var Router = Backbone.Router.extend({ 52 52 routes: { 53 53 'upload.php?item=:slug': 'showItem', 54 'upload.php?search=:query': 'search' 54 'upload.php?search=:query': 'search', 55 'upload.php': 'reset' 55 56 }, 56 57 57 58 // Map routes against the page URL … … var Router = Backbone.Router.extend({ 59 60 return 'upload.php' + url; 60 61 }, 61 62 63 reset: function( query ) { 64 var frame = wp.media.frames.edit; 65 66 if ( frame ) { 67 frame.close(); 68 } 69 }, 70 62 71 // Respond to the search route by filling the search field and trigggering the input event 63 72 search: function( query ) { 64 73 jQuery( '#media-search-input' ).val( query ).trigger( 'input' ); … … var Router = Backbone.Router.extend({ 67 76 // Show the modal with a specific item 68 77 showItem: function( query ) { 69 78 var media = wp.media, 70 library = media.frame.state().get('library'), 79 frame = media.frames.browse, 80 library = frame.state().get('library'), 71 81 item; 72 82 73 83 // Trigger the media frame to open the correct item 74 84 item = library.findWhere( { id: parseInt( query, 10 ) } ); 85 75 86 if ( item ) { 76 media.frame.trigger( 'edit:attachment', item );87 frame.trigger( 'edit:attachment', item ); 77 88 } else { 78 89 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 ); 82 93 } ); 83 94 item.fetch(); 84 95 } … … EditAttachments = MediaFrame.extend({ 401 412 // Bind default title creation. 402 413 this.on( 'title:create:default', this.createTitle, this ); 403 414 404 // Close the modal if the attachment is deleted.405 this.listenTo( this.model, 'change:status destroy', this.close, this );406 407 415 this.on( 'content:create:edit-metadata', this.editMetadataMode, this ); 408 416 this.on( 'content:create:edit-image', this.editImageMode, this ); 409 417 this.on( 'content:render:edit-image', this.editImageModeRender, this ); 418 this.on( 'refresh', this.rerender, this ); 410 419 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 ); 411 428 }, 412 429 413 430 createModal: function() { … … EditAttachments = MediaFrame.extend({ 424 441 425 442 // Completely destroy the modal DOM element when closing it. 426 443 this.modal.on( 'close', _.bind( function() { 427 this.modal.remove();428 444 $( 'body' ).off( 'keydown.media-modal' ); /* remove the keydown event */ 429 445 // Restore the original focus item if possible 430 446 $( 'li.attachment[data-id="' + this.model.get( 'id' ) +'"]' ).focus(); … … EditAttachments = MediaFrame.extend({ 442 458 */ 443 459 createStates: function() { 444 460 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 }) 446 465 ]); 447 466 }, 448 467 … … EditAttachments = MediaFrame.extend({ 508 527 /** 509 528 * Rerender the view. 510 529 */ 511 rerender: function() { 530 rerender: function( model ) { 531 this.stopListening( this.model ); 532 533 this.model = model; 534 535 this.bindModelHandlers(); 536 512 537 // Only rerender the `content` region. 513 538 if ( this.content.mode() !== 'edit-metadata' ) { 514 539 this.content.mode( 'edit-metadata' ); … … EditAttachments = MediaFrame.extend({ 527 552 this.$( '.left' ).blur(); 528 553 return; 529 554 } 530 this.model = this.library.at( this.getCurrentIndex() - 1 ); 531 this.rerender(); 555 this.trigger( 'refresh', this.library.at( this.getCurrentIndex() - 1 ) ); 532 556 this.$( '.left' ).focus(); 533 557 }, 534 558 … … EditAttachments = MediaFrame.extend({ 540 564 this.$( '.right' ).blur(); 541 565 return; 542 566 } 543 this.model = this.library.at( this.getCurrentIndex() + 1 ); 544 this.rerender(); 567 this.trigger( 'refresh', this.library.at( this.getCurrentIndex() + 1 ) ); 545 568 this.$( '.right' ).focus(); 546 569 }, 547 570 … … EditAttachments = MediaFrame.extend({ 576 599 }, 577 600 578 601 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 ) ); 580 606 } 581 607 }); 582 608 … … Manage = MediaFrame.extend({ 662 688 this.bindRegionModeHandlers(); 663 689 this.render(); 664 690 this.bindSearchHandler(); 691 692 wp.media.frames.browse = this; 665 693 }, 666 694 667 695 bindSearchHandler: function() { … … Manage = MediaFrame.extend({ 682 710 683 711 // Update the URL when entering search string (at most once per second) 684 712 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 }); 697 728 }, 698 729 699 730 /** … … Manage = MediaFrame.extend({ 785 816 */ 786 817 openEditAttachmentModal: function( model ) { 787 818 // 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 } 794 829 }, 795 830 796 831 /** -
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
9 9 var Router = Backbone.Router.extend({ 10 10 routes: { 11 11 'upload.php?item=:slug': 'showItem', 12 'upload.php?search=:query': 'search' 12 'upload.php?search=:query': 'search', 13 'upload.php': 'reset' 13 14 }, 14 15 15 16 // Map routes against the page URL … … var Router = Backbone.Router.extend({ 17 18 return 'upload.php' + url; 18 19 }, 19 20 21 reset: function( query ) { 22 var frame = wp.media.frames.edit; 23 24 if ( frame ) { 25 frame.close(); 26 } 27 }, 28 20 29 // Respond to the search route by filling the search field and trigggering the input event 21 30 search: function( query ) { 22 31 jQuery( '#media-search-input' ).val( query ).trigger( 'input' ); … … var Router = Backbone.Router.extend({ 25 34 // Show the modal with a specific item 26 35 showItem: function( query ) { 27 36 var media = wp.media, 28 library = media.frame.state().get('library'), 37 frame = media.frames.browse, 38 library = frame.state().get('library'), 29 39 item; 30 40 31 41 // Trigger the media frame to open the correct item 32 42 item = library.findWhere( { id: parseInt( query, 10 ) } ); 43 33 44 if ( item ) { 34 media.frame.trigger( 'edit:attachment', item );45 frame.trigger( 'edit:attachment', item ); 35 46 } else { 36 47 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 ); 40 51 } ); 41 52 item.fetch(); 42 53 } -
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({ 59 59 // Bind default title creation. 60 60 this.on( 'title:create:default', this.createTitle, this ); 61 61 62 // Close the modal if the attachment is deleted.63 this.listenTo( this.model, 'change:status destroy', this.close, this );64 65 62 this.on( 'content:create:edit-metadata', this.editMetadataMode, this ); 66 63 this.on( 'content:create:edit-image', this.editImageMode, this ); 67 64 this.on( 'content:render:edit-image', this.editImageModeRender, this ); 65 this.on( 'refresh', this.rerender, this ); 68 66 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 ); 69 75 }, 70 76 71 77 createModal: function() { … … EditAttachments = MediaFrame.extend({ 82 88 83 89 // Completely destroy the modal DOM element when closing it. 84 90 this.modal.on( 'close', _.bind( function() { 85 this.modal.remove();86 91 $( 'body' ).off( 'keydown.media-modal' ); /* remove the keydown event */ 87 92 // Restore the original focus item if possible 88 93 $( 'li.attachment[data-id="' + this.model.get( 'id' ) +'"]' ).focus(); … … EditAttachments = MediaFrame.extend({ 100 105 */ 101 106 createStates: function() { 102 107 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 }) 104 112 ]); 105 113 }, 106 114 … … EditAttachments = MediaFrame.extend({ 166 174 /** 167 175 * Rerender the view. 168 176 */ 169 rerender: function() { 177 rerender: function( model ) { 178 this.stopListening( this.model ); 179 180 this.model = model; 181 182 this.bindModelHandlers(); 183 170 184 // Only rerender the `content` region. 171 185 if ( this.content.mode() !== 'edit-metadata' ) { 172 186 this.content.mode( 'edit-metadata' ); … … EditAttachments = MediaFrame.extend({ 185 199 this.$( '.left' ).blur(); 186 200 return; 187 201 } 188 this.model = this.library.at( this.getCurrentIndex() - 1 ); 189 this.rerender(); 202 this.trigger( 'refresh', this.library.at( this.getCurrentIndex() - 1 ) ); 190 203 this.$( '.left' ).focus(); 191 204 }, 192 205 … … EditAttachments = MediaFrame.extend({ 198 211 this.$( '.right' ).blur(); 199 212 return; 200 213 } 201 this.model = this.library.at( this.getCurrentIndex() + 1 ); 202 this.rerender(); 214 this.trigger( 'refresh', this.library.at( this.getCurrentIndex() + 1 ) ); 203 215 this.$( '.right' ).focus(); 204 216 }, 205 217 … … EditAttachments = MediaFrame.extend({ 234 246 }, 235 247 236 248 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 ) ); 238 253 } 239 254 }); 240 255 -
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({ 77 77 this.bindRegionModeHandlers(); 78 78 this.render(); 79 79 this.bindSearchHandler(); 80 81 wp.media.frames.browse = this; 80 82 }, 81 83 82 84 bindSearchHandler: function() { … … Manage = MediaFrame.extend({ 97 99 98 100 // Update the URL when entering search string (at most once per second) 99 101 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 }); 112 117 }, 113 118 114 119 /** … … Manage = MediaFrame.extend({ 200 205 */ 201 206 openEditAttachmentModal: function( model ) { 202 207 // 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 } 209 218 }, 210 219 211 220 /**