Changeset 41021
- Timestamp:
- 07/10/2017 07:07:27 PM (7 years ago)
- Location:
- trunk/src/wp-includes/js
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/js/media-grid.js
r40359 r41021 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 … … 60 62 }, 61 63 64 reset: function() { 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 ) { … … 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 item.set( 'skipHistory', true ); 87 75 88 if ( item ) { 76 media.frame.trigger( 'edit:attachment', item );89 frame.trigger( 'edit:attachment', item ); 77 90 } else { 78 91 item = media.attachment( query ); 79 media.frame.listenTo( item, 'change', function( model ) {80 media.frame.stopListening( item );81 media.frame.trigger( 'edit:attachment', model );92 frame.listenTo( item, 'change', function( model ) { 93 frame.stopListening( item ); 94 frame.trigger( 'edit:attachment', model ); 82 95 } ); 83 96 item.fetch(); 84 97 } 98 }, 99 100 // Show the modal in edit mode with a specific item. 101 editItem: function( query ) { 102 this.showItem( query ); 103 wp.media.frames.edit.content.mode( 'edit-details' ); 85 104 } 86 105 }); … … 108 127 template: wp.template( 'attachment-details-two-column' ), 109 128 129 initialize: function() { 130 this.controller.on( 'content:activate:edit-details', _.bind( this.editAttachment, this ) ); 131 132 Details.prototype.initialize.apply( this, arguments ); 133 }, 134 110 135 editAttachment: function( event ) { 111 event.preventDefault(); 136 if ( event ) { 137 event.preventDefault(); 138 } 112 139 this.controller.content.mode( 'edit-image' ); 113 140 }, … … 402 429 this.on( 'title:create:default', this.createTitle, this ); 403 430 404 // Close the modal if the attachment is deleted.405 this.listenTo( this.model, 'change:status destroy', this.close, this );406 407 431 this.on( 'content:create:edit-metadata', this.editMetadataMode, this ); 408 432 this.on( 'content:create:edit-image', this.editImageMode, this ); 409 433 this.on( 'content:render:edit-image', this.editImageModeRender, this ); 434 this.on( 'refresh', this.rerender, this ); 410 435 this.on( 'close', this.detach ); 436 437 this.bindModelHandlers(); 438 this.listenTo( this.gridRouter, 'route:search', this.close, this ); 439 }, 440 441 bindModelHandlers: function() { 442 // Close the modal if the attachment is deleted. 443 this.listenTo( this.model, 'change:status destroy', this.close, this ); 411 444 }, 412 445 … … 425 458 // Completely destroy the modal DOM element when closing it. 426 459 this.modal.on( 'close', _.bind( function() { 427 this.modal.remove();428 460 $( 'body' ).off( 'keydown.media-modal' ); /* remove the keydown event */ 429 461 // Restore the original focus item if possible … … 443 475 createStates: function() { 444 476 this.states.add([ 445 new wp.media.controller.EditAttachmentMetadata( { model: this.model } ) 477 new wp.media.controller.EditAttachmentMetadata({ 478 model: this.model, 479 library: this.library 480 }) 446 481 ]); 447 482 }, … … 468 503 }) ); 469 504 470 // Update browser url when navigating media details 471 if ( this.model ) {505 // Update browser url when navigating media details, except on load. 506 if ( this.model && ! this.model.get( 'skipHistory' ) ) { 472 507 this.gridRouter.navigate( this.gridRouter.baseUrl( '?item=' + this.model.id ) ); 473 508 } … … 495 530 controller: editImageController 496 531 } ); 532 533 this.gridRouter.navigate( this.gridRouter.baseUrl( '?item=' + this.model.id + '&mode=edit' ) ); 534 497 535 }, 498 536 … … 509 547 * Rerender the view. 510 548 */ 511 rerender: function() { 549 rerender: function( model ) { 550 this.stopListening( this.model ); 551 552 this.model = model; 553 554 this.bindModelHandlers(); 555 512 556 // Only rerender the `content` region. 513 557 if ( this.content.mode() !== 'edit-metadata' ) { … … 528 572 return; 529 573 } 530 this.model = this.library.at( this.getCurrentIndex() - 1 ); 531 this.rerender(); 574 this.trigger( 'refresh', this.library.at( this.getCurrentIndex() - 1 ) ); 532 575 this.$( '.left' ).focus(); 533 576 }, … … 541 584 return; 542 585 } 543 this.model = this.library.at( this.getCurrentIndex() + 1 ); 544 this.rerender(); 586 this.trigger( 'refresh', this.library.at( this.getCurrentIndex() + 1 ) ); 545 587 this.$( '.right' ).focus(); 546 588 }, … … 577 619 578 620 resetRoute: function() { 579 this.gridRouter.navigate( this.gridRouter.baseUrl( '' ) ); 621 var searchTerm = this.controller.browserView.toolbar.get( 'search' ).$el.val(), 622 url = '' !== searchTerm ? '?search=' + searchTerm : ''; 623 this.gridRouter.navigate( this.gridRouter.baseUrl( url ), { replace: true } ); 580 624 } 581 625 }); … … 667 711 this.render(); 668 712 this.bindSearchHandler(); 713 714 wp.media.frames.browse = this; 669 715 }, 670 716 671 717 bindSearchHandler: function() { 672 718 var search = this.$( '#media-search-input' ), 673 currentSearch = this.options.container.data( 'search' ),674 719 searchView = this.browserView.toolbar.get( 'search' ).$el, 675 720 listMode = this.$( '.view-list' ), 676 721 677 input = _. debounce( function (e) {722 input = _.throttle( function (e) { 678 723 var val = $( e.currentTarget ).val(), 679 724 url = ''; … … 681 726 if ( val ) { 682 727 url += '?search=' + val; 728 this.gridRouter.navigate( this.gridRouter.baseUrl( url ), { replace: true } ); 683 729 } 684 this.gridRouter.navigate( this.gridRouter.baseUrl( url ) );685 730 }, 1000 ); 686 731 687 732 // Update the URL when entering search string (at most once per second) 688 733 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 } ); 734 735 this.gridRouter 736 .on( 'route:search', function () { 737 var href = window.location.href; 738 if ( href.indexOf( 'mode=' ) > -1 ) { 739 href = href.replace( /mode=[^&]+/g, 'mode=list' ); 740 } else { 741 href += href.indexOf( '?' ) > -1 ? '&mode=list' : '?mode=list'; 742 } 743 href = href.replace( 'search=', 's=' ); 744 listMode.prop( 'href', href ); 745 }) 746 .on( 'route:reset', function() { 747 searchView.val( '' ).trigger( 'input' ); 748 }); 701 749 }, 702 750 … … 790 838 openEditAttachmentModal: function( model ) { 791 839 // 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 } ); 840 if ( wp.media.frames.edit ) { 841 wp.media.frames.edit.open().trigger( 'refresh', model ); 842 } else { 843 wp.media.frames.edit = wp.media( { 844 frame: 'edit-attachments', 845 controller: this, 846 library: this.state().get('library'), 847 model: model 848 } ); 849 } 798 850 }, 799 851 -
trunk/src/wp-includes/js/media/routers/manage.js
r33342 r41021 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 … … 16 18 baseUrl: function( url ) { 17 19 return 'upload.php' + url; 20 }, 21 22 reset: function() { 23 var frame = wp.media.frames.edit; 24 25 if ( frame ) { 26 frame.close(); 27 } 18 28 }, 19 29 … … 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 item.set( 'skipHistory', true ); 45 33 46 if ( item ) { 34 media.frame.trigger( 'edit:attachment', item );47 frame.trigger( 'edit:attachment', item ); 35 48 } else { 36 49 item = media.attachment( query ); 37 media.frame.listenTo( item, 'change', function( model ) {38 media.frame.stopListening( item );39 media.frame.trigger( 'edit:attachment', model );50 frame.listenTo( item, 'change', function( model ) { 51 frame.stopListening( item ); 52 frame.trigger( 'edit:attachment', model ); 40 53 } ); 41 54 item.fetch(); 42 55 } 56 }, 57 58 // Show the modal in edit mode with a specific item. 59 editItem: function( query ) { 60 this.showItem( query ); 61 wp.media.frames.edit.content.mode( 'edit-details' ); 43 62 } 44 63 }); -
trunk/src/wp-includes/js/media/views/attachment/details-two-column.js
r33337 r41021 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 }, -
trunk/src/wp-includes/js/media/views/frame/edit-attachments.js
r33337 r41021 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 … … 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 … … 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 }, … … 126 134 }) ); 127 135 128 // Update browser url when navigating media details 129 if ( this.model ) {136 // Update browser url when navigating media details, except on load. 137 if ( this.model && ! this.model.get( 'skipHistory' ) ) { 130 138 this.gridRouter.navigate( this.gridRouter.baseUrl( '?item=' + this.model.id ) ); 131 139 } … … 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 … … 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' ) { … … 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 }, … … 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 }, … … 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 this.gridRouter.navigate( this.gridRouter.baseUrl( url ), { replace: true } ); 238 255 } 239 256 }); -
trunk/src/wp-includes/js/media/views/frame/manage.js
r40359 r41021 82 82 this.render(); 83 83 this.bindSearchHandler(); 84 85 wp.media.frames.browse = this; 84 86 }, 85 87 86 88 bindSearchHandler: function() { 87 89 var search = this.$( '#media-search-input' ), 88 currentSearch = this.options.container.data( 'search' ),89 90 searchView = this.browserView.toolbar.get( 'search' ).$el, 90 91 listMode = this.$( '.view-list' ), 91 92 92 input = _. debounce( function (e) {93 input = _.throttle( function (e) { 93 94 var val = $( e.currentTarget ).val(), 94 95 url = ''; … … 96 97 if ( val ) { 97 98 url += '?search=' + val; 99 this.gridRouter.navigate( this.gridRouter.baseUrl( url ), { replace: true } ); 98 100 } 99 this.gridRouter.navigate( this.gridRouter.baseUrl( url ) );100 101 }, 1000 ); 101 102 102 103 // Update the URL when entering search string (at most once per second) 103 104 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 } ); 105 106 this.gridRouter 107 .on( 'route:search', function () { 108 var href = window.location.href; 109 if ( href.indexOf( 'mode=' ) > -1 ) { 110 href = href.replace( /mode=[^&]+/g, 'mode=list' ); 111 } else { 112 href += href.indexOf( '?' ) > -1 ? '&mode=list' : '?mode=list'; 113 } 114 href = href.replace( 'search=', 's=' ); 115 listMode.prop( 'href', href ); 116 }) 117 .on( 'route:reset', function() { 118 searchView.val( '' ).trigger( 'input' ); 119 }); 116 120 }, 117 121 … … 205 209 openEditAttachmentModal: function( model ) { 206 210 // 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 } ); 211 if ( wp.media.frames.edit ) { 212 wp.media.frames.edit.open().trigger( 'refresh', model ); 213 } else { 214 wp.media.frames.edit = wp.media( { 215 frame: 'edit-attachments', 216 controller: this, 217 library: this.state().get('library'), 218 model: model 219 } ); 220 } 213 221 }, 214 222
Note: See TracChangeset
for help on using the changeset viewer.