Merge set-post-thumbnail-handler.js with post.js, move Post Thumbnail meta-box to /includes/meta-boxes.php, see #10928

git-svn-id: http://svn.automattic.com/wordpress/trunk@12060 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2009-10-19 20:23:35 +00:00
parent d3f3b6bed1
commit 76f6b9706e
9 changed files with 71 additions and 52 deletions

View File

@ -114,26 +114,6 @@ function get_image_send_to_editor($id, $caption, $title, $align, $url='', $rel =
return $html; return $html;
} }
function _wp_post_thumbnail_html( $thumbnail_id = NULL ) {
$content = '<p class="hide-if-no-js"><a href="#" id="set-post-thumbnail" onclick="jQuery(\'#add_image\').click();return false;">' . esc_html__( 'Set thumbnail' ) . '</a></p>';
if ( $thumbnail_id && get_post( $thumbnail_id ) ) {
$thumbnail_html = wp_get_attachment_image($thumbnail_id, array( 266, 266 ) );
if ( !empty( $thumbnail_html ) ) {
$content = '<a href="#" id="set-post-thumbnail" onclick="jQuery(\'#add_image\').click();return false;">' . $thumbnail_html . '</a>';
$content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail" onclick="WPRemoveThumbnail();return false;">' . esc_html__( 'Remove thumbnail' ) . '</a></p>';
}
}
return apply_filters( 'admin_post_thumbnail_html', $content );
}
function post_thumbnail_meta_box() {
global $post;
$thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true );
echo _wp_post_thumbnail_html( $thumbnail_id );
}
/** /**
* {@internal Missing Short Description}} * {@internal Missing Short Description}}
* *

View File

@ -807,3 +807,14 @@ function link_advanced_meta_box($link) {
</table> </table>
<?php <?php
} }
/**
* Display post thumbnail meta box.
*
* @since 2.9.0
*/
function post_thumbnail_meta_box() {
global $post;
$thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true );
echo _wp_post_thumbnail_html( $thumbnail_id );
}

View File

