Buenas, este codigo yo tb lo estuve mirndo y parece ser q es Rails (otro lenguaje).
http://weblogs.macromedia.com/mxna/e...a_suggest.html index.html Código PHP:
<html>
<head>
<title>MXNA Suggest</title>
<style>
body
{
background: #fff;
font-family: Helvetica, Arial, sans-serif;
font-size: 13px;
text-align: center;
}
#header
{
margin-bottom: 10px;
background: #90ACC8;
}
#textInput {
width: 300px;
}
#inputWrapper {
padding-top: 200px;
}
#suggestion
{
width: 300px;
margin-left: auto;
margin-right: auto;
}
#suggestion_table
{
border-width: 0 1px 1px 1px;
border-style: solid;
border-color: #ddd;
width: 298px;
}
.row
{
width: 298px;
}
.left_cell
{
float: left;
padding-left: 1px;
width: 198px;
text-align: left;
}
.right_cell
{
float: right;
padding-right: 1px;
color: green;
width: 98px;
text-align: right;
}
</style>
<script type="text/javascript" src="/javascript/XMLUtil.js"></script>
<script type="text/javascript" src="/javascript/replaceHTML.js"></script>
<script type="text/javascript" src="/javascript/BrowserDetection.js"></script>
<script type="text/javascript">
var xmlUtil = new XMLUtil();
var bd = new BrowserDetection();
var http;
var winRet = /\r\n$/;
var unxRet = /\n$/;
var domainRe = /http:\/\/(.+?)\//;
var domain = domainRe.exec(document.location)[1];
var currentRow = -1;
var resultArray = new Array();
var currentTerm = null;
var key;
function handleKeyPress(e)
{
// IE
if(window.event)
{
key = e.keyCode;
}
// Moz
else
{
key = e.which;
}
// Scrolling
if ((key == 38 || key == 40) && resultArray.length > 0)
{
if (key == 38)
{
if (currentRow != 0)
{
inRow(currentRow - 1);
}
}
else
{
if (currentRow != (resultArray.length - 1))
{
inRow(currentRow + 1);
}
}
return;
}
if (key == 8 || (key >= 48 && key <= 90))
{
var searchTerm = document.getElementById('textInput').value;
if (searchTerm.length > 0)
{
searchMxna(document.getElementById('textInput').value);
}
else
{
populateResults('');
}
}
// Enter
if (key == 13)
{
gotoMxna();
return;
}
// Escape
if (key == 27)
{
close();
return;
}
}
function searchMxna(hint)
{
http = xmlUtil.getXMLHTTPObject();
http.open('GET', 'http://'+domain+'/mxna/experimental/getSearchTerms.cfm?limit=10&hint='+escape(hint), false);
http.send(null);
handleSearchResults();
}
function handleSearchResults()
{
if (http.readyState == xmlUtil.COMPLETE && http.status == 200)
{
var res = http.responseText;
resultArray = new Array();
if (res.search(winRet) != -1)
{
res = res.substring(0, res.length - 2);
}
else if (res.search(unxRet) != -1)
{
res = res.substring(0, res.length - 1);
}
var html = new String();
if (res.length > 0)
{
resultArray = res.split('\n');
html += '<div id="suggestion_table">';
for (var i = 0; i < resultArray.length; ++i)
{
var term = resultArray[i].substring(0, resultArray[i].indexOf('\t'));
var ranking = resultArray[i].substring(resultArray[i].indexOf('\t') + 1, resultArray[i].length);
html += '<div class="row" id="row_'+i+'" onMouseOver="inRow('+i+')" onClick="gotoMxna();">';
html += '<div class="left_cell" id="left_cell_'+i+'">'+term+'</div>';
html += '<div class="right_cell" id="right_cell_'+i+'">'+ranking+'</div>';
html += '</div>';
if (!bd.isIE)
{
html += '<br/>';
}
}
html += '</div>';
populateResults(html);
inRow(0);
}
else
{
html = '<strong>No suggestions found.</strong>';
populateResults(html);
}
}
}
function populateResults(val)
{
replaceHTML('suggestion', val);
}
function close()
{
replaceHTML('suggestion', '');
}
function changeRowColor(id, fgColor, bgColor)
{
document.getElementById('left_cell_'+id).style.backgroundColor = bgColor;
document.getElementById('right_cell_'+id).style.backgroundColor = bgColor;
document.getElementById('row_'+id).style.backgroundColor = bgColor;
document.getElementById('right_cell_'+id).style.color = fgColor;
}
function inRow(id)
{
if (currentRow != -1)
{
changeRowColor(currentRow, 'green', '#fff');
}
currentRow = id;
currentTerm = resultArray[currentRow].substring(0, resultArray[currentRow].indexOf('\t'));
changeRowColor(currentRow, '#fff', '#90ACC8');
if (key != 8)
{
autoComplete();
}
}
// Funcion que conecta con la pagina de consulta.
function gotoMxna()
{
if (resultArray.length == 0 ||
currentRow == -1)
{
return;
}
document.location = 'http://'+domain+'/mxna/index.cfm?searchterms='+escape(currentTerm)+'&query=bySimpleSearch';
}
function autoComplete()
{
if (bd.isSafari)
{
return;
}
var textInput = document.getElementById('textInput');
var startVal = textInput.value;
textInput.value = currentTerm;
if (!bd.isIE)
{
textInput.setSelectionRange(startVal.length, currentTerm.length);
}
else
{
var range = textInput.createTextRange();
range.moveStart("character", startVal.length);
range.moveEnd("character", currentTerm.length);
range.select();
}
}
function init()
{
document.getElementById('textInput').focus();
}
window.onload = init;
</script>
</head>
<body>
<div id="inputWrapper">
<div id="header">
<img src="../images/logo.gif" width="169" height="49" border="0"/>
</div>
<input type="text" id="textInput" onKeyUp="handleKeyPress(event);" autocomplete="off"/><br/>
<div id="suggestion"></div>
</div>
</body>
</html>
XMLUtil.js Código PHP:
function XMLUtil()
{
this.UNINITIALIZED = 0;
this.LOADING = 1;
this.LOADED = 2;
this.INTERACTIVE = 3;
this.COMPLETE = 4;
this.isIE = (document.implementation.createDocument) ? false : true;
}
XMLUtil.prototype.getXMLHTTPObject = function()
{
if(this.isIE)
{
return new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
return new XMLHttpRequest();
}
}
XMLUtil.prototype.getDOM = function()
{
if (this.isIE)
{
return new ActiveXObject("Microsoft.XMLDOM");
}
else
{
return new DOMParser();
}
}
XMLUtil.prototype.getDOMFromString = function(xmlStr)
{
var xmlDom = this.getDOM();
if (this.isIE)
{
xmlDom.async = 'false';
xmlDom.loadXML(xmlStr);
return xmlDom;
}
else
{
return xmlDom.parseFromString(xmlStr, 'text/xml');
}
}
XMLUtil.prototype.getText = function(elem)
{
if (this.isIE)
{
return elem.text;
}
else
{
return elem.textContent;
}
}
replaceHTML.js Código PHP:
function replaceHTML(idName, content)
{
var target = document.getElementById(idName);
target.innerHTML = content;
}
Browserdetection.js Código PHP:
function BrowserDetection()
{
var isIE, isMozilla, isSafari, isOpera = false;
if (navigator.userAgent.indexOf('MSIE') != -1)
this.isIE = true;
else if (navigator.userAgent.indexOf('Safari') != -1)
this.isSafari = true;
else if (navigator.userAgent.indexOf('Opera') != -1)
this.isOpera = true;
else
this.isMozilla = true;
}
El fichero q realiza la consulta ha de tener el siguiente formato.
Código:
ajax 277
amfphp 38
actionscript 25
actionscript 3 24
asdt 22
arp 19
actionstep 17
avalon 17
apple 16
aggregator 11
Espero q te sea util.
Un saludo.