Created
September 23, 2015 19:49
-
-
Save kosmiq/79252f5bb310975391bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function($) { | |
var formfield = null; | |
$('#upload_image_button').click(function() { | |
$('html').addClass('Image'); | |
formfield = $(this).prev('input').attr('name'); | |
formfield_id = $(this).prev('input').attr('id'); | |
tb_show( '', 'media-upload.php?type=image&TB_iframe=true' ); | |
return false; | |
}); | |
// user inserts file into post. | |
// only run custom if user started process using the above process | |
// window.send_to_editor(html) is how wp normally handles the received data | |
window.original_send_to_editor = window.send_to_editor; | |
window.send_to_editor = function( html ) { | |
var fileurl; | |
if(formfield != null) { | |
fileurl = $( 'img', html).attr('src'); | |
$( "#" + formfield_id ).val(fileurl); | |
tb_remove(); | |
$('html').removeClass('Image'); | |
formfield = null; | |
} 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