|
|
|
| Почему то в IE меню выскакивает только один раз. В ФФ же всё нормально.
Код ниже.
<?php
if(isset($_GET['q'])) :
// Dictionary
$words = Array('ab','abc','abb','abcd','abcc','abcde','abcdd','abcdef','abcdee','abcdefg','abcdeff','abcdefxyz1','abcdexyz2');
$len = strlen($_GET['q']);
## Search for suitable words
for($i=0;$i<count($words);$i++)
if(substr($words[$i],0,$len)==$_GET['q'] && $words[$i]!=$_GET['q'])
$suitable[] = $words[$i];
## Outputting data
for($i=0;$i<@count($suitable);$i++)
echo "<span class='menu_item'>".$suitable[$i]."</span><br/>\r\n";
die();
EndIf;
/*
Actually the code above shoud be optimized as follows:
$words = Array('ab','abc','abb','abcd','abcc','abcde','abcdd','abcdef','abcdee','abcdefg','abcdeff','abcdefxyz1','abcdexyz2');
$len = strlen($_GET['q']);
for($i=0;$i<count($words);$i++)
if(substr($words[$i],$len)==$_GET['q'] && $words[$i]!=$_GET['q'])
echo "<span id='word"$i"'>".$words[$i]."</span>\r\n";
*/
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Word compliter </TITLE>
<META NAME="Author" CONTENT="Raskin Alexander">
<style type='text/css'>
.menu
{
border:1px solid #7F9DB9;
width:167px;
cursor:default;
font-size:small;
}
.menu_item_hover{
background-color:#316AC5;
color:white;
width:166px;
}
.menu_item{
background-color:white;
color:black;
}
</style>
</HEAD>
<BODY>
<center>
<br><br><br>
<textarea id='txt' rows='10' cols='50' onkeyup='checkwords()' wrap='soft'></textarea>
</center>
<table id='menu' class='menu' border='0' cellspacing='0' cellpadding='0'
style="position:absolute; overflow:hidden; display:none; left:10px; top:10px;" >
<tr><td id='td'>
</td></tr>
</table>
<SCRIPT language="JavaScript" type='text/JavaScript'>
var req;
var pos;
try { req = new XMLHttpRequest(); }
catch (trymicrosoft) {
try { req = new ActiveXObject("Msxml2.XMLHTTP");}
catch (othermicrosoft) {
try {req = new ActiveXObject("Microsoft.XMLHTTP");}
catch (failed) {req = false; }
}
}
function processReqChange()
{
// only if req shows "complete"
if (req.readyState == 4 && req.status == 200 )
{
document.getElementById('menu').style.display='none';
if(req.responseText=='') return true;
document.getElementById('td').innerHTML = req.responseText;
document.getElementById('menu').style.display='';
document.getElementById('menu').style.left = tempX+5 + 'px';
document.getElementById('menu').style.top = tempY+5 + 'px';
}
}
function loadXMLDoc(url){
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send(null);
}
}
function checkwords()
{
var text = document.getElementById('txt').value;
pos = false;
if(text.charCodeAt(text.length)==32 || text.charCodeAt(text.length)==10) return true;
for(i = text.length;i>0;i--)
if(text.charCodeAt(i)==32 || text.charCodeAt(i)==10) { pos = i+1; break;}
var word = text.substr(pos);
// Input mode
if(word!='') loadXMLDoc("<?php echo 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];?>?q=" + word);
}
var menu = document.getElementById('menu');
menu.onmouseover = menu.onmouseout = menu.onclick = function(e)
{
if (!e) e = window.event;
var elem = e.target || e.srcElement;
if(elem.tagName=='SPAN') {
if(e.type=="mouseover") {
if(!isMSIE) elem.setAttribute('class','menu_item_hover');
else elem.className = 'menu_item_hover';
}
if(e.type=="mouseout") {
if(!isMSIE) elem.setAttribute('class', 'menu_item');
else elem.className = 'menu_item';
}
if(e.type=="click")
{ if(isMSIE) pos--;
document.getElementById('txt').value = document.getElementById('txt').value.substr(0,pos) + elem.innerHTML + " ";
document.getElementById('txt').focus();
document.getElementById('menu').style.display='none';
}
}
}
isOpera=window.opera; //Opera 5+
isMSIE=document.all&&document.all.item&&!isOpera; //MSIE 4+
isMozilla=navigator.appName=="Netscape"; //Mozilla
if (!isMSIE && !isMozilla) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;
function getMouseXY(e) {
if (isMSIE) {
tempX = event.clientX + document.body.scrollLeft;
tempY = event.clientY + document.body.scrollTop;
} else {
tempX = e.pageX;
tempY = e.pageY;
}
if (tempX < 0){tempX = 0}
if (tempY < 0){tempY = 0}
}
</SCRIPT>
</BODY>
</HTML>
|
| |
|
|
|
|
|
|
|
для: valenok
(10.08.2007 в 01:00)
| | Я бы таких записей не применял:
<td id='td'>
Потому что как раз IE от его особого "ума" и "сообразительности" может переглючить.
А вообще надо проследить событийную линию для ИЕ | |
|
|
|