Skip to content

Instantly share code, notes, and snippets.

@benallfree
Created March 31, 2013 21:37
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 benallfree/5282099 to your computer and use it in GitHub Desktop.
Save benallfree/5282099 to your computer and use it in GitHub Desktop.
Demo of WP media uploader in metabox
jQuery(function($) {
var element_clicked = false;
$('#my-button').click(function() {
formfield = jQuery('#my-button').attr('name');
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
element_clicked = true;
return false;
});
// Store original function
window.original_send_to_editor = window.send_to_editor;
/**
* Override send_to_editor function from original script
* Writes URL into the textbox.
*
* Note: If header is not clicked, we use the original function.
*/
window.send_to_editor = function(html) {
if (element_clicked) {
imgurl = $('img',html).attr('src');
// do stuff here with the URL
element_clicked = false;
tb_remove();
} else {
window.original_send_to_editor(html);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment