| 1 |
// Trigger upload dialog |
| 2 |
jQuery(document).ready(function() { |
| 3 |
var header_clicked = false; |
| 4 |
jQuery('#upload_image_button').click(function() { |
| 5 |
formfield = jQuery('#upload_image').attr('name'); |
| 6 |
tb_show('', 'media-upload.php?type=image&TB_iframe=true'); |
| 7 |
header_clicked = true; |
| 8 |
return false; |
| 9 |
}); |
| 10 |
|
| 11 |
// Store original function |
| 12 |
window.original_send_to_editor = window.send_to_editor; |
| 13 |
window.original_tb_remove = window.tb_remove; |
| 14 |
|
| 15 |
// Override removing function (resets our boolean) |
| 16 |
window.tb_remove = function() { |
| 17 |
header_clicked = false; |
| 18 |
window.original_tb_remove(); |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Override send_to_editor function from original script |
| 23 |
* Writes URL into the textbox. |
| 24 |
* |
| 25 |
* Note: If header is not clicked, we use the original function. |
| 26 |
*/ |
| 27 |
window.send_to_editor = function(html) { |
| 28 |
if (header_clicked) { |
| 29 |
imgurl = jQuery('img',html).attr('src'); |
| 30 |
jQuery('#upload_image').val(imgurl); |
| 31 |
tb_remove(); |
| 32 |
} else { |
| 33 |
window.original_send_to_editor(html); |
| 34 |
} |
| 35 |
} |
| 36 |
}); |