@ -1028,6 +1028,28 @@ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) {
return $return; return $return;
} }
/**
* Output HTML for the post thumbnail meta-box.
*
* @since 2.9.0
*
* @param int $thumbnail_id ID of the attachment used for thumbnail
* @return string html
*/
function _wp_post_thumbnail_html( $thumbnail_id = NULL ) {
$content = '<p class="hide-if-no-js"><a href="#" id="set-post-thumbnail" onclick="jQuery(\'#add_image\').click();return false;">' . esc_html__( 'Set thumbnail' ) . '</a></p>';
if ( $thumbnail_id && get_post( $thumbnail_id ) ) {
$thumbnail_html = wp_get_attachment_image($thumbnail_id, array( 266, 266 ) );
if ( !empty( $thumbnail_html ) ) {
$content = '<a href="#" id="set-post-thumbnail" onclick="jQuery(\'#add_image\').click();return false;">' . $thumbnail_html . '</a>';
$content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail" onclick="WPRemoveThumbnail();return false;">' . esc_html__( 'Remove thumbnail' ) . '</a></p>';
}
}
return apply_filters( 'admin_post_thumbnail_html', $content );
}
/** /**
* Check to see if the post is currently being edited by another user. * Check to see if the post is currently being edited by another user.
* *

View File

@ -55,6 +55,12 @@ $_old_files = array(
'wp-admin/js/link-cat.js', 'wp-admin/js/link-cat.js',
'wp-admin/js/forms.js', 'wp-admin/js/forms.js',
'wp-admin/js/upload.js', 'wp-admin/js/upload.js',
'wp-admin/js/set-post-thumbnail-handler.js',
'wp-admin/js/set-post-thumbnail-handler.dev.js',
'wp-admin/js/page.js',
'wp-admin/js/page.dev.js',
'wp-admin/js/slug.js',
'wp-admin/js/slug.dev.js',
'wp-admin/profile-update.php', 'wp-admin/profile-update.php',
'wp-admin/templates.php', 'wp-admin/templates.php',
'wp-includes/images/audio.png', 'wp-includes/images/audio.png',

View File

@ -1,4 +1,4 @@
var tagBox, commentsBox, editPermalink, makeSlugeditClickable; var tagBox, commentsBox, editPermalink, makeSlugeditClickable, WPSetThumbnailHTML, WPSetThumbnailID, WPRemoveThumbnail;
// return an array with any duplicate, whitespace or values removed // return an array with any duplicate, whitespace or values removed
function array_unique_noempty(a) { function array_unique_noempty(a) {
@ -57,7 +57,7 @@ tagBox = {
}); });
}, },
flushTags : function(el, a) { flushTags : function(el, a, f) {
a = a || false; a = a || false;
var text, tags = $('.the-tags', el), newtag = $('input.newtag', el), newtags; var text, tags = $('.the-tags', el), newtag = $('input.newtag', el), newtags;
@ -71,7 +71,9 @@ tagBox = {
this.quickClicks(el); this.quickClicks(el);
if ( !a ) if ( !a )
newtag.val('').focus(); newtag.val('');
if ( 'undefined' == f )
newtag.focus();
return false; return false;
}, },
@ -128,7 +130,7 @@ tagBox = {
// save tags on post save/publish // save tags on post save/publish
$('#post').submit(function(){ $('#post').submit(function(){
$('div.tagsdiv').each( function() { $('div.tagsdiv').each( function() {
tagBox.flushTags(this); tagBox.flushTags(this, false, 1);
}); });
}); });
@ -196,6 +198,30 @@ commentsBox = {
} }
}; };
WPSetThumbnailHTML = function(html){
$('.inside', '#postthumbnaildiv').html(html);
};
WPSetThumbnailID = function(id){
var field = $('input[value=_thumbnail_id]', '#list-table');
if ( field.size() > 0 ) {
$('#meta\\[' + field.attr('id').match(/[0-9]+/) + '\\]\\[value\\]').text(id);
}
};
WPRemoveThumbnail = function(){
$.post(ajaxurl, {
action:"set-post-thumbnail", post_id: $('#post_ID').val(), thumbnail_id: -1, cookie: encodeURIComponent(document.cookie)
}, function(str){
if ( str == '0' ) {
alert( setPostThumbnailL10n.error );
} else {
WPSetThumbnailHTML(str);
}
}
);
};
})(jQuery); })(jQuery);
jQuery(document).ready( function($) { jQuery(document).ready( function($) {

File diff suppressed because one or more lines are too long

View File

@ -1,22 +0,0 @@
function WPSetThumbnailHTML(html){
jQuery('#postthumbnaildiv .inside').html(html);
}
function WPSetThumbnailID(id){
if ( jQuery('input[value=_thumbnail_id]').size() > 0 ) {
jQuery('#meta\\[' + jQuery('input[value=_thumbnail_id]').attr('id').match(/[0-9]+/) + '\\]\\[value\\]' ).text(id);
}
}
function WPRemoveThumbnail(){
jQuery.post(ajaxurl, {
action:"set-post-thumbnail", post_id: jQuery('#post_ID').val(), thumbnail_id: -1, cookie: encodeURIComponent(document.cookie)
}, function(str){
if ( str == '0' ) {
alert( setPostThumbnailL10n.error );
} else {
WPSetThumbnailHTML(str);
}
}
);
}

View File

@ -1 +0,0 @@
function WPSetThumbnailHTML(html){jQuery("#postthumbnaildiv .inside").html(html)}function WPSetThumbnailID(id){if(jQuery("input[value=_thumbnail_id]").size()>0){jQuery("#meta\\["+jQuery("input[value=_thumbnail_id]").attr("id").match(/[0-9]+/)+"\\]\\[value\\]").text(id)}}function WPRemoveThumbnail(){jQuery.post(ajaxurl,{action:"set-post-thumbnail",post_id:jQuery("#post_ID").val(),thumbnail_id:-1,cookie:encodeURIComponent(document.cookie)},function(str){if(str=="0"){alert(setPostThumbnailL10n.error)}else{WPSetThumbnailHTML(str)}})};

View File

@ -265,7 +265,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'postbox', "/wp-admin/js/postbox$suffix.js", array('jquery-ui-sortable'), '20091012' ); $scripts->add( 'postbox', "/wp-admin/js/postbox$suffix.js", array('jquery-ui-sortable'), '20091012' );
$scripts->add_data( 'postbox', 'group', 1 ); $scripts->add_data( 'postbox', 'group', 1 );
$scripts->add( 'post', "/wp-admin/js/post$suffix.js", array('suggest', 'wp-lists', 'postbox'), '20091014' ); $scripts->add( 'post', "/wp-admin/js/post$suffix.js", array('suggest', 'wp-lists', 'postbox'), '20091019' );
$scripts->add_data( 'post', 'group', 1 ); $scripts->add_data( 'post', 'group', 1 );
$scripts->localize( 'post', 'postL10n', array( $scripts->localize( 'post', 'postL10n', array(
'tagsUsed' => __('Tags used on this post:'), 'tagsUsed' => __('Tags used on this post:'),
@ -380,9 +380,6 @@ function wp_default_scripts( &$scripts ) {
'error' => __( 'Could not set that as the thumbnail image. Try a different attachment.' ) 'error' => __( 'Could not set that as the thumbnail image. Try a different attachment.' )
) ); ) );
$scripts->add( 'set-post-thumbnail-handler', "/wp-admin/js/set-post-thumbnail-handler$suffix.js", array( 'jquery' ), '20091015' );
$scripts->add_data( 'set-post-thumbnail-handler', 'group', 1 );
} }
} }