I just integrated the TAB key multi-browser handling to support nicknames completions like on most IRC clients.
But the completion algorithme I written is very basic.
It would be great to have a better one.
Here is the basic code I wrote :
- Code: Select all
/**
* Try to complete a nickname like on IRC when pressing the TAB key
* @todo: improve the algorithme, it should take into account the cursor position
*/
completeNick: function()
{
var w = this.el_words;
var nick_src = w.value.substring(w.value.lastIndexOf(' ')+1,w.value.length);
if (nick_src != '')
{
var ul_online = this.el_online.firstChild;
for (var i=0; i<ul_online.childNodes.length; i++)
{
var nick = ul_online.childNodes[i].innerHTML;
if (nick.indexOf(nick_src) == 0)
w.value = w.value.replace(nick_src, nick);
}
}
},
- this.el_words is the form text input widget where text is typed.
- this.el_online is the html nickname list using <ul> and <li>, but it would be easier to use the javascript array which containes exatly the same : this.nicklist
The challenge is to simplify this algorithme and improve it in order to :
- make possible to choose which nickname to use if two nickname starts with the same prefix, example: if the two nicks are "bob" and "boby", when the user type "bo"+TAB, the algorithme can't choose.
- ... list to complete
For those who want to help, just checkout the subversion head : svn co http://www.phpfreechat.net/svn/trunk
Then open this file : phpfreechat/themes/default/templates/pfcclient.js.tpl.php
And search for the completeNick function.
Anyway, any ideas are welcomed to help