Created
March 31, 2013 21:37
-
-
Save benallfree/5282099 to your computer and use it in GitHub Desktop.
Demo of WP media uploader in metabox
This file contains 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(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