Add tab completion for the chatbox

This commit is contained in:
calzoneman 2013-03-17 20:24:28 -05:00
parent 173ff8c2e5
commit 5cf8a089ab
1 changed files with 22 additions and 0 deletions

View File

@ -173,6 +173,28 @@ $('#chatline').keydown(function(ev) {
}); });
$('#chatline').val(''); $('#chatline').val('');
} }
else if(ev.keyCode == 9) { // Tab completion
var words = $('#chatline').val().split();
var current = words[words.length - 1].toLowerCase();
var users = $('#userlist').children();
var match = null;
for(var i = 0; i < users.length; i++) {
var name = users[i].children[1].innerHTML.toLowerCase();
if(name.indexOf(current) == 0 && match == null) {
match = users[i].children[1].innerHTML;
}
else if(name.indexOf(current) == 0) {
match = null;
break;
}
}
if(match != null) {
words[words.length - 1] = match;
$('#chatline').val(words.join(' '));
}
ev.preventDefault();
return false;
}
}); });