2015-02-22 01:56:27 -05:00
|
|
|
/*globals wp, Backbone */
|
|
|
|
|
2015-02-08 19:43:50 -05:00
|
|
|
/**
|
2015-02-22 02:25:27 -05:00
|
|
|
* wp.media.view.MediaFrame.Manage.Router
|
|
|
|
*
|
2015-02-08 19:43:50 -05:00
|
|
|
* A router for handling the browser history and application state.
|
|
|
|
*
|
2015-02-22 01:28:26 -05:00
|
|
|
* @class
|
2015-02-08 19:43:50 -05:00
|
|
|
* @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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-02-09 11:01:29 -05:00
|
|
|
module.exports = Router;
|