Make WordPress Core

Changeset 22496


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

Media: Update featured images to use the media frame. fixes #21776, see #21390.

File:
1 edited

Legend:

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

    r22396 r22496  
    10101010                        title        = '<?php _e( "Choose a Featured Image" ); ?>',
    10111011                        update       = '<?php _e( "Update Featured Image" ); ?>',
    1012                         frame, selection, setFeaturedImage;
     1012                        frame, setFeaturedImage;
    10131013
    10141014                setFeaturedImage = function( thumbnailId ) {
     
    10211021                        event.preventDefault();
    10221022
    1023                         if ( ! frame ) {
    1024                                 frame = wp.media({
    1025                                         title:   title,
    1026                                         library: {
    1027                                                 type: 'image'
     1023                        if ( frame ) {
     1024                                frame.open();
     1025                                return;
     1026                        }
     1027
     1028                        frame = wp.media({
     1029                                title:     title,
     1030                                selection: [ wp.media.model.Attachment.get( $thumbnailId.val() ) ],
     1031                                library:   {
     1032                                        type: 'image'
     1033                                }
     1034                        });
     1035
     1036                        frame.toolbar.on( 'activate:select', function() {
     1037                                frame.toolbar.view().add({
     1038                                        select: {
     1039                                                text: update,
     1040
     1041                                                click: function() {
     1042                                                        var selection = frame.state().get('selection'),
     1043                                                                model = selection.first(),
     1044                                                                sizes = model.get('sizes'),
     1045                                                                size;
     1046
     1047                                                        setFeaturedImage( model.id );
     1048
     1049                                                        // @todo: might need a size hierarchy equivalent.
     1050                                                        if ( sizes )
     1051                                                                size = sizes['post-thumbnail'] || sizes.medium;
     1052
     1053                                                        // @todo: Need a better way of accessing full size
     1054                                                        // data besides just calling toJSON().
     1055                                                        size = size || model.toJSON();
     1056
     1057                                                        frame.close();
     1058
     1059                                                        $( '<img />', {
     1060                                                                src:    size.url,
     1061                                                                width:  size.width
     1062                                                        }).prependTo( $element );
     1063                                                }
    10281064                                        }
    10291065                                });
    1030 
    1031                                 frame.toolbar( new wp.media.view.Toolbar({
    1032                                         controller: frame,
    1033                                         items: {
    1034                                                 update: {
    1035                                                         style:    'primary',
    1036                                                         text:     update,
    1037                                                         priority: 40,
    1038 
    1039                                                         click: function() {
    1040                                                                 var selection = frame.state().get('selection'),
    1041                                                                         model = selection.first(),
    1042                                                                         sizes = model.get('sizes'),
    1043                                                                         size;
    1044 
    1045                                                                 setFeaturedImage( model.id );
    1046 
    1047                                                                 // @todo: might need a size hierarchy equivalent.
    1048                                                                 if ( sizes )
    1049                                                                         size = sizes['post-thumbnail'] || sizes.medium;
    1050 
    1051                                                                 // @todo: Need a better way of accessing full size
    1052                                                                 // data besides just calling toJSON().
    1053                                                                 size = size || model.toJSON();
    1054 
    1055                                                                 frame.close();
    1056                                                                 selection.clear();
    1057 
    1058                                                                 $( '<img />', {
    1059                                                                         src:    size.url,
    1060                                                                         width:  size.width
    1061                                                                 }).prependTo( $element );
    1062                                                         }
    1063                                                 }
    1064                                         }
    1065                                 }) );
    1066                         }
    1067 
    1068                         frame.open();
     1066                        });
    10691067                });
    10701068
Note: See TracChangeset for help on using the changeset viewer.