Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   var lastCompletion = '';
  2.  
  3.   $('#m').keydown(function(e)
  4. {
  5.     console.log('Action');
  6.     names = [];
  7.     for(x in chat.currentChannel.users)
  8.     {
  9.       if(x > 0)
  10.       {
  11.         names.push(chat.currentChannel.users[x].name);
  12.       }
  13.     }
  14.    
  15.   var keyCode = e.keyCode || e.which;
  16.   if(keyCode == 9)
  17.   {
  18.   e.preventDefault();
  19.   if(this.value == '')
  20.       {
  21.         if(lastCompletion != '')
  22.         {
  23.           this.value = lastCompletion + ', ';
  24.         }
  25.         return;
  26.       }
  27.      
  28.       var matches = [];
  29.   for(i=0;i<names.length;i++)
  30.   {
  31.     if(this.value.toLowerCase() == names[i].substring(0,this.value.length).toLowerCase())
  32.     {
  33.     matches.push(names[i]);
  34.     }
  35.   }
  36.       console.log(matches);
  37.   if(matches.length == 1)
  38.   {
  39.         lastCompletion = matches[0];
  40.     this.value = matches[0] + ', ';
  41.   }
  42.   else if(matches.length > 1)
  43.   {
  44.     var common = matches[0];
  45.     for(i=1;i<matches.length;i++)
  46.     {
  47.     common = inCommon(common,matches[i]);
  48.     }
  49.     this.value = common;
  50.   }
  51.   }
  52. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement