Ticket #31846: 31846.4.diff
| File 31846.4.diff, 16.1 KB (added by , 9 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 edf429e..4ddd034 100644
media.view.DeleteSelectedPermanentlyButton = require( './views/button/delete-sel 50 50 */ 51 51 var Router = Backbone.Router.extend({ 52 52 routes: { 53 'upload.php?item=:slug': 'showItem', 54 'upload.php?search=:query': 'search' 53 'upload.php?item=:slug&mode=edit': 'editItem', 54 'upload.php?item=:slug': 'showItem', 55 'upload.php?search=:query': 'search', 56 'upload.php': 'reset' 55 57 }, 56 58 57 59 // Map routes against the page URL … … var Router = Backbone.Router.extend({ 59 61 return 'upload.php' + url; 60 62 }, 61 63 64 reset: function( query ) { 65 var frame = wp.media.frames.edit; 66 67 if ( frame ) { 68 frame.close(); 69 } 70 }, 71 62 72 // Respond to the search route by filling the search field and trigggering the input event 63 73 search: function( query ) { 64 74 jQuery( '#media-search-input' ).val( query ).trigger( 'input' ); … … var Router = Backbone.Router.extend({ 67 77 // Show the modal with a specific item 68 78 showItem: function( query ) { 69 79 var media = wp.media, 70 library = media.frame.state().get('library'), 80 frame = media.frames.browse, 81 library = frame.state().get('library'), 71 82 item; 72 83 73 84 // Trigger the media frame to open the correct item 74 85 item = library.findWhere( { id: parseInt( query, 10 ) } ); 86 75 87 if ( item ) { 76 media.frame.trigger( 'edit:attachment', item );88 frame.trigger( 'edit:attachment', item ); 77 89 } else { 78 90 item = media.attachment( query ); 79 media.frame.listenTo( item, 'change', function( model ) {80 media.frame.stopListening( item );81 media.frame.trigger( 'edit:attachment', model );91 frame.listenTo( item, 'change', function( model ) { 92 frame.stopListening( item ); 93 frame.trigger( 'edit:attachment', model ); 82 94 } ); 83 95 item.fetch(); 84 96 } 97 }, 98 99 // Show the modal in edit mode with a specific item. 100 editItem: function( query ) { 101 this.showItem( query ); 102 wp.media.frames.edit.content.mode( 'edit-details' ); 85 103 } 86 104 }); 87 105 … … var Details = wp.media.view.Attachment.Details, 107 125 TwoColumn = Details.extend({ 108 126 template: wp.template( 'attachment-details-two-column' ), 109 127 128 initialize: function() { 129 this.controller.on( 'content:activate:edit-details', _.bind( this.editAttachment, this ) ); 130 131 Details.prototype.initialize.apply( this, arguments ); 132 }, 133 110 134 editAttachment: function( event ) { 111 event.preventDefault(); 135 if ( event ) { 136 event.preventDefault(); 137 } 112 138 this.controller.content.mode( 'edit-image' ); 113 139 }, 114 140 … … EditAttachments = MediaFrame.extend({ 401 427 // Bind default title creation. 402 428 this.on( 'title:create:default', this.createTitle, this ); 403 429 404 // Close the modal if the attachment is deleted.405 this.listenTo( this.model, 'change:status destroy', this.close, this );406 407 430 this.on( 'content:create:edit-metadata', this.editMetadataMode, this ); 408 431 this.on( 'content:create:edit-image', this.editImageMode, this ); 409 432 this.on( 'content:render:edit-image', this.editImageModeRender, this ); 433 this.on( 'refresh', this.rerender, this ); 410 434 this.on( 'close', this.detach ); 435 436 this.bindModelHandlers(); 437 this.listenTo( this.gridRouter, 'route:search', this.close, this ); 438 }, 439 440 bindModelHandlers: function() { 441 // Close the modal if the attachment is deleted. 442 this.listenTo( this.model, 'change:status destroy', this.close, this ); 411 443 }, 412 444 413 445 createModal: function() { … … EditAttachments = MediaFrame.extend({ 424 456 425 457 // Completely destroy the modal DOM element when closing it. 426 458 this.modal.on( 'close', _.bind( function() { 427 this.modal.remove();428 459 $( 'body' ).off( 'keydown.media-modal' ); /* remove the keydown event */ 429 460 // Restore the original focus item if possible 430 461 $( 'li.attachment[data-id="' + this.model.get( 'id' ) +'"]' ).focus(); … … EditAttachments = MediaFrame.extend({ 442 473 */ 443 474 createStates: function() { 444 475 this.states.add([ 445 new wp.media.controller.EditAttachmentMetadata( { model: this.model } ) 476 new wp.media.controller.EditAttachmentMetadata({ 477 model: this.model, 478 library: this.library 479 }) 446 480 ]); 447 481 }, 448 482 … … EditAttachments = MediaFrame.extend({ 494 528 frame: this, 495 529 controller: editImageController 496 530 } ); 531 532 this.gridRouter.navigate( this.gridRouter.baseUrl( '?item=' + this.model.id + '&mode=edit' ) ); 533 497 534 }, 498 535 499 536 editImageModeRender: function( view ) { … … EditAttachments = MediaFrame.extend({ 508 545 /** 509 546 * Rerender the view. 510 547 */ 511 rerender: function() { 548 rerender: function( model ) { 549 this.stopListening( this.model ); 550 551 this.model = model; 552 553 this.bindModelHandlers(); 554 512 555 // Only rerender the `content` region. 513 556 if ( this.content.mode() !== 'edit-metadata' ) { 514 557 this.content.mode( 'edit-metadata' ); … … EditAttachments = MediaFrame.extend({ 527 570 this.$( '.left' ).blur(); 528 571 return; 529 572 } 530 this.model = this.library.at( this.getCurrentIndex() - 1 ); 531 this.rerender(); 573 this.trigger( 'refresh', this.library.at( this.getCurrentIndex() - 1 ) ); 532 574 this.$( '.left' ).focus(); 533 575 }, 534 576 … … EditAttachments = MediaFrame.extend({ 540 582 this.$( '.right' ).blur(); 541 583 return; 542 584 } 543 this.model = this.library.at( this.getCurrentIndex() + 1 ); 544 this.rerender(); 585 this.trigger( 'refresh', this.library.at( this.getCurrentIndex() + 1 ) ); 545 586 this.$( '.right' ).focus(); 546 587 }, 547 588 … … EditAttachments = MediaFrame.extend({ 576 617 }, 577 618 578 619 resetRoute: function() { 579 this.gridRouter.navigate( this.gridRouter.baseUrl( '' ) ); 620 var searchTerm = this.controller.browserView.toolbar.get( 'search' ).$el.val(), 621 url = '' !== searchTerm ? '?search=' + searchTerm : ''; 622 623 this.gridRouter.navigate( this.gridRouter.baseUrl( url ) ); 580 624 } 581 625 }); 582 626 … … Manage = MediaFrame.extend({ 666 710 this.bindRegionModeHandlers(); 667 711 this.render(); 668 712 this.bindSearchHandler(); 713 714 wp.media.frames.browse = this; 669 715 }, 670 716 671 717 bindSearchHandler: function() { … … Manage = MediaFrame.extend({ 686 732 687 733 // Update the URL when entering search string (at most once per second) 688 734 search.on( 'input', _.bind( input, this ) ); 689 searchView.val( currentSearch ).trigger( 'input' ); 690 691 this.gridRouter.on( 'route:search', function () { 692 var href = window.location.href; 693 if ( href.indexOf( 'mode=' ) > -1 ) { 694 href = href.replace( /mode=[^&]+/g, 'mode=list' ); 695 } else { 696 href += href.indexOf( '?' ) > -1 ? '&mode=list' : '?mode=list'; 697 } 698 href = href.replace( 'search=', 's=' ); 699 listMode.prop( 'href', href ); 700 } ); 735 736 this.gridRouter 737 .on( 'route:search', function () { 738 var href = window.location.href; 739 if ( href.indexOf( 'mode=' ) > -1 ) { 740 href = href.replace( /mode=[^&]+/g, 'mode=list' ); 741 } else { 742 href += href.indexOf( '?' ) > -1 ? '&mode=list' : '?mode=list'; 743 } 744 href = href.replace( 'search=', 's=' ); 745 listMode.prop( 'href', href ); 746 }) 747 .on( 'route:reset', function() { 748 searchView.val( '' ).trigger( 'input' ); 749 }); 701 750 }, 702 751 703 752 /** … … Manage = MediaFrame.extend({ 789 838 */ 790 839 openEditAttachmentModal: function( model ) { 791 840 // Create a new EditAttachment frame, passing along the library and the attachment model. 792 wp.media( { 793 frame: 'edit-attachments', 794 controller: this, 795 library: this.state().get('library'), 796 model: model 797 } ); 841 if ( wp.media.frames.edit ) { 842 wp.media.frames.edit.open().trigger( 'refresh', model ); 843 } else { 844 wp.media.frames.edit = wp.media( { 845 frame: 'edit-attachments', 846 controller: this, 847 library: this.state().get('library'), 848 model: model 849 } ); 850 } 798 851 }, 799 852 800 853 /** -
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..477150e 100644
8 8 */ 9 9 var Router = Backbone.Router.extend({ 10 10 routes: { 11 'upload.php?item=:slug': 'showItem', 12 'upload.php?search=:query': 'search' 11 'upload.php?item=:slug&mode=edit': 'editItem', 12 'upload.php?item=:slug': 'showItem', 13 'upload.php?search=:query': 'search', 14 'upload.php': 'reset' 13 15 }, 14 16 15 17 // Map routes against the page URL … … var Router = Backbone.Router.extend({ 17 19 return 'upload.php' + url; 18 20 }, 19 21 22 reset: function( query ) { 23 var frame = wp.media.frames.edit; 24 25 if ( frame ) { 26 frame.close(); 27 } 28 }, 29 20 30 // Respond to the search route by filling the search field and trigggering the input event 21 31 search: function( query ) { 22 32 jQuery( '#media-search-input' ).val( query ).trigger( 'input' ); … … var Router = Backbone.Router.extend({ 25 35 // Show the modal with a specific item 26 36 showItem: function( query ) { 27 37 var media = wp.media, 28 library = media.frame.state().get('library'), 38 frame = media.frames.browse, 39 library = frame.state().get('library'), 29 40 item; 30 41 31 42 // Trigger the media frame to open the correct item 32 43 item = library.findWhere( { id: parseInt( query, 10 ) } ); 44 33 45 if ( item ) { 34 media.frame.trigger( 'edit:attachment', item );46 frame.trigger( 'edit:attachment', item ); 35 47 } else { 36 48 item = media.attachment( query ); 37 media.frame.listenTo( item, 'change', function( model ) {38 media.frame.stopListening( item );39 media.frame.trigger( 'edit:attachment', model );49 frame.listenTo( item, 'change', function( model ) { 50 frame.stopListening( item ); 51 frame.trigger( 'edit:attachment', model ); 40 52 } ); 41 53 item.fetch(); 42 54 } 55 }, 56 57 // Show the modal in edit mode with a specific item. 58 editItem: function( query ) { 59 this.showItem( query ); 60 wp.media.frames.edit.content.mode( 'edit-details' ); 43 61 } 44 62 }); 45 63 -
src/wp-includes/js/media/views/attachment/details-two-column.js
diff --git src/wp-includes/js/media/views/attachment/details-two-column.js src/wp-includes/js/media/views/attachment/details-two-column.js index 708287d..96a8fed 100644
var Details = wp.media.view.Attachment.Details, 17 17 TwoColumn = Details.extend({ 18 18 template: wp.template( 'attachment-details-two-column' ), 19 19 20 initialize: function() { 21 this.controller.on( 'content:activate:edit-details', _.bind( this.editAttachment, this ) ); 22 23 Details.prototype.initialize.apply( this, arguments ); 24 }, 25 20 26 editAttachment: function( event ) { 21 event.preventDefault(); 27 if ( event ) { 28 event.preventDefault(); 29 } 22 30 this.controller.content.mode( 'edit-image' ); 23 31 }, 24 32 -
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..7976eac 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({ 152 160 frame: this, 153 161 controller: editImageController 154 162 } ); 163 164 this.gridRouter.navigate( this.gridRouter.baseUrl( '?item=' + this.model.id + '&mode=edit' ) ); 165 155 166 }, 156 167 157 168 editImageModeRender: function( view ) { … … EditAttachments = MediaFrame.extend({ 166 177 /** 167 178 * Rerender the view. 168 179 */ 169 rerender: function() { 180 rerender: function( model ) { 181 this.stopListening( this.model ); 182 183 this.model = model; 184 185 this.bindModelHandlers(); 186 170 187 // Only rerender the `content` region. 171 188 if ( this.content.mode() !== 'edit-metadata' ) { 172 189 this.content.mode( 'edit-metadata' ); … … EditAttachments = MediaFrame.extend({ 185 202 this.$( '.left' ).blur(); 186 203 return; 187 204 } 188 this.model = this.library.at( this.getCurrentIndex() - 1 ); 189 this.rerender(); 205 this.trigger( 'refresh', this.library.at( this.getCurrentIndex() - 1 ) ); 190 206 this.$( '.left' ).focus(); 191 207 }, 192 208 … … EditAttachments = MediaFrame.extend({ 198 214 this.$( '.right' ).blur(); 199 215 return; 200 216 } 201 this.model = this.library.at( this.getCurrentIndex() + 1 ); 202 this.rerender(); 217 this.trigger( 'refresh', this.library.at( this.getCurrentIndex() + 1 ) ); 203 218 this.$( '.right' ).focus(); 204 219 }, 205 220 … … EditAttachments = MediaFrame.extend({ 234 249 }, 235 250 236 251 resetRoute: function() { 237 this.gridRouter.navigate( this.gridRouter.baseUrl( '' ) ); 252 var searchTerm = this.controller.browserView.toolbar.get( 'search' ).$el.val(), 253 url = '' !== searchTerm ? '?search=' + searchTerm : ''; 254 255 this.gridRouter.navigate( this.gridRouter.baseUrl( url ) ); 238 256 } 239 257 }); 240 258 -
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 a033d7b..ccf7849 100644
Manage = MediaFrame.extend({ 81 81 this.bindRegionModeHandlers(); 82 82 this.render(); 83 83 this.bindSearchHandler(); 84 85 wp.media.frames.browse = this; 84 86 }, 85 87 86 88 bindSearchHandler: function() { … … Manage = MediaFrame.extend({ 101 103 102 104 // Update the URL when entering search string (at most once per second) 103 105 search.on( 'input', _.bind( input, this ) ); 104 searchView.val( currentSearch ).trigger( 'input' ); 105 106 this.gridRouter.on( 'route:search', function () { 107 var href = window.location.href; 108 if ( href.indexOf( 'mode=' ) > -1 ) { 109 href = href.replace( /mode=[^&]+/g, 'mode=list' ); 110 } else { 111 href += href.indexOf( '?' ) > -1 ? '&mode=list' : '?mode=list'; 112 } 113 href = href.replace( 'search=', 's=' ); 114 listMode.prop( 'href', href ); 115 } ); 106 107 this.gridRouter 108 .on( 'route:search', function () { 109 var href = window.location.href; 110 if ( href.indexOf( 'mode=' ) > -1 ) { 111 href = href.replace( /mode=[^&]+/g, 'mode=list' ); 112 } else { 113 href += href.indexOf( '?' ) > -1 ? '&mode=list' : '?mode=list'; 114 } 115 href = href.replace( 'search=', 's=' ); 116 listMode.prop( 'href', href ); 117 }) 118 .on( 'route:reset', function() { 119 searchView.val( '' ).trigger( 'input' ); 120 }); 116 121 }, 117 122 118 123 /** … … Manage = MediaFrame.extend({ 204 209 */ 205 210 openEditAttachmentModal: function( model ) { 206 211 // Create a new EditAttachment frame, passing along the library and the attachment model. 207 wp.media( { 208 frame: 'edit-attachments', 209 controller: this, 210 library: this.state().get('library'), 211 model: model 212 } ); 212 if ( wp.media.frames.edit ) { 213 wp.media.frames.edit.open().trigger( 'refresh', model ); 214 } else { 215 wp.media.frames.edit = wp.media( { 216 frame: 'edit-attachments', 217 controller: this, 218 library: this.state().get('library'), 219 model: model 220 } ); 221 } 213 222 }, 214 223 215 224 /**