Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 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"]
  2. //tabs => filtered commands, pos = position in tab, tmp => currently written text
  3. var tabs = [], pos=-1, tmp = '';
  4. $("#warchat").keydown(function (e) {  
  5.     if (e.which == 9) {
  6.         if(pos<0){
  7.             pos = 0;
  8.             tmp = $(this).val()
  9.             tabs = commands.filter(function(a){return a.match("^"+tmp)})
  10.         }
  11.         if(tabs.length){
  12.             $(this).val(tabs[pos]+" ")
  13.             $(this)[0].setSelectionRange(tmp.length,tabs[pos].length+1)
  14.             pos = pos < tabs.length-1?pos+1:0;
  15.             console.log(tmp)
  16.         }
  17.         e.preventDefault();
  18.     }
  19.     else{
  20.         pos = -1;
  21.     }
  22. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement