Changeset 22496
- Timestamp:
- 11/09/2012 10:13:39 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/meta-boxes.php
r22396 r22496 1010 1010 title = '<?php _e( "Choose a Featured Image" ); ?>', 1011 1011 update = '<?php _e( "Update Featured Image" ); ?>', 1012 frame, se lection, setFeaturedImage;1012 frame, setFeaturedImage; 1013 1013 1014 1014 setFeaturedImage = function( thumbnailId ) { … … 1021 1021 event.preventDefault(); 1022 1022 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 } 1028 1064 } 1029 1065 }); 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 }); 1069 1067 }); 1070 1068
Note: See TracChangeset
for help on using the changeset viewer.