Advertisement
Guest User

img-upload.js - Image Upload jQuery Function

a guest
Jan 7th, 2011
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. jQuery(document).ready(function() {
  2.     var formfield;
  3.    
  4.     jQuery('#upload_image_button').click(function() {
  5.         jQuery('html').addClass('Image');
  6.         formfield = jQuery('#upload_image').attr('name');
  7.         tb_show('', 'media-upload.php?type=image&TB_iframe=true');
  8.         return false;
  9.     });
  10.     // user inserts file into post. only run custom if user started process using the above process
  11.     // window.send_to_editor(html) is how wp would normally handle the received data
  12.     window.original_send_to_editor = window.send_to_editor;
  13.     window.send_to_editor = function(html){
  14.     if (formfield) {
  15.         fileurl = jQuery('img',html).attr('src');
  16.         jQuery('#upload_image').val(fileurl);
  17.         tb_remove();
  18.         jQuery('html').removeClass('Image');
  19.     } else {
  20.         window.original_send_to_editor(html);
  21.         }
  22.     };
  23. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement