Skip to content

Instantly share code, notes, and snippets.

@Abban
Created July 16, 2012 13:18
Show Gist options
  • Save Abban/3122667 to your computer and use it in GitHub Desktop.
Save Abban/3122667 to your computer and use it in GitHub Desktop.
WP: Hijack Thickbox
$('.add-file').live('click', function(){
formfield = $('#' + $(this).attr('id') + '_field');
// show the thickbox
tb_show( $(this).val() , fab_admin_url + 'media-upload.php?post_id=' + fab_post_id + '&type=file&acf_type=file&TB_iframe=1');
return false;
});
window.original_send_to_editor = window.send_to_editor;
window.send_to_editor = function(html){
if(formfield){
fileurl = $('img',html).attr('src');
formfield.val(fileurl);
tb_remove();
}else{
window.original_send_to_editor(html);
}
};
window.original_tb_remove = window.tb_remove;
window.tb_remove = function(){
original_tb_remove();
formfield = '';
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment