Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- commands = ["/glance","/phase","/summon","/heal","/swap","/radiance","/hide","/cloak","/scan","/blast","/who","/me","/w","/me laughs hysterically","/me smiles gleefully","/me begins to cry","/me breaks out into a dance","/me lets out a fierce roar","/track","/shadow","/bomb"]
- //tabs => filtered commands, pos = position in tab, tmp => currently written text
- var tabs = [], pos=-1, tmp = '';
- $("#warchat").keydown(function (e) {
- if (e.which == 9) {
- if(pos<0){
- pos = 0;
- tmp = $(this).val()
- tabs = commands.filter(function(a){return a.match("^"+tmp)})
- }
- if(tabs.length){
- $(this).val(tabs[pos]+" ")
- $(this)[0].setSelectionRange(tmp.length,tabs[pos].length+1)
- pos = pos < tabs.length-1?pos+1:0;
- console.log(tmp)
- }
- e.preventDefault();
- }
- else{
- pos = -1;
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement