// // requires keyboard.js and mouse.js // var the_balloon_count=0; function new_balloon(html_content, where_to_point, timeout, direction) { var pelem; var rect; if (where_to_point instanceof Array) { pelem = null; rect = where_to_point; } else if (typeof(where_to_point) == 'string') { pelem = element(where_to_point); rect = get_rect(pelem); } else { pelem = where_to_point; rect = get_rect(pelem); } var x = Math.floor(rect[0]); var y = Math.floor(rect[1]); var cnt = "
\"\"\"\"
"+html_content+"
\"\"\"\"
"; var div = document.createElement('div'); div.id = 'BALLOON_'+(the_balloon_count++); div.style['position'] = 'absolute'; div.style['display'] = 'none'; div.style['width'] = '24em'; div.style['cursor'] = 'default'; div.style['textAlign'] = 'left'; document.body.appendChild(div); var inneroffs = (timeout>=0?4:0); switch (direction) { case 1: var dx = 10; var dy = 24; cnt = ''+cnt; if (rect.length==4) { x = rect[0]+rect[2]-inneroffs; y = rect[1]+rect[3]*3/5; } x += dx; y -= dy; break; case 2: var dx = 15; var dy = 3; cnt = cnt+''; div.innerHTML = cnt; div.style['display'] = ''; div.style['opacity'] = '0'; if (rect.length==4) { x = rect[0]+rect[2]*3/5; y = rect[1]+inneroffs; } x -= dx; y -= div.offsetHeight-dy-2; div.style['display'] = 'none'; div.style['opacity'] = ''; break; default: cnt = ''+cnt; x-=12; y-=1; if (rect.length==4) { x = rect[0]+rect[2]*3/5; y = rect[1]+rect[3]-inneroffs; } if (pelem.type == 'text') { x = Math.min(x, rect[0] + pelem.value.length*rect[3]*0.41*3/5); } break; } if ( timeout == -1 ) div.style['display'] = ''; div.style['left'] = x+'px'; div.style['top'] = y+'px'; div.innerHTML = cnt; if (timeout > 0) { $("#"+id).fadeIn(250); timeout( 250+timeout, function () { $("#"+id).fadeOut(500, function () { del_balloon(div); }) } ); } add_keyboard_handler('down','del_balloon(elem('+repr(div.id)+'))'); add_mouse_handler('down','del_balloon(elem('+repr(div.id)+'))'); return div; } function del_balloon(balloon) { if (balloon != null) { document.body.removeChild(balloon); add_keyboard_handler('down','del_balloon(elem('+repr(balloon.id)+'))'); add_mouse_handler('down','del_balloon(elem('+repr(balloon.id)+'))'); } }