Ticket #31846: 31846.diff
| File 31846.diff, 12.8 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 01db38b..77323aa 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 }, 423 424 bindModelHandlers: function() { 425 // Close the modal if the attachment is deleted. 426 this.listenTo( this.model, 'change:status destroy', this.close, this ); 411 427 }, 412 428 413 429 createModal: function() { … … EditAttachments = MediaFrame.extend({ 424 440 425 441 // Completely destroy the modal DOM element when closing it. 426 442 this.modal.on( 'close', _.bind( function() { 427 this.modal.remove();428 443 $( 'body' ).off( 'keydown.media-modal' ); /* remove the keydown event */ 429 444 // Restore the original focus item if possible 430 445 $( 'li.attachment[data-id="' + this.model.get( 'id' ) +'"]' ).focus(); … … EditAttachments = MediaFrame.extend({ 442 457 */ 443 458 createStates: function() { 444 459 this.states.add([ 445 new wp.media.controller.EditAttachmentMetadata( { model: this.model } ) 460 new wp.media.controller.EditAttachmentMetadata({ 461 model: this.model, 462 library: this.library 463 }) 446 464 ]); 447 465 }, 448 466 … … EditAttachments = MediaFrame.extend({ 508 526 /** 509 527 * Rerender the view. 510 528 */ 511 rerender: function() { 529 rerender: function( model ) { 530 this.stopListening( this.model ); 531 532 this.model = model; 533 534 this.bindModelHandlers(); 535 512 536 // Only rerender the `content` region. 513 537 if ( this.content.mode() !== 'edit-metadata' ) { 514 538 this.content.mode( 'edit-metadata' ); … … EditAttachments = MediaFrame.extend({ 527 551 this.$( '.left' ).blur(); 528 552 return; 529 553 } 530 this.model = this.library.at( this.getCurrentIndex() - 1 ); 531 this.rerender(); 554 this.trigger( 'refresh', this.library.at( this.getCurrentIndex() - 1 ) ); 532 555 this.$( '.left' ).focus(); 533 556 }, 534 557 … … EditAttachments = MediaFrame.extend({ 540 563 this.$( '.right' ).blur(); 541 564 return; 542 565 } 543 this.model = this.library.at( this.getCurrentIndex() + 1 ); 544 this.rerender(); 566 this.trigger( 'refresh', this.library.at( this.getCurrentIndex() + 1 ) ); 545 567 this.$( '.right' ).focus(); 546 568 }, 547 569 … … Manage = MediaFrame.extend({ 662 684 this.bindRegionModeHandlers(); 663 685 this.render(); 664 686 this.bindSearchHandler(); 687 688 wp.media.frames.browse = this; 665 689 }, 666 690 667 691 bindSearchHandler: function() { … … Manage = MediaFrame.extend({ 682 706 683 707 // Update the URL when entering search string (at most once per second) 684 708 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 } ); 709 710 this.gridRouter 711 .on( 'route:search', function () { 712 var href = window.location.href; 713 if ( href.indexOf( 'mode=' ) > -1 ) { 714 href = href.replace( /mode=[^&]+/g, 'mode=list' ); 715 } else { 716 href += href.indexOf( '?' ) > -1 ? '&mode=list' : '?mode=list'; 717 } 718 href = href.replace( 'search=', 's=' ); 719 listMode.prop( 'href', href ); 720 }) 721 .on( 'route:reset', function() { 722 searchView.val( '' ).trigger( 'input' ); 723 }); 697 724 }, 698 725 699 726 /** … … Manage = MediaFrame.extend({ 781 808 */ 782 809 openEditAttachmentModal: function( model ) { 783 810 // Create a new EditAttachment frame, passing along the library and the attachment model. 784 wp.media( { 785 frame: 'edit-attachments', 786 controller: this, 787 library: this.state().get('library'), 788 model: model 789 } ); 811 if ( wp.media.frames.edit ) { 812 wp.media.frames.edit.open().trigger( 'refresh', model ); 813 } else { 814 wp.media.frames.edit = wp.media( { 815 frame: 'edit-attachments', 816 controller: this, 817 library: this.state().get('library'), 818 model: model 819 } ); 820 } 790 821 }, 791 822 792 823 /** -
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..d97eafe 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 }, 70 71 bindModelHandlers: function() { 72 // Close the modal if the attachment is deleted. 73 this.listenTo( this.model, 'change:status destroy', this.close, this ); 69 74 }, 70 75 71 76 createModal: function() { … … EditAttachments = MediaFrame.extend({ 82 87 83 88 // Completely destroy the modal DOM element when closing it. 84 89 this.modal.on( 'close', _.bind( function() { 85 this.modal.remove();86 90 $( 'body' ).off( 'keydown.media-modal' ); /* remove the keydown event */ 87 91 // Restore the original focus item if possible 88 92 $( 'li.attachment[data-id="' + this.model.get( 'id' ) +'"]' ).focus(); … … EditAttachments = MediaFrame.extend({ 100 104 */ 101 105 createStates: function() { 102 106 this.states.add([ 103 new wp.media.controller.EditAttachmentMetadata( { model: this.model } ) 107 new wp.media.controller.EditAttachmentMetadata({ 108 model: this.model, 109 library: this.library 110 }) 104 111 ]); 105 112 }, 106 113 … … EditAttachments = MediaFrame.extend({ 166 173 /** 167 174 * Rerender the view. 168 175 */ 169 rerender: function() { 176 rerender: function( model ) { 177 this.stopListening( this.model ); 178 179 this.model = model; 180 181 this.bindModelHandlers(); 182 170 183 // Only rerender the `content` region. 171 184 if ( this.content.mode() !== 'edit-metadata' ) { 172 185 this.content.mode( 'edit-metadata' ); … … EditAttachments = MediaFrame.extend({ 185 198 this.$( '.left' ).blur(); 186 199 return; 187 200 } 188 this.model = this.library.at( this.getCurrentIndex() - 1 ); 189 this.rerender(); 201 this.trigger( 'refresh', this.library.at( this.getCurrentIndex() - 1 ) ); 190 202 this.$( '.left' ).focus(); 191 203 }, 192 204 … … EditAttachments = MediaFrame.extend({ 198 210 this.$( '.right' ).blur(); 199 211 return; 200 212 } 201 this.model = this.library.at( this.getCurrentIndex() + 1 ); 202 this.rerender(); 213 this.trigger( 'refresh', this.library.at( this.getCurrentIndex() + 1 ) ); 203 214 this.$( '.right' ).focus(); 204 215 }, 205 216 -
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 46d758b..26a5da5 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({ 196 201 */ 197 202 openEditAttachmentModal: function( model ) { 198 203 // Create a new EditAttachment frame, passing along the library and the attachment model. 199 wp.media( { 200 frame: 'edit-attachments', 201 controller: this, 202 library: this.state().get('library'), 203 model: model 204 } ); 204 if ( wp.media.frames.edit ) { 205 wp.media.frames.edit.open().trigger( 'refresh', model ); 206 } else { 207 wp.media.frames.edit = wp.media( { 208 frame: 'edit-attachments', 209 controller: this, 210 library: this.state().get('library'), 211 model: model 212 } ); 213 } 205 214 }, 206 215 207 216 /**