Make WordPress Core

Changeset 22568


Ignore:
Timestamp:
11/14/2012 09:06:10 AM (14 years ago)
Author:
koopersmith
Message:

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

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/media.php

    r22541 r22568  
    384384 */
    385385function media_buttons($editor_id = 'content') {
    386         wp_enqueue_media();
     386        wp_enqueue_media( array(
     387                'post' => get_post()
     388        ) );
    387389
    388390        $context = apply_filters('media_buttons_context', __('Upload/Insert %s'));
  • trunk/wp-admin/js/media-upload.js

    r22567 r22568  
    213213
    214214                return {
    215                         attachments: function( shortcode, parent ) {
     215                        defaults: {
     216                                order:      'ASC',
     217                                orderby:    'post__in',
     218                                id:         wp.media.view.settings.postId,
     219                                itemtag:    'dl',
     220                                icontag:    'dt',
     221                                captiontag: 'dd',
     222                                columns:    3,
     223                                size:       'thumbnail'
     224                        },
     225
     226                        attachments: function( shortcode ) {
    216227                                var shortcodeString = shortcode.string(),
    217228                                        result = galleries[ shortcodeString ],
    … …  
    241252
    242253                                if ( ! args.post__in )
    243                                         args.parent = attrs.id || parent;
     254                                        args.parent = attrs.id;
    244255
    245256                                // Collect the attributes that were not included in `args`.
    … …  
    284295
    285296                                return shortcode;
     297                        },
     298
     299                        edit: function( content ) {
     300                                var shortcode = wp.shortcode.next( 'gallery', content ),
     301                                        defaultPostId = wp.media.gallery.defaults.postId,
     302                                        attachments, selection;
     303
     304                                // Bail if we didn't match the shortcode or all of the content.
     305                                if ( ! shortcode || shortcode.content !== content )
     306                                        return;
     307
     308                                // Ignore the rest of the match object.
     309                                shortcode = shortcode.shortcode;
     310
     311                                if ( _.isUndefined( shortcode.get('id') ) && ! _.isUndefined( defaultPostId ) )
     312                                        shortcode.set( 'id', defaultPostId );
     313
     314                                attachments = wp.media.gallery.attachments( shortcode );
     315
     316                                selection = new wp.media.model.Selection( attachments.models, {
     317                                        props:    attachments.props.toJSON(),
     318                                        multiple: true
     319                                });
     320
     321                                selection.gallery = attachments.gallery;
     322
     323                                return wp.media({
     324                                        frame:     'post',
     325                                        state:     'gallery-edit',
     326                                        title:     wp.media.view.l10n.editGalleryTitle,
     327                                        editing:   true,
     328                                        multiple:  true,
     329                                        selection: selection
     330                                });
    286331                        }
    287332                };
  • trunk/wp-includes/js/tinymce/plugins/wpgallery/editor_plugin_src.js

    r20519 r22568  
    1111                        // Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('...');
    1212                        ed.addCommand('WP_Gallery', function() {
    13                                 var el = ed.selection.getNode(), post_id, vp = tinymce.DOM.getViewPort(),
    14                                         H = vp.h - 80, W = ( 640 < vp.w ) ? 640 : vp.w;
     13                                var el = ed.selection.getNode(),
     14                                        gallery = wp.media.gallery,
     15                                        frame;
    1516
    16                                 if ( el.nodeName != 'IMG' ) return;
    17                                 if ( ed.dom.getAttrib(el, 'class').indexOf('wpGallery') == -1 ) return;
     17                                // Check if the `wp.media.gallery` API exists.
     18                                if ( typeof wp === 'undefined' || ! wp.media || ! wp.media.gallery )
     19                                        return;
    1820
    19                                 post_id = tinymce.DOM.get('post_ID').value;
    20                                 tb_show('', tinymce.documentBaseURL + 'media-upload.php?post_id='+post_id+'&tab=gallery&TB_iframe=true&width='+W+'&height='+H);
     21                                // Make sure we've selected a gallery node.
     22                                if ( el.nodeName != 'IMG' || ed.dom.getAttrib(el, 'class').indexOf('wpGallery') == -1 )
     23                                        return;
    2124
    22                                 tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
     25                                frame = gallery.edit( '[' + ed.dom.getAttrib( el, 'title' ) + ']' );
     26
     27                                frame.get('gallery-edit').on( 'update', function( selection ) {
     28                                        var shortcode = gallery.shortcode( selection ).string().slice( 1, -1 );
     29                                        ed.dom.setAttrib( el, 'title', shortcode );
     30                                });
    2331                        });
    2432
  • trunk/wp-includes/media.php

    r22557 r22568  
    13011301 * @since 3.5.0
    13021302 */
    1303 function wp_enqueue_media() {
     1303function wp_enqueue_media( $args = array() ) {
     1304        $defaults = array(
     1305                'post' => null,
     1306        );
     1307        $args = wp_parse_args( $args, $defaults );
     1308
    13041309        // We're going to pass the old thickbox media tabs to `media_upload_tabs`
    13051310        // to ensure plugins will work. We will then unset those tabs.
    … …  
    13211326                ), admin_url('media-upload.php') ),
    13221327        );
     1328
     1329        if ( isset( $args['post'] ) )
     1330                $settings['postId'] = get_post( $args['post'] )->ID;
    13231331
    13241332        wp_localize_script( 'media-views', '_wpMediaViewsL10n', array(
Note: See TracChangeset for help on using the changeset viewer.