Ticket #24716: 24716.24.diff
File 24716.24.diff, 4.7 KB (added by , 10 years ago) |
---|
-
src/wp-admin/upload.php
24 24 wp_enqueue_media(); 25 25 wp_enqueue_script( 'media-grid' ); 26 26 wp_enqueue_script( 'media' ); 27 wp_localize_script( 'media-grid', 'mediaGridSettings', array( 'adminUrl' => parse_url( self_admin_url(), PHP_URL_PATH ) ) ); 27 28 28 29 require_once( ABSPATH . 'wp-admin/admin-header.php' ); 29 30 include( ABSPATH . 'wp-admin/admin-footer.php' ); -
src/wp-includes/js/media-grid.js
120 120 * @global wp.Uploader 121 121 */ 122 122 initialize: function() { 123 var self = this; 123 124 _.defaults( this.options, { 124 125 title: l10n.mediaLibraryTitle, 125 126 modal: false, … … 168 169 this.createStates(); 169 170 this.bindHandlers(); 170 171 this.render(); 172 173 _.defer( function(){ 174 wp.media.mediarouter = new media.view.Frame.Router( self ); 175 if ( window.history && window.history.pushState ) { 176 Backbone.history.start({ 177 root: mediaGridSettings.adminUrl, 178 pushState: true 179 }); 180 } 181 }); 182 183 $( '#media-search-input' ).on( 'input', _.debounce( function() { 184 wp.media.mediarouter.searchWith( this ); 185 }, 250) ) 186 171 187 }, 172 188 173 189 createSelection: function() { … … 210 226 bindHandlers: function() { 211 227 this.on( 'content:create:browse', this.browseContent, this ); 212 228 this.on( 'content:render:edit-image', this.editImageContent, this ); 229 this.on( 'input #media-search-input', this.search, this ); 213 230 231 214 232 // Handle a frame-level event for editing an attachment. 215 233 this.on( 'edit:attachment', this.editAttachment, this ); 216 234 this.on( 'edit:attachment:next', this.editNextAttachment, this ); … … 324 342 }); 325 343 326 344 /** 345 * A router for handling the browser history and application state 346 */ 347 media.view.Frame.Router = Backbone.Router.extend({ 348 349 initialize: function( passedview ){ 350 this.passedview = passedview; 351 }, 352 353 passedview: '', 354 355 routes: { 356 'upload.php?image=:slug': 'showimage', 357 'upload.php?search=:query': 'search' 358 }, 359 360 baseUrl: function( url ) { 361 return 'upload.php' + url; 362 }, 363 364 search: function( query ) { 365 $( '#media-search-input' ).val( query ).trigger( 'input' ); 366 }, 367 368 searchWith: function( s ) { 369 this.navigate( this.baseUrl( '?search=' + $( s ).val() ), {trigger: false, replace: false} ); 370 }, 371 372 showimage: function( query ) { 373 var library = this.passedview.state().get('library'); 374 this.passedview.trigger( 'edit:attachment', library.findWhere( { id: parseInt( query ) } ) ); 375 }, 376 377 }); 378 379 380 /** 327 381 * A frame for editing the details of a specific media item. 328 382 * 329 383 * Opens in a modal by default. … … 340 394 'click': 'collapse', 341 395 'click .delete-media-item': 'deleteMediaItem', 342 396 'click .left': 'previousMediaItem', 343 'click .right': 'nextMediaItem' 344 }, 397 'click .right': 'nextMediaItem', 398 'keydown': 'keyEvent' 399 }, 345 400 346 401 initialize: function() { 347 402 var self = this; … … 373 428 // Completely destroy the modal DOM element when closing it. 374 429 this.modal.close = function() { 375 430 self.modal.remove(); 431 // Reset the browser URL 376 432 }; 377 433 378 434 this.modal.content( this ); 379 435 this.modal.open(); 436 437 // Update browser url when navigating media details 438 wp.media.mediarouter.navigate( wp.media.mediarouter.baseUrl( '?image=' + this.options.model.id ), {trigger: false, replace: false} ); 439 440 // Ensure modal gains focus, otherwise keyboard events lost 441 $( '.attachment-fields input:first' ).focus(); 442 $( '.media-modal-backdrop, .media-modal-close' ).on( 'click', function() { 443 self.resetRoute(); 444 } ); 380 445 } 381 446 }, 382 447 … … 482 547 return; 483 548 this.modal.close(); 484 549 this.options.gridController.trigger( 'edit:attachment:next', this.model ); 550 }, 551 /** 552 * Respond to the keyboard events: right arrow, left arrow, escape . 553 */ 554 keyEvent: function( event ) { 555 // The right arrow key 556 if ( event.keyCode === 39 ) { 557 if ( ! this.options.hasNext ) { return; } 558 _.once( this.nextMediaItem() ); 559 } 560 561 // The left arrow key 562 if ( event.keyCode === 37 ) { 563 if ( ! this.options.hasPrevious ) { return; } 564 _.once( this.previousMediaItem() ); 565 } 566 // Pressing the escape key routes back to main url 567 if ( event.keyCode === 27 ) { 568 this.resetRoute(); 569 return event; 570 } 571 }, 572 573 resetRoute: function() { 574 wp.media.mediarouter.navigate( wp.media.mediarouter.baseUrl( '' ), { trigger: false } ); 575 return; 485 576 } 486 577 487 578 });