Changeset 33342
- Timestamp:
- 07/21/2015 03:09:28 PM (10 years ago)
- Location:
- trunk/src/wp-includes/js
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/js/media-grid.js
r33337 r33342 50 50 */ 51 51 var Router = Backbone.Router.extend({ 52 initialize: function ( options ) {53 this.controller = options.controller;54 this.library = options.library;55 this.on( 'route', this.checkRoute );56 },57 58 52 routes: { 59 53 'upload.php?item=:slug': 'showItem', 60 'upload.php?search=:query': 'search', 61 'upload.php': 'defaultRoute' 62 }, 63 64 checkRoute: function ( event ) { 65 if ( 'defaultRoute' !== event ) { 66 this.modal = true; 67 } 68 }, 69 70 defaultRoute: function () { 71 if ( this.modal ) { 72 wp.media.frame.close(); 73 this.modal = false; 74 } 54 'upload.php?search=:query': 'search' 75 55 }, 76 56 … … 87 67 // Show the modal with a specific item 88 68 showItem: function( query ) { 89 var frame = this.controller, 69 var media = wp.media, 70 library = media.frame.state().get('library'), 90 71 item; 91 72 92 73 // Trigger the media frame to open the correct item 93 item = this.library.findWhere( { id: parseInt( query, 10 ) } );74 item = library.findWhere( { id: parseInt( query, 10 ) } ); 94 75 if ( item ) { 95 frame.trigger( 'edit:attachment', item );76 media.frame.trigger( 'edit:attachment', item ); 96 77 } else { 97 item = wp.media.attachment( query );98 frame.listenTo( item, 'change', function( model ) {99 frame.stopListening( item );100 frame.trigger( 'edit:attachment', model );78 item = media.attachment( query ); 79 media.frame.listenTo( item, 'change', function( model ) { 80 media.frame.stopListening( item ); 81 media.frame.trigger( 'edit:attachment', model ); 101 82 } ); 102 83 item.fetch(); … … 665 646 }).render(); 666 647 this.uploader.ready(); 667 this.$body.append( this.uploader.el );648 $('body').append( this.uploader.el ); 668 649 669 650 this.options.uploader = false; 670 651 } 652 653 this.gridRouter = new wp.media.view.MediaFrame.Manage.Router(); 671 654 672 655 // Call 'initialize' directly on the parent class. … … 676 659 this.$el.appendTo( this.options.container ); 677 660 678 this.setLibrary( this.options );679 this.setRouter();680 661 this.createStates(); 681 662 this.bindRegionModeHandlers(); 682 663 this.render(); 683 664 this.bindSearchHandler(); 684 },685 686 setLibrary: function ( options ) {687 this.library = wp.media.query( options.library );688 },689 690 setRouter: function () {691 this.gridRouter = new wp.media.view.MediaFrame.Manage.Router({692 controller: this,693 library: this.library694 });695 665 }, 696 666 … … 713 683 // Update the URL when entering search string (at most once per second) 714 684 search.on( 'input', _.bind( input, this ) ); 715 if ( currentSearch ) { 716 searchView.val( currentSearch ).trigger( 'input' ); 717 } 685 searchView.val( currentSearch ).trigger( 'input' ); 718 686 719 687 this.gridRouter.on( 'route:search', function () { … … 742 710 this.states.add([ 743 711 new Library({ 744 library: this.library,712 library: wp.media.query( options.library ), 745 713 multiple: options.multiple, 746 714 title: options.title, -
trunk/src/wp-includes/js/media/routers/manage.js
r33337 r33342 8 8 */ 9 9 var Router = Backbone.Router.extend({ 10 initialize: function ( options ) {11 this.controller = options.controller;12 this.library = options.library;13 this.on( 'route', this.checkRoute );14 },15 16 10 routes: { 17 11 'upload.php?item=:slug': 'showItem', 18 'upload.php?search=:query': 'search', 19 'upload.php': 'defaultRoute' 20 }, 21 22 checkRoute: function ( event ) { 23 if ( 'defaultRoute' !== event ) { 24 this.modal = true; 25 } 26 }, 27 28 defaultRoute: function () { 29 if ( this.modal ) { 30 wp.media.frame.close(); 31 this.modal = false; 32 } 12 'upload.php?search=:query': 'search' 33 13 }, 34 14 … … 45 25 // Show the modal with a specific item 46 26 showItem: function( query ) { 47 var frame = this.controller, 27 var media = wp.media, 28 library = media.frame.state().get('library'), 48 29 item; 49 30 50 31 // Trigger the media frame to open the correct item 51 item = this.library.findWhere( { id: parseInt( query, 10 ) } );32 item = library.findWhere( { id: parseInt( query, 10 ) } ); 52 33 if ( item ) { 53 frame.trigger( 'edit:attachment', item );34 media.frame.trigger( 'edit:attachment', item ); 54 35 } else { 55 item = wp.media.attachment( query );56 frame.listenTo( item, 'change', function( model ) {57 frame.stopListening( item );58 frame.trigger( 'edit:attachment', model );36 item = media.attachment( query ); 37 media.frame.listenTo( item, 'change', function( model ) { 38 media.frame.stopListening( item ); 39 media.frame.trigger( 'edit:attachment', model ); 59 40 } ); 60 41 item.fetch(); -
trunk/src/wp-includes/js/media/views/frame/manage.js
r33337 r33342 61 61 }).render(); 62 62 this.uploader.ready(); 63 this.$body.append( this.uploader.el );63 $('body').append( this.uploader.el ); 64 64 65 65 this.options.uploader = false; 66 66 } 67 68 this.gridRouter = new wp.media.view.MediaFrame.Manage.Router(); 67 69 68 70 // Call 'initialize' directly on the parent class. … … 72 74 this.$el.appendTo( this.options.container ); 73 75 74 this.setLibrary( this.options );75 this.setRouter();76 76 this.createStates(); 77 77 this.bindRegionModeHandlers(); 78 78 this.render(); 79 79 this.bindSearchHandler(); 80 },81 82 setLibrary: function ( options ) {83 this.library = wp.media.query( options.library );84 },85 86 setRouter: function () {87 this.gridRouter = new wp.media.view.MediaFrame.Manage.Router({88 controller: this,89 library: this.library90 });91 80 }, 92 81 … … 109 98 // Update the URL when entering search string (at most once per second) 110 99 search.on( 'input', _.bind( input, this ) ); 111 if ( currentSearch ) { 112 searchView.val( currentSearch ).trigger( 'input' ); 113 } 100 searchView.val( currentSearch ).trigger( 'input' ); 114 101 115 102 this.gridRouter.on( 'route:search', function () { … … 138 125 this.states.add([ 139 126 new Library({ 140 library: this.library,127 library: wp.media.query( options.library ), 141 128 multiple: options.multiple, 142 129 title: options.title,
Note: See TracChangeset
for help on using the changeset viewer.