Advertisement
IzaacJ

jQuery

Nov 10th, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. jQuery(document).ready(function() {
  2.     jQuery('.upload_image_button').click(function() {
  3.         targetfield = jQuery(this).prev('.upload_image'); // locates the textbox where the url is to be stored
  4.     targetimg = jQuery(this).prev('.preview_image'); // locates the img element where to preview the image before save
  5.         tb_show('Choose Image', 'media-upload.php?type=image&TB_iframe=true'); // shows the wordpress media uploader
  6.     old_ste = window.send_to_editor; // save current send_to_editor
  7.         return false;
  8.     });
  9.  
  10.     window.send_to_editor = function(html) {
  11.         imgurl = jQuery('img',html).attr('src'); // gets the image url from media uploader
  12.         jQuery(targetfield).val(imgurl); // puts the image url in the textbox, successfully
  13.     jQuery(targetimg).attr('src',imgurl); // changes the source of the preview image element, unsuccessfully
  14.         tb_remove(); // closes the wordpress media uploader
  15.     window.send_to_editor = old_ste; // restores previous send_to_editor
  16.     }
  17. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement