Changeset 32466
- Timestamp:
- 05/09/2015 05:41:01 AM (11 years ago)
- Location:
- trunk/src/wp-includes/js
- Files:
-
- 3 edited
-
media-grid.js (modified) (6 diffs)
-
media/routers/manage.js (modified) (2 diffs)
-
media/views/frame/manage.js (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/js/media-grid.js
r32125 r32466 56 56 */ 57 57 var Router = Backbone.Router.extend({ 58 initialize: function ( options ) { 59 this.controller = options.controller; 60 this.library = options.library; 61 this.on( 'route', this.checkRoute ); 62 }, 63 58 64 routes: { 59 65 'upload.php?item=:slug': 'showItem', 60 'upload.php?search=:query': 'search' 66 'upload.php?search=:query': 'search', 67 'upload.php': 'defaultRoute' 68 }, 69 70 checkRoute: function ( event ) { 71 if ( 'defaultRoute' !== event ) { 72 this.modal = true; 73 } 74 }, 75 76 defaultRoute: function () { 77 if ( this.modal ) { 78 wp.media.frame.close(); 79 this.modal = false; 80 } 61 81 }, 62 82 … … 73 93 // Show the modal with a specific item 74 94 showItem: function( query ) { 75 var media = wp.media, 76 library = media.frame.state().get('library'), 95 var frame = this.controller, 77 96 item; 78 97 79 98 // Trigger the media frame to open the correct item 80 item = library.findWhere( { id: parseInt( query, 10 ) } );99 item = this.library.findWhere( { id: parseInt( query, 10 ) } ); 81 100 if ( item ) { 82 media.frame.trigger( 'edit:attachment', item );101 frame.trigger( 'edit:attachment', item ); 83 102 } else { 84 item = media.attachment( query );85 media.frame.listenTo( item, 'change', function( model ) {86 media.frame.stopListening( item );87 media.frame.trigger( 'edit:attachment', model );103 item = wp.media.attachment( query ); 104 frame.listenTo( item, 'change', function( model ) { 105 frame.stopListening( item ); 106 frame.trigger( 'edit:attachment', model ); 88 107 } ); 89 108 item.fetch(); … … 656 675 }).render(); 657 676 this.uploader.ready(); 658 $('body').append( this.uploader.el );677 this.$body.append( this.uploader.el ); 659 678 660 679 this.options.uploader = false; 661 680 } 662 663 this.gridRouter = new wp.media.view.MediaFrame.Manage.Router();664 681 665 682 // Call 'initialize' directly on the parent class. … … 669 686 this.$el.appendTo( this.options.container ); 670 687 688 this.setLibrary( this.options ); 689 this.setRouter(); 671 690 this.createStates(); 672 691 this.bindRegionModeHandlers(); 673 692 this.render(); 674 693 this.bindSearchHandler(); 694 }, 695 696 setLibrary: function ( options ) { 697 this.library = wp.media.query( options.library ); 698 }, 699 700 setRouter: function () { 701 this.gridRouter = new wp.media.view.MediaFrame.Manage.Router({ 702 controller: this, 703 library: this.library 704 }); 675 705 }, 676 706 … … 693 723 // Update the URL when entering search string (at most once per second) 694 724 search.on( 'input', _.bind( input, this ) ); 695 searchView.val( currentSearch ).trigger( 'input' ); 725 if ( currentSearch ) { 726 searchView.val( currentSearch ).trigger( 'input' ); 727 } 696 728 697 729 this.gridRouter.on( 'route:search', function () { … … 720 752 this.states.add([ 721 753 new Library({ 722 library: wp.media.query( options.library ),754 library: this.library, 723 755 multiple: options.multiple, 724 756 title: options.title, -
trunk/src/wp-includes/js/media/routers/manage.js
r31492 r32466 10 10 */ 11 11 var Router = Backbone.Router.extend({ 12 initialize: function ( options ) { 13 this.controller = options.controller; 14 this.library = options.library; 15 this.on( 'route', this.checkRoute ); 16 }, 17 12 18 routes: { 13 19 'upload.php?item=:slug': 'showItem', 14 'upload.php?search=:query': 'search' 20 'upload.php?search=:query': 'search', 21 'upload.php': 'defaultRoute' 22 }, 23 24 checkRoute: function ( event ) { 25 if ( 'defaultRoute' !== event ) { 26 this.modal = true; 27 } 28 }, 29 30 defaultRoute: function () { 31 if ( this.modal ) { 32 wp.media.frame.close(); 33 this.modal = false; 34 } 15 35 }, 16 36 … … 27 47 // Show the modal with a specific item 28 48 showItem: function( query ) { 29 var media = wp.media, 30 library = media.frame.state().get('library'), 49 var frame = this.controller, 31 50 item; 32 51 33 52 // Trigger the media frame to open the correct item 34 item = library.findWhere( { id: parseInt( query, 10 ) } );53 item = this.library.findWhere( { id: parseInt( query, 10 ) } ); 35 54 if ( item ) { 36 media.frame.trigger( 'edit:attachment', item );55 frame.trigger( 'edit:attachment', item ); 37 56 } else { 38 item = media.attachment( query );39 media.frame.listenTo( item, 'change', function( model ) {40 media.frame.stopListening( item );41 media.frame.trigger( 'edit:attachment', model );57 item = wp.media.attachment( query ); 58 frame.listenTo( item, 'change', function( model ) { 59 frame.stopListening( item ); 60 frame.trigger( 'edit:attachment', model ); 42 61 } ); 43 62 item.fetch(); -
trunk/src/wp-includes/js/media/views/frame/manage.js
r31935 r32466 63 63 }).render(); 64 64 this.uploader.ready(); 65 $('body').append( this.uploader.el );65 this.$body.append( this.uploader.el ); 66 66 67 67 this.options.uploader = false; 68 68 } 69 70 this.gridRouter = new wp.media.view.MediaFrame.Manage.Router();71 69 72 70 // Call 'initialize' directly on the parent class. … … 76 74 this.$el.appendTo( this.options.container ); 77 75 76 this.setLibrary( this.options ); 77 this.setRouter(); 78 78 this.createStates(); 79 79 this.bindRegionModeHandlers(); 80 80 this.render(); 81 81 this.bindSearchHandler(); 82 }, 83 84 setLibrary: function ( options ) { 85 this.library = wp.media.query( options.library ); 86 }, 87 88 setRouter: function () { 89 this.gridRouter = new wp.media.view.MediaFrame.Manage.Router({ 90 controller: this, 91 library: this.library 92 }); 82 93 }, 83 94 … … 100 111 // Update the URL when entering search string (at most once per second) 101 112 search.on( 'input', _.bind( input, this ) ); 102 searchView.val( currentSearch ).trigger( 'input' ); 113 if ( currentSearch ) { 114 searchView.val( currentSearch ).trigger( 'input' ); 115 } 103 116 104 117 this.gridRouter.on( 'route:search', function () { … … 127 140 this.states.add([ 128 141 new Library({ 129 library: wp.media.query( options.library ),142 library: this.library, 130 143 multiple: options.multiple, 131 144 title: options.title,
Note: See TracChangeset
for help on using the changeset viewer.