Media: Make edit gallery button use new media. see #21390.

git-svn-id: http://core.svn.wordpress.org/trunk@22568 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Daryl Koopersmith 2012-11-14 09:06:10 +00:00
parent b2db6270ee
commit fd6b847330
4 changed files with 74 additions and 11 deletions

View File

@ -383,7 +383,9 @@ document.body.className = document.body.className.replace('no-js', 'js');
* @param string $editor_id * @param string $editor_id
*/ */
function media_buttons($editor_id = 'content') { function media_buttons($editor_id = 'content') {
wp_enqueue_media(); wp_enqueue_media( array(
'post' => get_post()
) );
$context = apply_filters('media_buttons_context', __('Upload/Insert %s')); $context = apply_filters('media_buttons_context', __('Upload/Insert %s'));

View File

@ -212,7 +212,18 @@ var tb_position;
var galleries = {}; var galleries = {};
return { return {
attachments: function( shortcode, parent ) { defaults: {
order: 'ASC',
orderby: 'post__in',
id: wp.media.view.settings.postId,
itemtag: 'dl',
icontag: 'dt',
captiontag: 'dd',
columns: 3,
size: 'thumbnail'
},
attachments: function( shortcode ) {
var shortcodeString = shortcode.string(), var shortcodeString = shortcode.string(),
result = galleries[ shortcodeString ], result = galleries[ shortcodeString ],
attrs, args, query, others; attrs, args, query, others;
@ -240,7 +251,7 @@ var tb_position;
args.post__not_in = attrs.exclude.split(','); args.post__not_in = attrs.exclude.split(',');
if ( ! args.post__in ) if ( ! args.post__in )
args.parent = attrs.id || parent; args.parent = attrs.id;
// Collect the attributes that were not included in `args`. // Collect the attributes that were not included in `args`.
others = {}; others = {};
@ -283,6 +294,40 @@ var tb_position;
galleries[ shortcode.string() ] = clone; galleries[ shortcode.string() ] = clone;
return shortcode; return shortcode;
},
edit: function( content ) {
var shortcode = wp.shortcode.next( 'gallery', content ),
defaultPostId = wp.media.gallery.defaults.postId,
attachments, selection;
// Bail if we didn't match the shortcode or all of the content.
if ( ! shortcode || shortcode.content !== content )
return;
// Ignore the rest of the match object.
shortcode = shortcode.shortcode;
if ( _.isUndefined( shortcode.get('id') ) && ! _.isUndefined( defaultPostId ) )
shortcode.set( 'id', defaultPostId );
attachments = wp.media.gallery.attachments( shortcode );
selection = new wp.media.model.Selection( attachments.models, {
props: attachments.props.toJSON(),
multiple: true
});
selection.gallery = attachments.gallery;
return wp.media({
frame: 'post',
state: 'gallery-edit',
title: wp.media.view.l10n.editGalleryTitle,
editing: true,
multiple: true,
selection: selection
});
} }
}; };
}()); }());

View File

@ -10,16 +10,24 @@
// Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('...'); // Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('...');
ed.addCommand('WP_Gallery', function() { ed.addCommand('WP_Gallery', function() {
var el = ed.selection.getNode(), post_id, vp = tinymce.DOM.getViewPort(), var el = ed.selection.getNode(),
H = vp.h - 80, W = ( 640 < vp.w ) ? 640 : vp.w; gallery = wp.media.gallery,
frame;
if ( el.nodeName != 'IMG' ) return; // Check if the `wp.media.gallery` API exists.
if ( ed.dom.getAttrib(el, 'class').indexOf('wpGallery') == -1 ) return; if ( typeof wp === 'undefined' || ! wp.media || ! wp.media.gallery )
return;
post_id = tinymce.DOM.get('post_ID').value; // Make sure we've selected a gallery node.
tb_show('', tinymce.documentBaseURL + 'media-upload.php?post_id='+post_id+'&tab=gallery&TB_iframe=true&width='+W+'&height='+H); if ( el.nodeName != 'IMG' || ed.dom.getAttrib(el, 'class').indexOf('wpGallery') == -1 )
return;
tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' ); frame = gallery.edit( '[' + ed.dom.getAttrib( el, 'title' ) + ']' );
frame.get('gallery-edit').on( 'update', function( selection ) {
var shortcode = gallery.shortcode( selection ).string().slice( 1, -1 );
ed.dom.setAttrib( el, 'title', shortcode );
});
}); });
ed.onMouseDown.add(function(ed, e) { ed.onMouseDown.add(function(ed, e) {

View File

@ -1300,7 +1300,12 @@ function wp_prepare_attachment_for_js( $attachment ) {
* *
* @since 3.5.0 * @since 3.5.0
*/ */
function wp_enqueue_media() { function wp_enqueue_media( $args = array() ) {
$defaults = array(
'post' => null,
);
$args = wp_parse_args( $args, $defaults );
// We're going to pass the old thickbox media tabs to `media_upload_tabs` // We're going to pass the old thickbox media tabs to `media_upload_tabs`
// to ensure plugins will work. We will then unset those tabs. // to ensure plugins will work. We will then unset those tabs.
$tabs = array( $tabs = array(
@ -1321,6 +1326,9 @@ function wp_enqueue_media() {
), admin_url('media-upload.php') ), ), admin_url('media-upload.php') ),
); );
if ( isset( $args['post'] ) )
$settings['postId'] = get_post( $args['post'] )->ID;
wp_localize_script( 'media-views', '_wpMediaViewsL10n', array( wp_localize_script( 'media-views', '_wpMediaViewsL10n', array(
// Settings // Settings
'settings' => $settings, 'settings' => $settings,