You can also add in a filter that can add the ID as a html5 data attribute to the returned HTML fragment from send_to_editor.
public function image_to_editor($html, $id, $caption, $title, $align, $url, $size, $alt){
$dom = new DOMDocument();
@$dom->loadHTML($html);
$x = new DOMXPath($dom);
foreach($x->query("//img") as $node){
$node->setAttribute("data-id", $id);
}
if($dom->getElementsByTagName("a")->length == 0){
$newHtml = $dom->saveXML($dom->getElementsByTagName('img')->item(0));
}else{
$newHtml = $dom->saveXML($dom->getElementsByTagName('a')->item(0));
}
return $newHtml;
}
add_filter('image_send_to_editor', array(&$this,'image_to_editor'), 1, 8);
Then in your javascript handler for window.send_to_editor;
$('img',html).data('id'));
You can do the same thing for media uploads as well.