mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-28 12:07:36 +01:00
d9a2e85bfe
* specify globals in more files * add missing `wp.media.*` namespace docs * add doc blocks to files that had none See #28510. Built from https://develop.svn.wordpress.org/trunk@31492 git-svn-id: http://core.svn.wordpress.org/trunk@31473 1a063a9b-81f0-0310-95a4-ce76da25c4cd
49 lines
1.2 KiB
JavaScript
49 lines
1.2 KiB
JavaScript
/*globals wp, Backbone */
|
|
|
|
/**
|
|
* wp.media.view.MediaFrame.Manage.Router
|
|
*
|
|
* A router for handling the browser history and application state.
|
|
*
|
|
* @class
|
|
* @augments Backbone.Router
|
|
*/
|
|
var Router = Backbone.Router.extend({
|
|
routes: {
|
|
'upload.php?item=:slug': 'showItem',
|
|
'upload.php?search=:query': 'search'
|
|
},
|
|
|
|
// Map routes against the page URL
|
|
baseUrl: function( url ) {
|
|
return 'upload.php' + url;
|
|
},
|
|
|
|
// Respond to the search route by filling the search field and trigggering the input event
|
|
search: function( query ) {
|
|
jQuery( '#media-search-input' ).val( query ).trigger( 'input' );
|
|
},
|
|
|
|
// Show the modal with a specific item
|
|
showItem: function( query ) {
|
|
var media = wp.media,
|
|
library = media.frame.state().get('library'),
|
|
item;
|
|
|
|
// Trigger the media frame to open the correct item
|
|
item = library.findWhere( { id: parseInt( query, 10 ) } );
|
|
if ( item ) {
|
|
media.frame.trigger( 'edit:attachment', item );
|
|
} else {
|
|
item = media.attachment( query );
|
|
media.frame.listenTo( item, 'change', function( model ) {
|
|
media.frame.stopListening( item );
|
|
media.frame.trigger( 'edit:attachment', model );
|
|
} );
|
|
item.fetch();
|
|
}
|
|
}
|
|
});
|
|
|
|
module.exports = Router;
|