Media: Disable 'Insert gallery' and 'Set featured image' if nothing is queued. Converts selection toolbars to use the newer view manager. props koopersmith, fixes #22714.

git-svn-id: https://develop.svn.wordpress.org/trunk@23024 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin
2012-12-04 16:21:57 +00:00
parent d943307e5d
commit e961de8af5
4 changed files with 165 additions and 216 deletions
+23 -16
View File
@@ -18,30 +18,37 @@
var $el = $(this);
event.preventDefault();
// Create the media frame.
frame = wp.media({
title: $el.data('choose'),
library: {
// Set the title of the modal.
title: $el.data('choose'),
// Tell the modal to show only images.
library: {
type: 'image'
},
// Customize the submit button.
button: {
// Set the text of the button.
text: $el.data('update'),
// Tell the button not to close the modal, since we're
// going to refresh the page when the image is selected.
close: false
}
});
frame.on( 'toolbar:render:select', function( view ) {
view.set({
select: {
style: 'primary',
text: $el.data('update'),
// When an image is selected, run a callback.
frame.on( 'select', function() {
// Grab the selected attachment.
var attachment = frame.state().get('selection').first(),
link = $el.data('updateLink');
click: function() {
var attachment = frame.state().get('selection').first(),
link = $el.data('updateLink');
window.location = link + '&file=' + attachment.id;
}
}
});
// Tell the browser to navigate to the crop step.
window.location = link + '&file=' + attachment.id;
});
frame.setState('library').open();
frame.open();
});
});
}(jQuery));