Skip to content

Instantly share code, notes, and snippets.

@ericmann
Created October 11, 2012 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericmann/3873602 to your computer and use it in GitHub Desktop.
Save ericmann/3873602 to your computer and use it in GitHub Desktop.
// the upload image button, saves the id and outputs a preview of the image
$('.meta_box_upload_image_button').click(function() {
formID = $(this).attr('rel');
formfield = $(this).siblings('.meta_box_upload_image');
preview = $(this).siblings('.meta_box_preview_image');
tb_show('Choose Image', 'media-upload.php?post_id='+formID+'&type=image&custom=simple&TB_iframe=1');
window.orig_send_to_editor = window.send_to_editor;
window.send_to_editor = function(html) {
img = $('img',html);
imgurl = img.attr('src');
classes = img.attr('class');
id = classes.replace(/(.*?)wp-image-/, '');
formfield.val(id);
preview.attr('src', imgurl);
tb_remove();
window.send_to_editor = window.orig_send_to_editor;
}
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment